mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 19:20:45 +02:00
Refactor logging mechanism for periodic stats
Updated `processLogQueue` to log periodic stats when the queue is empty. Replaced the switch-case structure in `logCurrentStats` with an array of log messages, which are randomized and queued for display. Added `shuffleArray` helper function and removed specific logging for unpaid balances to streamline the process.
This commit is contained in:
parent
7646149bb9
commit
6c7e986a80
@ -242,58 +242,50 @@ function processLogQueue() {
|
|||||||
if (logUpdateQueue.length > 0) {
|
if (logUpdateQueue.length > 0) {
|
||||||
const update = logUpdateQueue.shift(); // Get the next update
|
const update = logUpdateQueue.shift(); // Get the next update
|
||||||
addConsoleMessage(update.message, update.type); // Display it
|
addConsoleMessage(update.message, update.type); // Display it
|
||||||
|
} else {
|
||||||
|
// If the queue is empty, log periodic stats
|
||||||
|
logCurrentStats(cachedMetrics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log current mining stats
|
* Log current mining stats periodically
|
||||||
*/
|
*/
|
||||||
function logCurrentStats(metrics) {
|
function logCurrentStats(metrics) {
|
||||||
if (!metrics) return;
|
if (!metrics) return;
|
||||||
|
|
||||||
// Randomize which stat we log to avoid repetition
|
// Define an array of possible log messages
|
||||||
const statToLog = Math.floor(Math.random() * 5);
|
const logMessages = [
|
||||||
|
`HASHRATE: ${metrics.hashrate_60sec || metrics.hashrate_10min || metrics.hashrate_3hr || 0} ${metrics.hashrate_60sec_unit || metrics.hashrate_10min_unit || metrics.hashrate_3hr_unit || 'TH/s'}`,
|
||||||
|
`BLOCK HEIGHT: ${numberWithCommas(metrics.block_number || 0)}`,
|
||||||
|
`WORKERS ONLINE: ${metrics.workers_hashing || 0}`,
|
||||||
|
`BTC PRICE: $${numberWithCommas(parseFloat(metrics.btc_price || 0).toFixed(2))}`,
|
||||||
|
`DAILY PROFIT: $${metrics.daily_profit_usd ? metrics.daily_profit_usd.toFixed(2) : 'CALCULATING...'}`,
|
||||||
|
`UNPAID EARNINGS: ${numberWithCommas(metrics.unpaid_earnings || 0)} SATS`,
|
||||||
|
`NETWORK DIFFICULTY: ${numberWithCommas(Math.round(metrics.difficulty || 0))}`,
|
||||||
|
`POWER CONSUMPTION: ${metrics.power_usage || 'N/A'}W`,
|
||||||
|
];
|
||||||
|
|
||||||
switch (statToLog) {
|
// Randomize the order of log messages
|
||||||
case 0:
|
shuffleArray(logMessages);
|
||||||
// Hashrate stats
|
|
||||||
const hashrate = metrics.hashrate_60sec || metrics.hashrate_10min || metrics.hashrate_3hr || 0;
|
|
||||||
const hashrateUnit = metrics.hashrate_60sec_unit || metrics.hashrate_10min_unit || metrics.hashrate_3hr_unit || 'TH/s';
|
|
||||||
addConsoleMessage(`MINING PERFORMANCE: ${hashrate} ${hashrateUnit} - ${metrics.workers_hashing || 0} WORKERS ACTIVE`, MSG_TYPE.HASH);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
// Queue the first few messages for display
|
||||||
// Earnings projection
|
logMessages.slice(0, 3).forEach(message => queueLogUpdate(message, MSG_TYPE.INFO));
|
||||||
if (metrics.daily_mined_sats) {
|
|
||||||
addConsoleMessage(`EARNINGS PROJECTION: ${numberWithCommas(metrics.daily_mined_sats)} SATS/DAY - ${metrics.daily_profit_usd > 0 ? 'PROFITABLE' : 'UNPROFITABLE'}`, MSG_TYPE.INFO);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
// Update the last update time
|
||||||
// Network statistics
|
|
||||||
addConsoleMessage(`NETWORK STATUS: HASHRATE ${metrics.network_hashrate || 0} EH/s - BLOCKCHAIN HEIGHT ${numberWithCommas(metrics.block_number || 0)}`, MSG_TYPE.NETWORK);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
// Power consumption and efficiency
|
|
||||||
if (metrics.power_usage) {
|
|
||||||
const efficiency = metrics.power_usage > 0 ? ((metrics.hashrate_60sec || 0) / metrics.power_usage).toFixed(2) : 'N/A';
|
|
||||||
addConsoleMessage(`POWER CONSUMPTION: ${metrics.power_usage}W - EFFICIENCY: ${efficiency} TH/s/kW`, MSG_TYPE.SYSTEM);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
// Unpaid balance
|
|
||||||
if (metrics.unpaid_earnings) {
|
|
||||||
addConsoleMessage(`PENDING BALANCE: ${numberWithCommas(metrics.unpaid_earnings)} SATS - EST. PAYOUT: ${metrics.est_time_to_payout || 'CALCULATING...'}`, MSG_TYPE.INFO);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update last update time
|
|
||||||
lastUpdateTime = new Date();
|
lastUpdateTime = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffle an array in place
|
||||||
|
*/
|
||||||
|
function shuffleArray(array) {
|
||||||
|
for (let i = array.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[array[i], array[j]] = [array[j], array[i]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the dashboard stats display in the footer
|
* Update the dashboard stats display in the footer
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user