cryptocurrency-pool-server
Version:
An extremely efficient, highly scalable, all-in-one, easy to setup cryptocurrency pool server
7 lines • 3.03 kB
JavaScript
function f(){var a={};g=[];for(var b=0;b<h.length;b++)for(var e in h[b].pools)-1===g.indexOf(e)&&g.push(e);for(b=0;b<h.length;b++)for(var d=1E3*h[b].time,c=0;c<g.length;c++){var m=g[c],n=a[m]=a[m]||{hashrate:[],workers:[],blocks:[]};m in h[b].pools?(n.hashrate.push([d,h[b].pools[m].hashrate]),n.workers.push([d,h[b].pools[m].workerCount]),n.blocks.push([d,h[b].pools[m].blocks.pending])):(n.hashrate.push([d,0]),n.workers.push([d,0]),n.blocks.push([d,0]))}k=[];l=[];p=[];for(e in a)k.push({key:e.replace(/(^([a-zA-Zp{M}]))|([ -][a-zA-Zp{M}])/g,
function(a){return a.toUpperCase()}),values:a[e].workers}),l.push({key:e.replace(/(^([a-zA-Zp{M}]))|([ -][a-zA-Zp{M}])/g,function(a){return a.toUpperCase()}),values:a[e].hashrate}),p.push({key:e.replace(/(^([a-zA-Zp{M}]))|([ -][a-zA-Zp{M}])/g,function(a){return a.toUpperCase()}),values:a[e].blocks})}function q(a){a=d3.time.format("%I:%M %p")(new Date(a));0===a.indexOf("0")&&(a=a.slice(1));return a}
function r(){nv.addGraph(function(){t=nv.models.stackedAreaChart().margin({left:40,right:40}).x(function(a){return a[0]}).y(function(a){return a[1]}).useInteractiveGuideline(!0).clipEdge(!0);t.xAxis.tickFormat(q);t.yAxis.tickFormat(d3.format("d"));d3.select("#poolWorkers").datum(k).call(t);return t});nv.addGraph(function(){u=nv.models.lineChart().margin({left:60,right:40}).x(function(a){return a[0]}).y(function(a){return a[1]}).useInteractiveGuideline(!0);u.xAxis.tickFormat(q);u.yAxis.tickFormat(function(a){var b=
-1;do a/=1024,b++;while(1024<a);return Math.round(a)+[" KH"," MH"," GH"," TH"," PH"][b]});d3.select("#poolHashrate").datum(l).call(u);return u});nv.addGraph(function(){v=nv.models.multiBarChart().x(function(a){return a[0]}).y(function(a){return a[1]});v.xAxis.tickFormat(q);v.yAxis.tickFormat(d3.format("d"));d3.select("#poolBlocks").datum(p).call(v);return v})}function w(){t.update();u.update();v.update()}var k,l,p,t,u,v,h,g;
$(function(){window.statsSource=new EventSource("/api/live_stats");window.statsSource.addEventListener("message",function(a){a=JSON.parse(a.data);for(algo in a.algos)$("#statsMiners"+algo).text(a.algos[algo].workers),$("#statsHashrate"+algo).text(a.algos[algo].hashrateString);for(var b in a.pools)$("#statsMiners"+b).text(a.pools[b].workerCount),$("#statsHashrate"+b).text(a.pools[b].hashrateString)});nv.utils.windowResize(w);$.getJSON("/api/pool_stats",function(a){h=a;f();r()});window.statsSource.addEventListener("message",
function(a){a=JSON.parse(a.data);h.push(a);a:{for(b in a.pools)if(!g||-1===g.indexOf(b)){var b=!0;break a}b=!1}if(b||Object.keys(a.pools).length>g.length)f(),r();else{b=1E3*a.time;for(var e=0;e<g.length;e++){for(var d=g[e],c=0;c<k.length;c++)if(k[c].key===d){k[c].values.shift();k[c].values.push([b,d in a.pools?a.pools[d].workerCount:0]);break}for(c=0;c<l.length;c++)if(l[c].key===d){l[c].values.shift();l[c].values.push([b,d in a.pools?a.pools[d].hashrate:0]);break}for(c=0;c<p.length;c++)if(p[c].key===
d){p[c].values.shift();p[c].values.push([b,d in a.pools?a.pools[d].blocks.pending:0]);break}}w()}})});