Ethereum network status dashboard for PoW and PoA networks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ethstats-server/public/js/filters.js

83 lines
1.7 KiB

10 years ago
'use strict';
/* Filters */
angular.module('netStatsApp.filters', [])
.filter('nodesActiveClass', function() {
return function(active, total) {
var ratio = active/total;
if(ratio >= 0.9)
return 'text-success';
if(ratio >= 0.75)
return 'text-info';
if(ratio >= 0.5)
return 'text-warning';
return 'text-danger';
};
})
10 years ago
.filter('mainClass', function() {
10 years ago
return function(node, bestBlock) {
if( ! node.active)
return 'text-danger';
10 years ago
10 years ago
if(node.peers === 0)
return 'text-danger';
10 years ago
10 years ago
return timeClass(node.block.timestamp);
};
10 years ago
})
.filter('peerClass', function() {
10 years ago
return function(peers) {
return peerClass(peers);
};
})
.filter('miningClass', function() {
10 years ago
return function(mining) {
return (! mining ? 'text-danger' : 'text-success');
10 years ago
};
})
.filter('miningIconClass', function() {
10 years ago
return function(mining) {
return (! mining ? 'icon-cancel' : 'icon-check');
};
})
.filter('blockClass', function() {
10 years ago
return function(current, best) {
return (best - current <= 1 ? 'text-success' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger'));
10 years ago
};
10 years ago
})
.filter('timeClass', function() {
return function(timestamp) {
10 years ago
return timeClass(timestamp);
};
}).filter('geoTooltip', function() {
return function(geo) {
return geo.city + ", " + geo.country;
};
10 years ago
});
10 years ago
10 years ago
function peerClass(peers)
{
return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success'));
}
10 years ago
10 years ago
function timeClass(timestamp)
{
var time = Math.floor((new Date()).getTime() / 1000);
var diff = time - timestamp;
10 years ago
10 years ago
if(diff <= 12)
return 'text-success';
10 years ago
10 years ago
if(diff <= 20)
return 'text-info';
if(diff <= 30)
return 'text-warning';
return 'text-danger';
}