changed avg blocktime to be calculated from the entire history

pull/5/head
cubedro 9 years ago
parent 11a707b7b1
commit 55ac4ac09a
  1. 24
      lib/history.js

@ -429,13 +429,32 @@ History.prototype.getBlockTimes = function()
.reverse() .reverse()
.map(function (item) .map(function (item)
{ {
return item.block.time; return item.block.time / 1000;
}) })
.value(); .value();
return blockTimes; return blockTimes;
} }
History.prototype.getAvgBlocktime = function()
{
var blockTimes = _( this._items )
.sortByOrder( 'height', false )
// .filter(function (item)
// {
// return item.block.trusted;
// })
// .slice(0, MAX_BINS)
.reverse()
.map(function (item)
{
return item.block.time / 1000;
})
.value();
return _.sum(blockTimes) / (blockTimes.length === 0 ? 1 : blockTimes.length);
}
History.prototype.getGasLimit = function() History.prototype.getGasLimit = function()
{ {
var gasLimitHistory = _( this._items ) var gasLimitHistory = _( this._items )
@ -598,7 +617,8 @@ History.prototype.getCharts = function()
this._callback(null, { this._callback(null, {
height : _.pluck( chartHistory, 'height' ), height : _.pluck( chartHistory, 'height' ),
blocktime : _.pluck( chartHistory, 'blocktime' ), blocktime : _.pluck( chartHistory, 'blocktime' ),
avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length), // avgBlocktime : _.sum(_.pluck( chartHistory, 'blocktime' )) / (chartHistory.length === 0 ? 1 : chartHistory.length),
avgBlocktime : this.getAvgBlocktime(),
difficulty : _.pluck( chartHistory, 'difficulty' ), difficulty : _.pluck( chartHistory, 'difficulty' ),
uncles : _.pluck( chartHistory, 'uncles' ), uncles : _.pluck( chartHistory, 'uncles' ),
transactions : _.pluck( chartHistory, 'transactions' ), transactions : _.pluck( chartHistory, 'transactions' ),

Loading…
Cancel
Save