Tons of network chart improvements and changes
-Chart.js has been updated to v4.4.7 -The chartjs-plugin-crosshair chart plugin has been updated to v2.0.5 via a forked version that has a working sync feature which is now available as a new setting option for use with the network charts -Added a new max_hours setting to display chart data for a certain number of hours instead of a fixed set of records which can help reveal holes in the sync process for the explorer and/or blockchain -Added a new timestamp field to the network history collection for use with the max_hours setting chart data -Added a number of new network chart settings to control display of the chart title, legend, a new vertical block line option, chart height, an option to force 2 charts to appear on their own row or beside each other, and an option to force a chart to take up all available space in the chart box without extra padding -Added a new dependency chartjs-plugin-annotation v3.1.0 to display block lines in new hourly charts
This commit is contained in:
+85
-52
@@ -1306,67 +1306,97 @@ module.exports = {
|
||||
lib.get_hashrate(function(hashrate) {
|
||||
// lookup network difficulty
|
||||
lib.get_difficulty(function(difficulty) {
|
||||
var difficultyPOW = 0;
|
||||
var difficultyPOS = 0;
|
||||
// lookup the block hash
|
||||
lib.get_blockhash(height, function(blockhash) {
|
||||
if (blockhash) {
|
||||
// lookup block data
|
||||
lib.get_block(blockhash, function(block) {
|
||||
if (block) {
|
||||
var difficultyPOW = 0;
|
||||
var difficultyPOS = 0;
|
||||
|
||||
if (difficulty && difficulty['proof-of-work']) {
|
||||
if (settings.shared_pages.difficulty == 'Hybrid') {
|
||||
difficultyPOS = difficulty['proof-of-stake'];
|
||||
difficultyPOW = difficulty['proof-of-work'];
|
||||
} else if (settings.shared_pages.difficulty == 'POW')
|
||||
difficultyPOW = difficulty['proof-of-work'];
|
||||
else
|
||||
difficultyPOS = difficulty['proof-of-stake'];
|
||||
} else if (settings.shared_pages.difficulty == 'POW')
|
||||
difficultyPOW = difficulty;
|
||||
else
|
||||
difficultyPOS = difficulty;
|
||||
if (difficulty && difficulty['proof-of-work']) {
|
||||
if (settings.shared_pages.difficulty == 'Hybrid') {
|
||||
difficultyPOS = difficulty['proof-of-stake'];
|
||||
difficultyPOW = difficulty['proof-of-work'];
|
||||
} else if (settings.shared_pages.difficulty == 'POW')
|
||||
difficultyPOW = difficulty['proof-of-work'];
|
||||
else
|
||||
difficultyPOS = difficulty['proof-of-stake'];
|
||||
} else if (settings.shared_pages.difficulty == 'POW')
|
||||
difficultyPOW = difficulty;
|
||||
else
|
||||
difficultyPOS = difficulty;
|
||||
|
||||
// create a new network history record
|
||||
var newNetworkHistory = new NetworkHistory({
|
||||
blockindex: height,
|
||||
nethash: (hashrate == null || hashrate == '-' ? 0 : hashrate),
|
||||
difficulty_pow: difficultyPOW,
|
||||
difficulty_pos: difficultyPOS,
|
||||
});
|
||||
// create a new network history record
|
||||
var newNetworkHistory = new NetworkHistory({
|
||||
blockindex: height,
|
||||
nethash: (hashrate == null || hashrate == '-' ? 0 : hashrate),
|
||||
difficulty_pow: difficultyPOW,
|
||||
difficulty_pos: difficultyPOS,
|
||||
timestamp: block.time
|
||||
});
|
||||
|
||||
// save the new network history record
|
||||
newNetworkHistory.save().then(() => {
|
||||
// get the count of network history records
|
||||
NetworkHistory.find({}).countDocuments().then((count) => {
|
||||
// read maximum allowed records from settings
|
||||
let max_records = settings.network_history.max_saved_records;
|
||||
// save the new network history record
|
||||
newNetworkHistory.save().then(() => {
|
||||
// read maximum allowed records from settings
|
||||
const max_records = settings.network_history.max_saved_records;
|
||||
|
||||
// check if the current count of records is greater than the maximum allowed
|
||||
if (count > max_records) {
|
||||
// prune network history records to keep collection small and quick to access
|
||||
NetworkHistory.find().select('blockindex').sort({blockindex: 1}).limit(count - max_records).exec().then((records) => {
|
||||
// create a list of the oldest network history ids that will be deleted
|
||||
const ids = records.map((doc) => doc.blockindex);
|
||||
// check if the max allowed records is set
|
||||
if (max_records == 0) {
|
||||
// read maximum hours from settings
|
||||
const max_hours = settings.network_history.max_hours;
|
||||
|
||||
// delete old network history records
|
||||
NetworkHistory.deleteMany({blockindex: {$in: ids}}).then(() => {
|
||||
console.log('Network history update complete');
|
||||
return cb();
|
||||
// calculate the cutoff timestamp value
|
||||
const timestampThreshold = Math.floor(Date.now() / 1000) - max_hours * 60 * 60;
|
||||
|
||||
// delete all network history records that are older than the max hours setting
|
||||
NetworkHistory.deleteMany({ timestamp: { $lt: timestampThreshold } }).then(delete_result => {
|
||||
console.log('Network history update complete');
|
||||
return cb();
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
return cb();
|
||||
});
|
||||
} else {
|
||||
// prune network history records to keep collection small and quick to access
|
||||
NetworkHistory.find().sort({ blockindex: -1 }).skip(max_records).select('blockindex').exec().then((records) => {
|
||||
// check if any records need to be deleted
|
||||
if (records.length > 0) {
|
||||
// create a list of the oldest network history ids that will be deleted
|
||||
const ids = records.map((doc) => doc.blockindex);
|
||||
|
||||
// delete old network history records
|
||||
NetworkHistory.deleteMany({blockindex: {$in: ids}}).then(() => {
|
||||
console.log('Network history update complete');
|
||||
return cb();
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return cb();
|
||||
});
|
||||
} else {
|
||||
// no records need to be deleted
|
||||
console.log('Network history update complete');
|
||||
return cb();
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
return cb();
|
||||
});
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
console.log('Error updating network history: ' + err);
|
||||
return cb();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
} else {
|
||||
console.log(`Error updating network history: Cannot find block with hash ${blockhash}`);
|
||||
return cb();
|
||||
});
|
||||
} else {
|
||||
console.log('Network history update complete');
|
||||
return cb();
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log(`Error updating network history: Cannot find block hash with height ${height}`);
|
||||
return cb();
|
||||
});
|
||||
}).catch((err) => {
|
||||
console.log('Error updating network history: ' + err);
|
||||
return cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1928,7 +1958,10 @@ module.exports = {
|
||||
check_rename_db_field(NetworkHistory, 'difficulty', 'difficulty_pow', function(renamed) {
|
||||
// determine if difficulty_pos field exists
|
||||
check_add_db_field(NetworkHistory, 'difficulty_pos', 0, function(exists) {
|
||||
return cb(true);
|
||||
// determine if timestamp field exists
|
||||
check_add_db_field(NetworkHistory, 'timestamp', 0, function(timestamp_exists) {
|
||||
return cb(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user