In an effort to streamline my chart to only include data for "zelcash", I am currently faced with the issue of fluctuating values causing the line graph to be inconsistent. This is because the results show zelcash with 0 as the hashrate, along with actual varying values. If I can filter out all other data points (snowgem, votecoin, commercium), then the chart should display accurately.
function buildChartData(){
var pools = {};
poolKeys = [];
for (var i = 0; i < statData.length; i++){
for (var pool in statData[i].pools){
if (poolKeys.indexOf("zelcash") === -1)
poolKeys.push("zelcash");
}
}
for (var i = 0; i < statData.length; i++) {
var time = statData[i].time * 1000;
for (var f = 0; f < poolKeys.length; f++){
var pName = poolKeys[f];
var a = pools[pName] = (pools[pName] || {
hashrate: []
});
if (pName in statData[i].pools){
a.hashrate.push([time, statData[i].pools[pName].hashrate]);
}
else{
a.hashrate.push([time, 0]);
}
}
}
poolHashrateData = [];
for (var pool in pools){
poolHashrateData.push({
key: pool,
values: pools[pool].hashrate
});
$('#statsHashrateAvg' + pool).text(getReadableHashRateString(calculateAverageHashrate(pool)));
}
}
function displayCharts(){
nv.addGraph(function() {
poolHashrateChart = nv.models.lineChart()
.margin({left: 80, right: 30})
.x(function(d){ return d[0] })
.y(function(d){ return d[1] })
.useInteractiveGuideline(true);
poolHashrateChart.xAxis.tickFormat(timeOfDayFormat);
poolHashrateChart.yAxis.tickFormat(function(d){
return getReadableHashRateString(d);
});
d3.select('#poolHashrate').datum(poolHashrateData).call(poolHashrateChart);
return poolHashrateChart;
});
}
$.getJSON('/api/pool_stats', function(data){
statData = data;
buildChartData();
displayCharts();
});
JSON:
[
{
"time": 1529585412,
"pools": {
"commercium": {
"hashrate": 5189503226.486427,
"workerCount": 4,
"blocks": {
"pending": 0,
"confirmed": 16,
"orphaned": 0
}
}
}
},
...
]