added pending as a separate call

This commit is contained in:
cubedro 2015-06-01 21:42:50 +03:00
parent 34d23a06a3
commit 54eacc4a9a
6 changed files with 65 additions and 6 deletions

22
app.js
View File

@ -127,8 +127,6 @@ api.on('connection', function(spark) {
{ {
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) ) if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{ {
data.stats.latency = spark.latency;
var stats = Nodes.update(data.id, data.stats); var stats = Nodes.update(data.id, data.stats);
if(stats !== false) if(stats !== false)
@ -146,6 +144,22 @@ api.on('connection', function(spark) {
} }
}); });
spark.on('pending', function(data)
{
if( !_.isUndefined(data.id) && !_.isUndefined(data.stats) )
{
var stats = Nodes.updatePending(data.id, data.stats);
if(stats !== false)
{
client.write({
action: 'pending',
data: stats
});
}
}
});
spark.on('history', function(data) spark.on('history', function(data)
{ {
console.log("got history from " + data.id); console.log("got history from " + data.id);
@ -167,11 +181,11 @@ api.on('connection', function(spark) {
{ {
if( !_.isUndefined(data.id) ) if( !_.isUndefined(data.id) )
{ {
var stats = Nodes.updateLatency(data.id, data.latency); var latency = Nodes.updateLatency(data.id, data.latency);
client.write({ client.write({
action: 'latency', action: 'latency',
data: stats data: latency
}); });
if( Nodes.requiresUpdate(data.id) && (!askedForHistory || _.now() - askedForHistoryTime > 200000) ) if( Nodes.requiresUpdate(data.id) && (!askedForHistory || _.now() - askedForHistoryTime > 200000) )

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -39,6 +39,16 @@ Collection.prototype.update = function(id, stats)
return node.setStats(stats, propagationHistory); return node.setStats(stats, propagationHistory);
} }
Collection.prototype.updatePending = function(id, stats)
{
var node = this.getNode({ id: id });
if (!node)
return false;
return node.setPending(stats);
}
Collection.prototype.addHistory = function(id, blocks) Collection.prototype.addHistory = function(id, blocks)
{ {
var node = this.getNode({ id: id }); var node = this.getNode({ id: id });

View File

@ -130,6 +130,9 @@ Node.prototype.setStats = function(stats, history)
else else
stats.propagationAvg = 0; stats.propagationAvg = 0;
if( !_.isUndefined(this.stats.latency) )
stats.latency = this.stats.latency;
this.stats = stats; this.stats = stats;
return this.getStats(); return this.getStats();
@ -138,6 +141,21 @@ Node.prototype.setStats = function(stats, history)
return false; return false;
} }
Node.prototype.setPending = function(stats)
{
if( !_.isUndefined(stats) && !_.isUndefined(stats.pending) )
{
this.stats.pending = stats.pending;
return {
id: this.id,
pending: this.stats.pending
};
}
return false;
}
Node.prototype.setLatency = function(latency) Node.prototype.setLatency = function(latency)
{ {
if( !_.isUndefined(latency) ) if( !_.isUndefined(latency) )

View File

@ -155,6 +155,9 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
if( index >= 0 && !_.isUndefined($scope.nodes[index]) && !_.isUndefined($scope.nodes[index].stats) ) if( index >= 0 && !_.isUndefined($scope.nodes[index]) && !_.isUndefined($scope.nodes[index].stats) )
{ {
if( !_.isUndefined($scope.nodes[index].stats.latency) )
data.stats.latency = $scope.nodes[index].stats.latency;
if( _.isUndefined(data.stats.hashrate) ) if( _.isUndefined(data.stats.hashrate) )
data.stats.hashrate = 0; data.stats.hashrate = 0;
@ -178,6 +181,19 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
break; break;
case "pending":
var index = findIndex({id: data.id});
if( !_.isUndefined(data.id) && index >= 0 )
{
var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.pending) )
$scope.nodes[index].stats.pending = data.pending;
}
break;
case "info": case "info":
var index = findIndex({id: data.id}); var index = findIndex({id: data.id});
@ -263,6 +279,7 @@ netStatsApp.controller('StatsCtrl', function($scope, $filter, socket, _, toastr)
var node = $scope.nodes[index]; var node = $scope.nodes[index];
if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency) ) if( !_.isUndefined(node) && !_.isUndefined(node.stats) && !_.isUndefined(node.stats.latency) )
// console.log(data.latency);
$scope.nodes[index].stats.latency = data.latency; $scope.nodes[index].stats.latency = data.latency;
} }