diff --git a/models/collection.js b/models/collection.js index c38b5a5..c7917b1 100644 --- a/models/collection.js +++ b/models/collection.js @@ -23,9 +23,7 @@ Collection.prototype.update = function(id, stats) if(!node) return false; - node.stats = stats; - - return node.getStats(); + return node.setStats(stats); } Collection.prototype.inactive = function(id) diff --git a/models/node.js b/models/node.js index 5f58bd3..35afd86 100644 --- a/models/node.js +++ b/models/node.js @@ -18,7 +18,8 @@ var Node = function Node(data) gasLimit: 0, timestamp: 0, arrival: 0, - propagation: 0 + propagation: 0, + received: 0 }, blocktimeAvg: 0, blockTimes: [], @@ -72,6 +73,24 @@ Node.prototype.getInfo = function() return {id: this.id, info: this.info, geo: this.geo, stats: this.stats}; } +Node.prototype.setStats = function(stats) +{ + if(typeof stats !== undefined && typeof stats.block !== undefined && typeof stats.block.number !== undefined) + { + if(stats.block.number !== this.stats.number){ + stats.block.received == (new Date()).getTime() - stats.block.arrival; + } else { + stats.block.received = this.stats.block.received; + } + + this.stats = stats; + + return this.getStats(); + } + + return false; +} + Node.prototype.getStats = function() { return {id: this.id, stats: this.stats}; diff --git a/package.json b/package.json index cf1fbee..b76f0c2 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "private": true, "engines": { "node": "0.12.0", - "npm": "2.5.0" + "npm": "2.5.1" }, "scripts": { "start": "node ./bin/www" diff --git a/public/js/controllers.js b/public/js/controllers.js index 5c94201..2c048e8 100644 --- a/public/js/controllers.js +++ b/public/js/controllers.js @@ -69,13 +69,6 @@ function StatsCtrl($scope, $filter, socket, _, toastr) { break; case "update": - if(typeof $scope.nodes[findIndex({id: data.id})].stats !== 'undefined' && typeof $scope.nodes[findIndex({id: data.id})].stats.block !== 'undefined'){ - if($scope.nodes[findIndex({id: data.id})].stats.block.number != data.stats.block.number){ - data.stats.block.when = (new Date()).getTime() - data.stats.block.arrival; - } else { - data.stats.block.when = $scope.nodes[findIndex({id: data.id})].stats.block.when; - } - } $scope.nodes[findIndex({id: data.id})].stats = data.stats; break; diff --git a/public/js/filters.js b/public/js/filters.js index 517444b..e004fbe 100644 --- a/public/js/filters.js +++ b/public/js/filters.js @@ -116,7 +116,6 @@ angular.module('netStatsApp.filters', []) }) .filter('blockPropagationFilter', function() { return function(ms) { - // ms = (new Date()).getTime() - ms; var result = 0; if(ms < 1000) { diff --git a/views/index.jade b/views/index.jade index 05d8a3f..0fa50ae 100644 --- a/views/index.jade +++ b/views/index.jade @@ -128,5 +128,5 @@ block content //- div.small Difficulty: {{node.stats.block.difficulty | gasFilter}} | Gas used: {{node.stats.block.gasUsed | gasFilter}} | Min gas price: {{node.stats.block.minGasPrice | gasFilter}} | Gas limit: {{node.stats.block.gasLimit | gasFilter}} td(style="padding-left: 18px;") {{node.stats.block.txCount}} td(class="{{ node.stats.block.timestamp | timeClass }}") {{node.stats.block.timestamp | blockTimeFilter }} - td(class="{{ node.stats.block.when | propagationTimeClass }}") {{node.stats.block.when | blockPropagationFilter}} + td(class="{{ node.stats.block.received | propagationTimeClass }}") {{node.stats.block.received | blockPropagationFilter}} td(class="{{ node.stats.uptime | upTimeClass }}") {{ node.stats.uptime | upTimeFilter }}