-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.js
More file actions
120 lines (93 loc) · 4.03 KB
/
Copy pathtool.js
File metadata and controls
120 lines (93 loc) · 4.03 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const STEEMIT_BANDWIDTH_AVERAGE_WINDOW_SECONDS = 60 * 60 * 24 * 7
, STEEM_VOTING_MANA_REGENERATION_SECONDS = 432000 // 432000 sec = 5 days
, STEEM_RC_MANA_REGENERATION_SECONDS = 432000 // 432000 sec = 5 days
, CHAIN_ENERGY_REGENERATION_SECONDS = 432000 // 432000 sec = 5 days
;
let numeral = require(`numeral`);
class Tool {
static calculateAccountReputation(account) {
let out = Math.log10(account.reputation);
if (isNaN(out)) {
out = 0;
}
out = Math.max(out - 9, 0);
out = ((out < 0) ? -1 : 1) * out;
out = (out * 9) + 25;
return out.toFixed(2);
}
static vestsToPower(vests, gp) {
let totalVestingFundSteem = (`total_vesting_fund_steem` in gp)
? parseFloat(gp.total_vesting_fund_steem.split(` `)[0])
: parseFloat(gp.total_vesting_fund.split(` `)[0])
, totalVestingShares = parseFloat(gp.total_vesting_shares.split(` `)[0])
, steemPerVests = 1e6 * totalVestingFundSteem / totalVestingShares
, accountVests = parseFloat(vests.split(` `)[0]);
return accountVests / 1e6 * steemPerVests
}
static formatPower(power) {
return numeral(power).format(`0,0.000`);
}
static calculateAccountOwnPower(account, gp, raw) {
let value = Tool.vestsToPower(account.vesting_shares, gp);
return raw ? value : Tool.formatPower(value)
}
static calculateAccountReceivedPower(account, gp, raw) {
if (!(`received_vesting_shares` in account)) {
return 0;
}
let value = Tool.vestsToPower(account.received_vesting_shares, gp);
return raw ? value : Tool.formatPower(value)
}
static calculateAccountDelegatedPower(account, gp, raw) {
if (!(`delegated_vesting_shares` in account)) {
return 0;
}
let value = Tool.vestsToPower(account.delegated_vesting_shares, gp);
return raw ? value : Tool.formatPower(value)
}
static calculateAccountFullPower(account, gp, raw) {
let value = Tool.calculateAccountOwnPower(account, gp, true)
+ Tool.calculateAccountReceivedPower(account, gp, true)
- Tool.calculateAccountDelegatedPower(account, gp, true)
;
return raw ? value : Tool.formatPower(value)
}
static calculateAccountVotingPower(account) {
if (`voting_manabar` in account) {
let totalShares = parseFloat(account.vesting_shares)
+ parseFloat(account.received_vesting_shares)
- parseFloat(account.delegated_vesting_shares)
- parseFloat(account.vesting_withdraw_rate)
, elapsed = Math.floor(Date.now() / 1000) - account.voting_manabar.last_update_time
, maxMana = totalShares * 1000000
, currentMana = parseFloat(account.voting_manabar.current_mana) + elapsed * maxMana / STEEM_VOTING_MANA_REGENERATION_SECONDS
;
if (currentMana > maxMana) {
currentMana = maxMana;
}
return (currentMana * 100 / maxMana).toFixed(2);
} else if (`energy` in account) {
return (Tool.calculateVpCurrentValue(account, `energy`) / 100)
} else {
return (Tool.calculateVpCurrentValue(account, `voting_power`) / 100)
}
}
static calculateVpCurrentValue(account, key) {
let lastVoteTime = Date.parse(account.last_vote_time)
, deltaTime = parseInt((new Date().getTime() - lastVoteTime + (new Date().getTimezoneOffset() * 60000)) / 1000)
, currentValue = parseInt(account[key] + (deltaTime * 10000 / CHAIN_ENERGY_REGENERATION_SECONDS))
;
if (currentValue > 10000) {
currentValue = 10000;
}
return currentValue;
}
static formatBalance(balance) {
let parts = balance.split(` `);
parts[0] = Tool.formatPower(parts[0]);
return parts.join(` `)
}
static calculateAccountEstimatedValue(account, gp) {
}
}
module.exports.Tool = Tool;