2015-01-20 19:29:31 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* Controllers */
|
|
|
|
|
2015-01-28 23:38:54 +01:00
|
|
|
function StatsCtrl($scope, socket, _) {
|
2015-01-20 19:29:31 +01:00
|
|
|
|
|
|
|
// Socket listeners
|
|
|
|
// ----------------
|
|
|
|
|
|
|
|
socket.on('init', function(data){
|
|
|
|
$scope.nodes = data.nodes;
|
2015-01-29 17:50:16 +01:00
|
|
|
|
|
|
|
updateStats();
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('update', function(data){
|
|
|
|
$scope.nodes[data.node.id] = data.node;
|
|
|
|
|
|
|
|
updateStats();
|
|
|
|
});
|
|
|
|
|
|
|
|
function updateStats()
|
|
|
|
{
|
2015-01-20 19:29:31 +01:00
|
|
|
$scope.nodesTotal = $scope.nodes.length;
|
2015-01-28 23:38:54 +01:00
|
|
|
$scope.nodesActive = _.filter($scope.nodes, function(node){ return node.stats.active == true; }).length;
|
|
|
|
$scope.bestBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.height); }).stats.block.height;
|
2015-01-29 00:41:52 +01:00
|
|
|
$scope.lastBlock = _.max($scope.nodes, function(node){ return parseInt(node.stats.block.timestamp); }).stats.block.timestamp;
|
2015-01-29 17:50:16 +01:00
|
|
|
}
|
2015-01-20 19:29:31 +01:00
|
|
|
}
|