Merge pull request #278 from cubedro/develop

Changed avg blocktime to be calculated from the entire history
This commit is contained in:
Marian OANCΞA 2015-09-14 19:52:40 +03:00
commit 8134928d5e
1 changed files with 22 additions and 2 deletions

View File

@ -429,13 +429,32 @@ History.prototype.getBlockTimes = function()
.reverse()
.map(function (item)
{
return item.block.time;
return item.block.time / 1000;
})
.value();
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()
{
var gasLimitHistory = _( this._items )
@ -598,7 +617,8 @@ History.prototype.getCharts = function()
this._callback(null, {
height : _.pluck( chartHistory, 'height' ),
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' ),
uncles : _.pluck( chartHistory, 'uncles' ),
transactions : _.pluck( chartHistory, 'transactions' ),