Spaces:
Paused
Paused
File size: 4,907 Bytes
9aad16f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
class MiningDashboard {
constructor() {
this.statsHistory = {
timestamps: [],
hashrates: [],
totalHashes: [],
blocksFound: []
};
this.setupEventListeners();
this.setupCharts();
this.startAutoRefresh();
}
setupEventListeners() {
document.getElementById('startMining').addEventListener('click', () => this.startMining());
document.getElementById('stopMining').addEventListener('click', () => this.stopMining());
}
setupCharts() {
// Initialize empty charts
this.hashrateChart = Plotly.newPlot('hashrateChart', [{
x: [],
y: [],
type: 'scatter',
mode: 'lines+markers',
name: 'Hashrate',
line: { color: '#2ecc71' }
}], {
title: 'Mining Hashrate (KH/s)',
template: 'plotly_dark',
paper_bgcolor: '#2d2d2d',
plot_bgcolor: '#2d2d2d',
xaxis: { title: 'Time' },
yaxis: { title: 'Hashrate (KH/s)' }
});
this.totalHashesChart = Plotly.newPlot('totalHashesChart', [{
x: [],
y: [],
type: 'scatter',
mode: 'lines',
name: 'Total Hashes',
line: { color: '#3498db' }
}], {
title: 'Total Hashes',
template: 'plotly_dark',
paper_bgcolor: '#2d2d2d',
plot_bgcolor: '#2d2d2d',
xaxis: { title: 'Time' },
yaxis: { title: 'Total Hashes' }
});
}
async startMining() {
try {
const response = await fetch('/start_mining', { method: 'POST' });
const data = await response.json();
this.updateStatus(data.message);
} catch (error) {
console.error('Error starting mining:', error);
this.updateStatus('Error starting mining');
}
}
async stopMining() {
try {
const response = await fetch('/stop_mining', { method: 'POST' });
const data = await response.json();
this.updateStatus(data.message);
} catch (error) {
console.error('Error stopping mining:', error);
this.updateStatus('Error stopping mining');
}
}
async updateStats() {
try {
const response = await fetch('/get_stats');
const stats = await response.json();
// Update stats display
document.getElementById('status').textContent = stats.status;
document.getElementById('hashrate').textContent = stats.hashrate;
document.getElementById('totalHashes').textContent = stats.total_hashes;
document.getElementById('blocksFound').textContent = stats.blocks_found;
document.getElementById('bestHash').textContent = stats.best_hash;
document.getElementById('difficulty').textContent = stats.difficulty;
// Update block alert
const alertBox = document.getElementById('blockAlert');
alertBox.textContent = stats.block_alert;
alertBox.className = 'alert-box' + (stats.blocks_found > 0 ? ' success' : '');
// Update charts
if (stats.status === 'Running') {
this.updateCharts(stats);
}
} catch (error) {
console.error('Error updating stats:', error);
}
}
updateCharts(stats) {
const currentTime = new Date().toLocaleTimeString();
// Update history
this.statsHistory.timestamps.push(currentTime);
this.statsHistory.hashrates.push(parseFloat(stats.hashrate));
this.statsHistory.totalHashes.push(parseInt(stats.total_hashes.replace(/,/g, '')));
// Keep only last 100 points
if (this.statsHistory.timestamps.length > 100) {
this.statsHistory.timestamps.shift();
this.statsHistory.hashrates.shift();
this.statsHistory.totalHashes.shift();
}
// Update plots
Plotly.update('hashrateChart', {
x: [this.statsHistory.timestamps],
y: [this.statsHistory.hashrates]
});
Plotly.update('totalHashesChart', {
x: [this.statsHistory.timestamps],
y: [this.statsHistory.totalHashes]
});
}
startAutoRefresh() {
setInterval(() => this.updateStats(), 1000);
}
updateStatus(message) {
document.getElementById('status').textContent = message;
}
}
// Initialize dashboard when page loads
document.addEventListener('DOMContentLoaded', () => {
window.dashboard = new MiningDashboard();
}); |