forked from Karbovanets/Karbowanec-Blockchain-Explorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pools.html
211 lines (172 loc) · 6.16 KB
/
pools.html
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
<!-- // pools stats by MainCoins @ http://krb.mypool.name -->
<style>
#pools_rows > tr > td{
vertical-align: middle;
font-family: 'Inconsolata', monospace;
text-align: center;
}
#pools_rows > tr > td:first-child {
text-align: left;
}
</style>
<div class="row">
<div class="col-lg-12">
<div class="blocksStatHolder">
<span><i class="fa fa-tachometer"></i> Швидкість мережі*: <span id="totalPoolsHashrate"></span></span>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="table-responsive">
<table id="network-hash" class="table table-hover">
<thead>
<tr>
<th><span id="symbol"></span> Пули</th>
<th><i class="fa fa-bars"></i> Висота</th>
<th><i class="fa fa-tachometer"></i> Хешрейт</th>
<th><i class="fa fa-group"></i> Майнери</th>
<th><i class="fa fa-money"></i> Комісії</th>
<th><i class="fa fa-clock-o"></i> Останній блок</th>
</tr>
</thead>
<tbody id="pools_rows">
</tbody>
</table>
</div>
</div>
</div>
<div class="container">
<div class="row">
<div class="col-lg-6 col-md-6">
<canvas id="poolsChart" style="margin: 0 auto;"></canvas>
</div>
</div>
</div>
<br />
<div class="container">
<div class="row">
<div class="col-lg-12">
<small style="font-size: 0.55em;">* Загальна швидкість усіх відомих пулів, перелічених вище.</small>
</div>
</div>
</div>
<script src="js/Chart.bundle.min.js"></script>
<script>
window.NETWORK_STAT_MAP = new Map(networkStat[symbol.toLowerCase()]);
window.poolNames = [];
window.poolHashrates = [];
window.colors = [];
totalHashrate = 0;
var poolsRefreshed = 0;
NETWORK_STAT_MAP.forEach((url, host, map) => {
$.getJSON(url + '/stats', (data, textStatus, jqXHR) => {
var d = new Date(parseInt(data.pool.lastBlockFound));
var datestring = ("0" + d.getDate()).slice(-2) + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + d.getFullYear() + " " + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
$('#pools_rows').append('<tr><td id=host'+host+'><a target=blank href=http://'+host+'>'+host+'</a></td><td id=height'+host+'>'+data.network.height+'</td><td id=hashrate'+host+'>'+data.pool.hashrate+' H/s</td><td id=miners'+host+'>'+data.pool.miners+'</td><td id=totalFree'+host+'>'+calculateTotalFree(data)+'%</td><td id=lastFound'+host+'>'+datestring+'</td><</tr>');
totalHashrate += parseInt(data.pool.hashrate);
updateText('totalPoolsHashrate', getReadableHashRateString(totalHashrate) + '/sec');
poolNames.push(host);
poolHashrates.push(parseInt(data.pool.hashrate));
window.colors.push(getRandomColor());
});
poolsRefreshed++;
if (poolsRefreshed === NETWORK_STAT_MAP.size){
setTimeout(function(){ displayChart(); }, 1000);
}
});
currentPage = {
destroy: function(){
},
init: function(){
},
update: function(){
}
};
function calculateTotalFree(config) {
let totalFee = config.config.fee;
for (let property in config.config.donation) {
if (config.config.donation.hasOwnProperty(property)) {
totalFee += config.config.donation[property];
}
}
return totalFee;
}
function displayChart() {
var ctx = document.getElementById("poolsChart");
var chartData = {
labels: poolNames,
datasets: [{
data: poolHashrates,
backgroundColor: colors,
borderWidth: 1,
segmentShowStroke: false
}]
};
var options = {
title: {
display: true,
text: 'Швидкість пулів'
},
tooltips: {
enabled: true,
mode: 'single',
callbacks: {
title: function (tooltipItem, data) { return data.labels[tooltipItem[0].index]; },
label: function (tooltipItem, data) {
var amount = data.datasets[tooltipItem.datasetIndex].data[tooltipItem.index];
var total = eval(data.datasets[tooltipItem.datasetIndex].data.join("+"));
return amount + ' / ' + total + ' H/s (' + parseFloat(amount * 100 / total).toFixed(2) + '%)';
}
}
}
};
window.poolsChart = new Chart(ctx,{
type: 'pie',
data: chartData,
options: options
});
}
setInterval(function(){
var totalHashrate = 0;
poolNames = [];
poolHashrates = [];
var poolsRefreshed = 0;
NETWORK_STAT_MAP.forEach((url, host, map) => {
$.getJSON(url + '/stats', (data, textStatus, jqXHR) => {
updateText('height'+host, data.network.height);
updateText('hashrate'+host, data.pool.hashrate);
updateText('miners'+host, data.pool.miners);
updateText('totalFree'+host, calculateTotalFree(data)+'%');
var d = new Date(parseInt(data.pool.lastBlockFound));
var datestring = ("0" + d.getDate()).slice(-2) + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + d.getFullYear() + " " + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2);
updateText('lastFound'+host, datestring);
totalHashrate += parseInt(data.pool.hashrate);
updateText('totalPoolsHashrate', getReadableHashRateString(totalHashrate) + '/sec');
});
poolsRefreshed++;
if (poolsRefreshed === NETWORK_STAT_MAP.size){
setTimeout(function(){ refreshChart(); }, 1000);
}
});
}, 300000);
function refreshChart() {
var pool_rows = $('#pools_rows').children();
for (var i = 0; i < pool_rows.length; i++) {
var row = $(pool_rows[i]);
var label = row.find('td:first').text();
var hashrate = row.find('td:nth-child(3)').text();
poolsChart.data.labels[i] = label;
poolsChart.data.datasets[0].data[i] = parseInt(hashrate);
}
poolsChart.update();
}
function getRandomColor() {
var letters = '0123456789ABCDEF';
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
</script>