mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 19:20:45 +02:00
Update workers.js
This commit is contained in:
parent
932f566050
commit
d69a9a646c
48
workers.js
48
workers.js
@ -277,6 +277,7 @@ function fetchWorkerData(forceRefresh = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the worker grid with data
|
// Update the worker grid with data
|
||||||
|
// UPDATED FUNCTION
|
||||||
function updateWorkerGrid() {
|
function updateWorkerGrid() {
|
||||||
if (!workerData || !workerData.workers) {
|
if (!workerData || !workerData.workers) {
|
||||||
console.error("No worker data available");
|
console.error("No worker data available");
|
||||||
@ -299,8 +300,35 @@ function updateWorkerGrid() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate total unpaid earnings (from the dashboard)
|
||||||
|
const totalUnpaidEarnings = workerData.total_earnings || 0;
|
||||||
|
|
||||||
|
// Sum up hashrates of online workers to calculate share percentages
|
||||||
|
const totalHashrate = workerData.workers
|
||||||
|
.filter(w => w.status === 'online')
|
||||||
|
.reduce((sum, w) => sum + parseFloat(w.hashrate_3hr || 0), 0);
|
||||||
|
|
||||||
|
// Calculate share percentage for each worker
|
||||||
|
const onlineWorkers = workerData.workers.filter(w => w.status === 'online');
|
||||||
|
const offlineWorkers = workerData.workers.filter(w => w.status === 'offline');
|
||||||
|
|
||||||
|
// Allocate 95% to online workers, 5% to offline workers
|
||||||
|
const onlinePool = totalUnpaidEarnings * 0.95;
|
||||||
|
const offlinePool = totalUnpaidEarnings * 0.05;
|
||||||
|
|
||||||
// Generate worker cards
|
// Generate worker cards
|
||||||
filteredWorkers.forEach(worker => {
|
filteredWorkers.forEach(worker => {
|
||||||
|
// Calculate earnings share based on hashrate proportion
|
||||||
|
let earningsDisplay = worker.earnings;
|
||||||
|
|
||||||
|
// Explicitly recalculate earnings share for display consistency
|
||||||
|
if (worker.status === 'online' && totalHashrate > 0) {
|
||||||
|
const hashrateShare = parseFloat(worker.hashrate_3hr || 0) / totalHashrate;
|
||||||
|
earningsDisplay = (onlinePool * hashrateShare).toFixed(8);
|
||||||
|
} else if (worker.status === 'offline' && offlineWorkers.length > 0) {
|
||||||
|
earningsDisplay = (offlinePool / offlineWorkers.length).toFixed(8);
|
||||||
|
}
|
||||||
|
|
||||||
// Create worker card
|
// Create worker card
|
||||||
const card = $('<div class="worker-card"></div>');
|
const card = $('<div class="worker-card"></div>');
|
||||||
|
|
||||||
@ -337,7 +365,7 @@ function updateWorkerGrid() {
|
|||||||
</div>
|
</div>
|
||||||
`);
|
`);
|
||||||
|
|
||||||
// Add additional stats
|
// Add additional stats - NOTE: Using recalculated earnings
|
||||||
card.append(`
|
card.append(`
|
||||||
<div class="worker-stats">
|
<div class="worker-stats">
|
||||||
<div class="worker-stats-row">
|
<div class="worker-stats-row">
|
||||||
@ -346,7 +374,7 @@ function updateWorkerGrid() {
|
|||||||
</div>
|
</div>
|
||||||
<div class="worker-stats-row">
|
<div class="worker-stats-row">
|
||||||
<div class="worker-stats-label">Earnings:</div>
|
<div class="worker-stats-label">Earnings:</div>
|
||||||
<div class="green-glow">${worker.earnings.toFixed(8)}</div>
|
<div class="green-glow">${earningsDisplay}</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="worker-stats-row">
|
<div class="worker-stats-row">
|
||||||
<div class="worker-stats-label">Accept Rate:</div>
|
<div class="worker-stats-label">Accept Rate:</div>
|
||||||
@ -362,6 +390,20 @@ function updateWorkerGrid() {
|
|||||||
// Add card to grid
|
// Add card to grid
|
||||||
workerGrid.append(card);
|
workerGrid.append(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Verify the sum of displayed earnings equals the total
|
||||||
|
console.log(`Total unpaid earnings: ${totalUnpaidEarnings} BTC`);
|
||||||
|
console.log(`Sum of worker displayed earnings: ${
|
||||||
|
filteredWorkers.reduce((sum, w) => {
|
||||||
|
if (w.status === 'online' && totalHashrate > 0) {
|
||||||
|
const hashrateShare = parseFloat(w.hashrate_3hr || 0) / totalHashrate;
|
||||||
|
return sum + parseFloat((onlinePool * hashrateShare).toFixed(8));
|
||||||
|
} else if (w.status === 'offline' && offlineWorkers.length > 0) {
|
||||||
|
return sum + parseFloat((offlinePool / offlineWorkers.length).toFixed(8));
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}, 0)
|
||||||
|
} BTC`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filter worker data based on current filter state
|
// Filter worker data based on current filter state
|
||||||
@ -596,4 +638,4 @@ function updateLastUpdated() {
|
|||||||
function numberWithCommas(x) {
|
function numberWithCommas(x) {
|
||||||
if (x == null) return "N/A";
|
if (x == null) return "N/A";
|
||||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user