-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite
More file actions
373 lines (344 loc) · 12.1 KB
/
site
File metadata and controls
373 lines (344 loc) · 12.1 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Quai Mining Advisor</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@3.0.1"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.2.0"></script>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
line-height: 1.6;
}
.card {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.chart-container {
height: 250px;
margin-top: 20px;
}
.value {
font-weight: bold;
color: #2c3e50;
}
.recommendation {
padding: 15px;
border-radius: 8px;
text-align: center;
margin-top: 20px;
font-size: 1.2em;
font-weight: bold;
}
.recommend-quai {
background-color: #e8f5e9;
border-left: 5px solid #4caf50;
color: #2e7d32;
}
.recommend-qi {
background-color: #ffebee;
border-left: 5px solid #f44336;
color: #c62828;
}
.trend {
font-size: 0.9em;
margin-top: 5px;
font-weight: normal;
}
.up { color: #2e7d32; }
.down { color: #c62828; }
button, .time-btn {
background: #3f51b5;
color: white;
border: none;
padding: 8px 15px;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
margin-bottom: 10px;
}
button:hover, .time-btn:hover {
background: #303f9f;
}
.time-btn.active {
background: #1a237e;
}
.btn-group {
margin-bottom: 15px;
}
.footer {
margin-top: 40px;
text-align: center;
padding: 20px;
color: #666;
font-size: 0.9em;
}
.tip-address {
font-family: monospace;
background: #f0f0f0;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
display: inline-block;
margin-left: 5px;
transition: all 0.2s;
}
.tip-address:hover {
background: #e0e0e0;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body>
<h1>Quai Mining Advisor</h1>
<div class="card">
<h2>Network Status</h2>
<p>
Current Hashrate: <span id="hashrate" class="value">-</span>
<button onclick="changeUnit('ghs')">GH/s</button>
<button onclick="changeUnit('ths')">TH/s</button>
</p>
<p>Block Time: <span id="blockTime" class="value">-</span> seconds</p>
<div class="btn-group">
<span>View: </span>
<button class="time-btn active" onclick="changeTimeRange('hour')">Hour</button>
<button class="time-btn" onclick="changeTimeRange('day')">Day</button>
<button class="time-btn" onclick="changeTimeRange('week')">Week</button>
</div>
<div class="chart-container">
<canvas id="hashrateChart"></canvas>
</div>
</div>
<div class="card">
<h2>Mining Recommendation</h2>
<div id="miningRecommendation" class="recommendation">
Gathering data...
</div>
<p style="text-align: center; margin-top: 10px;">
<em>Strategy: Mine QUAI when hashrate is rising, QI when falling</em>
</p>
</div>
<div class="footer">
<div class="tooltip">
Tip me:
<span id="tipAddress" class="tip-address" onclick="copyAddress()">0x00700BD124Ffab1f7062D177aF1BB323Efee2665</span>
<span class="tooltiptext">Click to copy address</span>
</div>
</div>
<script>
// Configuration
const API_URL = "https://quaiscan.io/api/v2/stats";
const ctx = document.getElementById('hashrateChart').getContext('2d');
let historicalData = [];
let currentUnit = 'ghs';
let currentRange = 'hour';
// Initialize chart with time scale
const chart = new Chart(ctx, {
type: 'line',
data: {
datasets: [{
label: 'Hashrate',
data: [],
borderColor: '#3f51b5',
backgroundColor: 'rgba(63, 81, 181, 0.1)',
tension: 0.1,
fill: true
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: false,
title: {
display: true,
text: 'GH/s'
}
},
x: {
type: 'time',
time: {
tooltipFormat: 'HH:mm',
displayFormats: {
hour: 'HH:mm',
day: 'MMM dd',
week: 'MMM dd'
}
},
title: {
display: true,
text: 'Time'
}
}
}
}
});
// Change time range
function changeTimeRange(range) {
currentRange = range;
document.querySelectorAll('.time-btn').forEach(btn => {
btn.classList.toggle('active', btn.textContent.toLowerCase() === range);
});
updateChart();
}
// Update chart time settings based on range
function updateTimeScale() {
let unit, stepSize;
switch(currentRange) {
case 'hour':
unit = 'minute';
stepSize = 10;
break;
case 'day':
unit = 'hour';
stepSize = 4;
break;
case 'week':
unit = 'day';
stepSize = 1;
break;
}
chart.options.scales.x.time.unit = unit;
chart.options.scales.x.time.stepSize = stepSize;
chart.update();
}
// Fetch data from API
async function fetchData() {
try {
const response = await fetch(API_URL);
const data = await response.json();
// Calculate hashrate (simplified approximation)
const blockTimeSec = data.average_block_time / 1000;
const hashrate = 1e9 / blockTimeSec; // Basic approximation in H/s
// Store data with timestamp
historicalData.push({
x: new Date(),
y: hashrate
});
// Filter data based on current time range
const now = new Date();
let cutoffTime;
switch(currentRange) {
case 'hour':
cutoffTime = now.getTime() - 3600000; // 1 hour
break;
case 'day':
cutoffTime = now.getTime() - 86400000; // 24 hours
break;
case 'week':
cutoffTime = now.getTime() - 604800000; // 7 days
break;
}
historicalData = historicalData.filter(point => point.x.getTime() > cutoffTime);
// Update UI
updateDisplay(hashrate, blockTimeSec);
updateChart();
updateRecommendation();
} catch (error) {
console.error("Error fetching data:", error);
document.getElementById('hashrate').textContent = "Error";
}
}
// Update displayed values
function updateDisplay(hashrate, blockTime) {
const displayValue = currentUnit === 'ghs'
? (hashrate / 1e9).toFixed(2)
: (hashrate / 1e12).toFixed(4);
document.getElementById('hashrate').textContent = displayValue;
document.getElementById('blockTime').textContent = blockTime.toFixed(2);
// Update chart units
chart.options.scales.y.title.text = currentUnit === 'ghs' ? 'GH/s' : 'TH/s';
}
// Update chart with new data
function updateChart() {
chart.data.datasets[0].data = historicalData.map(point => ({
x: point.x,
y: currentUnit === 'ghs' ? point.y / 1e9 : point.y / 1e12
}));
updateTimeScale();
}
// Change unit between GH/s and TH/s
function changeUnit(unit) {
currentUnit = unit;
updateChart();
if (historicalData.length > 0) {
updateDisplay(historicalData[historicalData.length-1].y,
document.getElementById('blockTime').textContent);
}
}
// Generate mining recommendation
function updateRecommendation() {
if (historicalData.length < 3) return;
const current = historicalData[historicalData.length - 1].y;
const previous = historicalData[historicalData.length - 2].y;
const change = ((current - previous) / previous) * 100;
let trend, recommendation;
if (change > 1) {
trend = "up";
recommendation = "QUAI";
} else if (change < -1) {
trend = "down";
recommendation = "QI";
} else {
trend = "stable";
recommendation = "QI (neutral trend)";
}
const element = document.getElementById('miningRecommendation');
element.className = `recommendation ${recommendation.includes('QUAI') ? 'recommend-quai' : 'recommend-qi'}`;
element.innerHTML = `
Mine: <strong>${recommendation}</strong>
<div class="trend ${trend}">
(${Math.abs(change).toFixed(2)}% ${trend})
</div>
`;
}
// Handle address copying
function copyAddress() {
const address = '0x00700BD124Ffab1f7062D177aF1BB323Efee2665';
// Copy to clipboard
navigator.clipboard.writeText(address).then(() => {
const tooltip = document.querySelector('.tooltiptext');
tooltip.textContent = 'Copied!';
setTimeout(() => {
tooltip.textContent = 'Click to copy address';
}, 2000);
});
}
// Initial load and refresh every 30 seconds
fetchData();
setInterval(fetchData, 30000);
</script>
</body>
</html>