show hashrates

This commit is contained in:
stoffu
2018-11-13 09:37:58 +09:00
parent 6e6a138057
commit bcb469a0a3
5 changed files with 38 additions and 5 deletions
+11 -2
View File
@@ -1,10 +1,19 @@
function get_chart(chartData) {
function get_diff_target(diff_targets, height) {
for (var i = diff_targets.length - 1; i >= 0; --i) {
if (diff_targets[i].height <= height)
return diff_targets[i].value;
}
return 0;
}
function get_chart(chartData, diff_targets) {
chartData.shift();
for (var i = 0; i < chartData.length; ++i) {
chartData[i].date = new Date(1000 * chartData[i][0]);
chartData[i].height = i + 1;
chartData[i].difficulty = chartData[i][1];
chartData[i].hashrate = formatHashrate(chartData[i].difficulty / get_diff_target(diff_targets, chartData[i].height), 2);
}
var chart = AmCharts.makeChart("chartdiv", {
@@ -22,7 +31,7 @@ function get_chart(chartData) {
"graphs": [{
"id": "g1",
"lineColor": "#67B7DC",
"balloonText": "Diff: <b>[[value]]</b>\nHeight: <b>[[height]]</b>",
"balloonText": "Height: <b>[[height]]</b>\nDiff: <b>[[value]]</b>\n[[hashrate]]",
"bullet": "round",
"bulletBorderAlpha": 1,
"bulletColor": "#FFFFFF",
+10
View File
@@ -9,6 +9,16 @@ function formatBytes(bytes, decimal) {
return "<b>" + parseFloat((bytes / Math.pow(c, f)).toFixed(d)) + "</b> " + e[f]
}
function formatHashrate(hr, decimal) {
if (0 == hr)
return "0 H/s";
var c = 1000;
var d = decimal || 2;
var e = ["H/s", "kH/s", "MH/s", "GH/s", "TH/s", "PH/s", "EH/s", "ZH/s", "YH/s"];
var f = Math.floor(Math.log(hr) / Math.log(c));
return "<b>" + parseFloat((hr / Math.pow(c, f)).toFixed(d)) + "</b> " + e[f]
}
function print_money(amount, decimal_point) {
var s1 = String(amount);
while (s1.length < decimal_point+1)