|
|
@ -1,17 +1,23 @@ |
|
|
|
var models = require('../models'); |
|
|
|
var models = require('../models'); |
|
|
|
var express = require('express'); |
|
|
|
var express = require('express'); |
|
|
|
var router = express.Router(); |
|
|
|
var router = express.Router(); |
|
|
|
|
|
|
|
var HeightOffset = require('../config/config')['syncHeightOffset'] || 0; |
|
|
|
|
|
|
|
|
|
|
|
function formatRate(bytes, decimals = 2) { |
|
|
|
function formatRate(hashrate, decimals = 2) { |
|
|
|
if (bytes === 0) return '0 Bytes'; |
|
|
|
if (hashrate === 0) return '0 H/s'; |
|
|
|
|
|
|
|
|
|
|
|
const k = 1000; |
|
|
|
const k = 1000; |
|
|
|
const dm = decimals < 0 ? 0 : decimals; |
|
|
|
const dm = decimals < 0 ? 0 : decimals; |
|
|
|
const sizes = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s', 'EH/s', 'ZH/s', 'YH/s']; |
|
|
|
const sizes = ['H/s', 'KH/s', 'MH/s', 'GH/s', 'TH/s', 'PH/s', 'EH/s', 'ZH/s', 'YH/s']; |
|
|
|
|
|
|
|
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k)); |
|
|
|
const i = Math.floor(Math.log(hashrate) / Math.log(k)); |
|
|
|
|
|
|
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; |
|
|
|
return parseFloat((hashrate / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function shorterHash(hash) { |
|
|
|
|
|
|
|
var parts = hash.match(/[\s\S]{1,14}/g) || []; |
|
|
|
|
|
|
|
return parts[0] + '...' + parts[parts.length-1]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* GET home page. */ |
|
|
|
/* GET home page. */ |
|
|
@ -26,8 +32,10 @@ router.get('/', async function(req, res, next) { |
|
|
|
arrayItem.ago = arrayItem.time.toUTCString().substring(5); |
|
|
|
arrayItem.ago = arrayItem.time.toUTCString().substring(5); |
|
|
|
arrayItem.difficulty = parseFloat(arrayItem.difficulty).toFixed(8); |
|
|
|
arrayItem.difficulty = parseFloat(arrayItem.difficulty).toFixed(8); |
|
|
|
arrayItem.hashrate = formatRate(arrayItem.hashrate, 4); |
|
|
|
arrayItem.hashrate = formatRate(arrayItem.hashrate, 4); |
|
|
|
|
|
|
|
arrayItem.hash_short = shorterHash(arrayItem.hash); |
|
|
|
}); |
|
|
|
}); |
|
|
|
res.render('index', { |
|
|
|
res.render('index', { |
|
|
|
|
|
|
|
HeightOffset, |
|
|
|
blocks, |
|
|
|
blocks, |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|