2015-01-20 19:29:31 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/* Filters */
|
|
|
|
|
2015-01-29 17:50:16 +01:00
|
|
|
angular.module('netStatsApp.filters', [])
|
2015-02-05 00:30:16 +01:00
|
|
|
.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';
|
|
|
|
};
|
|
|
|
})
|
2015-01-30 22:37:38 +01:00
|
|
|
.filter('mainClass', function() {
|
2015-02-05 05:32:42 +01:00
|
|
|
return function(node, bestBlock) {
|
2015-02-08 16:03:05 +01:00
|
|
|
return mainClass(node, bestBlock);
|
2015-02-05 05:32:42 +01:00
|
|
|
};
|
2015-01-30 22:37:38 +01:00
|
|
|
})
|
2015-01-29 17:50:16 +01:00
|
|
|
.filter('peerClass', function() {
|
2015-02-05 05:32:42 +01:00
|
|
|
return function(peers) {
|
|
|
|
return peerClass(peers);
|
|
|
|
};
|
2015-01-29 17:50:16 +01:00
|
|
|
})
|
|
|
|
.filter('miningClass', function() {
|
2015-02-05 05:32:42 +01:00
|
|
|
return function(mining) {
|
2015-02-05 05:59:24 +01:00
|
|
|
return (! mining ? 'text-danger' : 'text-success');
|
2015-02-05 05:32:42 +01:00
|
|
|
};
|
2015-01-29 17:50:16 +01:00
|
|
|
})
|
|
|
|
.filter('miningIconClass', function() {
|
2015-02-05 05:32:42 +01:00
|
|
|
return function(mining) {
|
|
|
|
return (! mining ? 'icon-cancel' : 'icon-check');
|
|
|
|
};
|
2015-01-29 17:50:16 +01:00
|
|
|
})
|
2015-02-17 16:29:26 +01:00
|
|
|
.filter('nodeVersion', function($sce) {
|
2015-02-17 15:07:50 +01:00
|
|
|
return function(version) {
|
2015-02-17 16:29:26 +01:00
|
|
|
version = version.replace('eth version ', 'v')
|
|
|
|
.replace("\n" + 'Network protocol version: ', ' (')
|
|
|
|
.replace("\n" + 'Client database version: ', ',')
|
2015-02-18 09:57:45 +01:00
|
|
|
.replace("\n" + 'Build: ', ') - ')
|
|
|
|
.replace('/Debug', '')
|
|
|
|
.replace('/.', '');
|
2015-02-17 16:29:26 +01:00
|
|
|
return $sce.trustAsHtml(version);
|
|
|
|
};
|
2015-02-17 15:07:50 +01:00
|
|
|
})
|
2015-01-29 17:50:16 +01:00
|
|
|
.filter('blockClass', function() {
|
2015-02-05 05:32:42 +01:00
|
|
|
return function(current, best) {
|
2015-02-05 05:59:24 +01:00
|
|
|
return (best - current <= 1 ? 'text-success' : (best - current > 1 && best - current < 4 ? 'text-warning' : 'text-danger'));
|
2015-02-05 05:32:42 +01:00
|
|
|
};
|
2015-02-05 02:33:58 +01:00
|
|
|
})
|
2015-02-09 16:44:44 +01:00
|
|
|
.filter('gasFilter', function() {
|
|
|
|
return function(gas) {
|
|
|
|
return (typeof gas !== 'undefined' ? parseInt(gas) : '?');
|
|
|
|
}
|
|
|
|
})
|
2015-02-19 18:34:20 +01:00
|
|
|
.filter('hashFilter', function() {
|
|
|
|
return function(hash) {
|
|
|
|
return hash.substr(0, 6) + '...' + hash.substr(58, 6);
|
|
|
|
}
|
|
|
|
})
|
2015-02-05 02:33:58 +01:00
|
|
|
.filter('timeClass', function() {
|
|
|
|
return function(timestamp) {
|
2015-02-05 05:32:42 +01:00
|
|
|
return timeClass(timestamp);
|
|
|
|
};
|
2015-02-05 12:05:21 +01:00
|
|
|
})
|
2015-02-18 09:57:45 +01:00
|
|
|
.filter('blockTimeFilter', function() {
|
2015-02-18 10:10:33 +01:00
|
|
|
return function(timestamp) {
|
2015-02-18 10:11:26 +01:00
|
|
|
if(timestamp === 0)
|
|
|
|
return '∞';
|
|
|
|
|
2015-02-18 10:10:33 +01:00
|
|
|
var time = Math.floor((new Date()).getTime() / 1000);
|
|
|
|
var diff = time - timestamp;
|
|
|
|
|
|
|
|
if(diff < 60)
|
|
|
|
return Math.round(diff) + ' s';
|
|
|
|
|
|
|
|
return moment.duration(Math.round(diff), 's').humanize() + ' ago';
|
2015-02-18 09:57:45 +01:00
|
|
|
};
|
|
|
|
}).filter('avgTimeFilter', function() {
|
|
|
|
return function(time) {
|
2015-02-18 10:10:33 +01:00
|
|
|
if(time < 60)
|
|
|
|
return Math.round(time) + ' s';
|
|
|
|
|
2015-02-18 09:57:45 +01:00
|
|
|
return moment.duration(Math.round(time), 's').humanize();
|
2015-02-18 08:54:04 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
.filter('avgTimeClass', function() {
|
|
|
|
return function(time) {
|
|
|
|
return blockTimeClass(time);
|
|
|
|
}
|
|
|
|
})
|
2015-02-05 12:05:21 +01:00
|
|
|
.filter('upTimeFilter', function() {
|
|
|
|
return function(uptime) {
|
|
|
|
return Math.round(uptime) + '%';
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.filter('upTimeClass', function() {
|
|
|
|
return function(uptime) {
|
|
|
|
if(uptime >= 90)
|
|
|
|
return 'text-success';
|
|
|
|
|
|
|
|
if(uptime >= 75)
|
|
|
|
return 'text-warning';
|
|
|
|
|
|
|
|
return 'text-danger';
|
|
|
|
};
|
|
|
|
})
|
|
|
|
.filter('geoTooltip', function() {
|
2015-02-05 09:27:12 +01:00
|
|
|
return function(geo) {
|
2015-02-05 16:21:22 +01:00
|
|
|
if(geo !== null)
|
|
|
|
return geo.city + ", " + geo.country;
|
|
|
|
|
|
|
|
return '';
|
2015-02-05 09:27:12 +01:00
|
|
|
};
|
2015-02-08 16:03:05 +01:00
|
|
|
})
|
|
|
|
.filter('bubbleClass', function() {
|
|
|
|
return function(node, bestBlock) {
|
|
|
|
return mainClass(node, bestBlock).replace('text-', '');
|
|
|
|
}
|
2015-02-05 05:32:42 +01:00
|
|
|
});
|
2015-02-05 02:33:58 +01:00
|
|
|
|
2015-02-08 16:03:05 +01:00
|
|
|
function mainClass(node, bestBlock)
|
|
|
|
{
|
|
|
|
if( ! node.active)
|
|
|
|
return 'text-danger';
|
|
|
|
|
|
|
|
if(node.peers === 0)
|
|
|
|
return 'text-danger';
|
|
|
|
|
2015-02-18 00:28:47 +01:00
|
|
|
// return timeClass(node.block.timestamp);
|
|
|
|
return peerClass(node.peers);
|
2015-02-08 16:03:05 +01:00
|
|
|
}
|
|
|
|
|
2015-02-05 05:32:42 +01:00
|
|
|
function peerClass(peers)
|
|
|
|
{
|
|
|
|
return (peers <= 1 ? 'text-danger' : (peers > 1 && peers < 4 ? 'text-warning' : 'text-success'));
|
|
|
|
}
|
2015-02-05 02:33:58 +01:00
|
|
|
|
2015-02-05 05:32:42 +01:00
|
|
|
function timeClass(timestamp)
|
|
|
|
{
|
|
|
|
var time = Math.floor((new Date()).getTime() / 1000);
|
|
|
|
var diff = time - timestamp;
|
2015-02-05 02:33:58 +01:00
|
|
|
|
2015-02-18 08:54:04 +01:00
|
|
|
return blockTimeClass(diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
function blockTimeClass(diff)
|
|
|
|
{
|
2015-02-05 05:32:42 +01:00
|
|
|
if(diff <= 12)
|
|
|
|
return 'text-success';
|
2015-02-05 02:33:58 +01:00
|
|
|
|
2015-02-05 05:32:42 +01:00
|
|
|
if(diff <= 20)
|
|
|
|
return 'text-info';
|
|
|
|
|
|
|
|
if(diff <= 30)
|
|
|
|
return 'text-warning';
|
|
|
|
|
2015-02-18 08:54:04 +01:00
|
|
|
return 'text-danger'
|
2015-02-05 05:32:42 +01:00
|
|
|
}
|