-
Notifications
You must be signed in to change notification settings - Fork 15
/
solo.js
75 lines (58 loc) · 2.11 KB
/
solo.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
var _ = require('lodash'),
setWithHistoricalData = require('../../utils/setWithHistoricalData'),
Module = require('../../Module');
module.exports = Module.extend({
viewId: 'revenue',
defaults: {
chartTimespan: 14 * 24 * 60 * 60 * 1000,
chartPrecision: 60 * 60 * 1000
},
initialize: function () {
var self = this,
miner = self.config.miner;
this.title = this.config.title || 'Revenue';
self.config.miner = _.isArray(miner) ? miner : [ miner ];
self.minerData = {};
self.app.on('update:data:' + self.config.technical, function (data) {
self.technicalData = data;
self.calculateRevenue();
});
if (self.config.market) {
self.app.on('update:data:' + self.config.market, function (data) {
self.marketData = data;
self.calculateRevenue();
});
}
self.config.miner.forEach(function (miner) {
self.app.on('update:data:' + miner, function (data) {
self.minerData[miner] = data;
self.calculateRevenue();
});
});
},
calculateRevenue: function () {
var self = this,
currency,
ask,
totalHashrate;
if (!this.technicalData) {
return;
}
if (this.config.market && !this.marketData) {
return;
}
if (_.any(this.config.miner, function (miner) { return !_.has(self.minerData, miner); })) {
return;
}
totalHashrate = _.reduce(this.minerData, function (sum, miner) { return sum + (miner.averageHashrate || 0); }, 0);
ask = this.config.market ? this.marketData.ask : 1;
currency = this.config.market ? this.marketData.currency : 'BTC';
this.set({
value: this.technicalData.btcPerBlock * (24 * 60 * 60) * totalHashrate * 1e6 * this.technicalData.probability * ask,
currency: currency,
interval: 'Day'
});
},
set: setWithHistoricalData([ 'value' ], Module.prototype.set)
});