-
Notifications
You must be signed in to change notification settings - Fork 15
/
aggregated.js
53 lines (41 loc) · 1.56 KB
/
aggregated.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
var _ = require('lodash'),
setWithHistoricalData = require('../../utils/setWithHistoricalData'),
Module = require('../../Module');
module.exports = Module.extend({
viewId: 'aggregatedMiners',
defaults: {
chartTimespan: 24 * 60 * 60 * 1000,
chartPrecision: 5 * 60 * 1000,
miners: []
},
initialize: function () {
var self = this,
attributesToSave = _.map(self.config.miners, function (minerId) {
return 'currentHashrate.' + minerId;
});
self.set = setWithHistoricalData(attributesToSave, Module.prototype.set);
self.title = this.config.title || 'Total Hashrate';
self.config.miners.forEach(function (id) {
self.app.on('update:data:' + id, self.aggregateHashrates.bind(self));
});
},
aggregateHashrates: function () {
var self = this,
currentHashrate = 0,
individualHashrates = {},
minerTitles = {};
self.config.miners.forEach(function (id) {
var module = _.find(self.app.modules, function (module) {
return module.id === id;
});
minerTitles[id] = module ? module.title : id;
individualHashrates['currentHashrate.' + module.id] = module ? module.get('currentHashrate') : 0;
currentHashrate += module.get('currentHashrate') || 0;
});
self.set(_.extend({
currentHashrate: currentHashrate,
minerTitles: minerTitles
}, individualHashrates));
}
});