-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
235 lines (190 loc) · 11.6 KB
/
script.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
var data = [
'Custom,20,200,200',
'Radeon RX 480,24,150,170,443,https://www.amazon.com/gp/product/B01M368YOU/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B01M368YOU&linkCode=as2&tag=a35634fc3254df456262365-20&linkId=3e234a37ef2c1c61665f132fc9b97ae1',
'Radeon RX 470,25,150,190,443,https://www.amazon.com/gp/product/B01JTNU652/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B01JTNU652&linkCode=as2&tag=a35634fc3254df456262365-20&linkId=adcc0d64b3f49ccf6bbe84ea7b9b6d49',
'Radeon R9 Nano,23,175,499,443,https://www.amazon.com/gp/product/B016EWOSLO/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=B016EWOSLO&linkCode=as2&tag=a35634fc3254df456262365-20&linkId=0feb761e7a7fa6300d1773b45d4b4522',
'Radeon HD 7990,50,375,589,443,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+HD+7990&keywords=Radeon+HD+7990&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon HD 7950,20,200,295,119,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+HD+7950&keywords=Radeon+HD+7950&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon HD 7970,24,250,345,119,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+HD+7970&keywords=Radeon+HD+7970&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 280X,25,250,194,150,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+R9+280X&keywords=Radeon+R9+280X&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 270X,18,180,199,130,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+R9+270X&keywords=Radeon+R9+270X&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 270,14.2,150,168,126,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+R9+270&keywords=Radeon+R9+270&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 290X,25.46,290,371,225,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+R9+290X&keywords=Radeon+R9+290X&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 380 X,20,190,229,229,http://www.amazon.com/s/ref=sr_nr_n_0?fst=as%3Aoff&rh=n%3A172282%2Cn%3A541966%2Cn%3A284822%2Ck%3ARadeon+R9+380X&keywords=Radeon+R9+380X&ie=UTF8&tag=0596007124-20&qid=1453887867&rnid=493964',
'Radeon R9 295X2,51,500,804',
'Radeon HD 7950 Boost,16,225,160.00',
'Radeon R9 390x,27,220,500.00',
'Radeon HD 7870 XT,13,185,129.00',
'Radeon HD 7790 10,85,200.00',
'Radeon R9 280,15.6,200,220.00',
'Radeon HD 7870,12.2,175,147.00',
'Radeon HD 7770 8,80,151.00',
'Radeon R9 290,22.8,275,375.00',
'Radeon R9 285,15,190,299.00',
'Radeon HD 7850,11,130,259.00',
'Radeon R9 Nano,22,175,669.00',
'Radeon R9 Fury X,26.5,275,900.00',
'Radeon R7 260X,4.56,115,147.00',
'GeForce GTX 970,17.9,145,412.00',
'GeForce GTX 750,7.4,55,120.00',
'GeForce GTX 750 Ti,7,40,150.00',
'GeForce GTX 680,11,195,120.00',
'GeForce GTX 780 Ti,18.1,250,373.00',
'GeForce GTX 960,10,120,259.00',
'GeForce GTX 650 Ti,5,110,73.00',
'GeForce GTX 980,18.4,165,659.00',
'GeForce GTX 760,9.2,170,210.00',
'GeForce GTX Titan,20,250,670.00',
'GeForce GTX 780,17.9,250,599.00',
'GeForce GTX 980 Ti,20,250,743.00',
'GeForce GTX 660 Ti,6,150,120.00',
'GeForce GTX Titan Black,19,250,999.00',
'GeForce GTX Titan X,17,250,900.00',
'GeForce GTX 770,9,230,450.00',
'GeForce GTX Titan Z,35,375,2,999.00',
'Genesis Cloud Mining,3,0,54.00',
'Amazon EC2,44,0,0.00'
];
function populateHardware(selected,data){
for (var i = 0; i < data.length; i++)
{
var row = data[i].split(',');
var option = document.createElement('option');
option.value = i.toString();
option.innerHTML = row[0];
selected.appendChild(option);
// if (row.length > 5)
// document.getElementById('checkPriceA').href = row[5];
// else
document.getElementById('checkPrice').style.display = 'none';
}
}
function selectCard(selected)
{
document.getElementById('user-hashrate').value = data[selected].split(",")[1];
document.getElementById('watts').value = data[selected].split(",")[2];
var row = data[selected].split(',');
if (row.length > 5)
{
document.getElementById('checkPriceA').href = row[5];
document.getElementById('checkPrice').style.display = 'inline';
}
else
document.getElementById('checkPrice').style.display = 'none';
update();
}
function update(){
var network = new Object();
network.hashrate = Number(document.getElementById('network-hashrate').value);
network.hashrateIncrement = document.getElementById('networkHasrateIncrement').value / 100;
network.blocktime = document.getElementById('blocktime').value;
network.currencyPrice = document.getElementById('ethPrice').value;
network.futureHashrate = function(delayedMonths){
var res = this.hashrate;
for (var i = 0; i < delayedMonths; i++)
{
res += res * this.hashrateIncrement;
}
return res;
};
var userhashrate = document.getElementById('user-hashrate').value;
// calculates the amount of currency generated by user in one minute
var calculateUserCurrencyPerMin = function(userhashrate, network, delayedMonths){
if (typeof delayedMonths === 'undefined') delayedMonths = 0;
var blocksPerMin = 60.0 / network.blocktime;
var networkCurrencyPerMin = blocksPerMin * 5.0;
var userCurrencyPerMin = networkCurrencyPerMin * userhashrate / (network.futureHashrate(delayedMonths) * 1000);
return userCurrencyPerMin;
};
var userCurrencyPerMin = calculateUserCurrencyPerMin(userhashrate, network);
// estimate the generated amount per hour,day,week,month,year if the difficulty stays the same
var res = (function(min,diff){
var res = new Object();
res.min = min;
res.hour = res.min.toString() * 60;
res.day = res.hour * 24;
res.week = res.day * 7;
//res.month = res.day * 30;
res.month = 0;
var dayinc = Math.pow(1 + diff,1/30);
for (var i = 0; i < 30; i++)
res.month += res.day / Math.pow(dayinc, i);
res.year = 0;
for (var i = 0; i < 12; i++)
res.year += res.month / Math.pow(1 + diff, i);
return res;
})(userCurrencyPerMin, network.hashrateIncrement);
// estimate the generated monthly given an expected difficulty increase
var predictedRev = (function(min, diff){
var res = [];
var mo = 0;
var dd = min * 60 * 24;
var dayinc = Math.pow(1 + diff, 1/30);
for (var i = 0; i < 30; i++)
mo += dd / Math.pow(dayinc, i);
for (var i = 0; i < 12; i++)
{
res[i] = mo / Math.pow(1 + diff, i);
}
return res;
})(userCurrencyPerMin, network.hashrateIncrement);
var sumArray = function(arr){ var total = 0.0; for (var i = 0; i < arr.length; i++) total += arr[i]; return total;};
var kwhPrice = document.getElementById('kwhPrice').value;
var kwatts = document.getElementById('watts').value / 1000;
var ethPrice = document.getElementById('ethPrice').value;
var dailyUsdPerUnit = document.getElementById('dailyUsdPerUnit').value;
var hourly = kwatts * kwhPrice + (dailyUsdPerUnit * userhashrate / 24)
var cost = new Object();
cost.min = hourly/60;
cost.hour = hourly;
cost.day = hourly * 24;
cost.week = hourly * 24 * 7;
cost.month = hourly * 24 * 30;
cost.year = hourly * 24 * 365;
var format = function(n){return Math.round(n*100)/100;};
var renderer = '<table class="table table-striped" style="border:1:px;"><thead><tr><td>Period</td><td>Revenue(ETH)</td><td>Revenue(USD)</td><td>Cost</td></tr></thead>';
renderer += '<tr><td>Min</td><td>' + format(res.min) + '</td><td>' + format(res.min * ethPrice) + '</td><td>' + format(cost.min) + '</td></tr>';
renderer += '<tr><td>Hour</td><td>' + format(res.hour) + '</td><td>' + format(res.hour * ethPrice) + '</td><td>' + format(cost.hour) + '</td></tr>';
renderer += '<tr><td>Day</td><td>' + format(res.day) + '</td><td>' + format(res.day * ethPrice) + '</td><td>' + format(cost.day) + '</td></tr>';
renderer += '<tr><td>Week</td><td>' + format(res.week) + '</td><td>' + format(res.week * ethPrice) + '</td><td>' + format(cost.week) + '</td></tr>';
renderer += '<tr><td>Month</td><td>' + format(res.month) + '</td><td>' + format(res.month * ethPrice) + '</td><td>' + format(cost.month) + '</td></tr>';
renderer += '<tr><td>Year</td><td>' + format(res.year) + '</td><td>' + format(res.year * ethPrice) + '</td><td>' + format(cost.year) + '</td></tr>';
renderer += '</table>';
renderer += '<hr>';
renderer += '<table class="table table-striped" style="border:1:px;"><thead><tr><td>Month</td><td>Revenue(ETH)</td><td>Revenue(USD)</td><td>Cost(USD)</td></tr></thead>';
for (var i = 0; i < predictedRev.length; i++)
renderer += '<tr><td>' + i + '</td><td>' + format(predictedRev[i]) + '</td><td>' + format(predictedRev[i] * ethPrice) + '</td><td>' + format(cost.month) + '</td></tr>';
renderer += '<tr><td>Total</td><td>' + format(sumArray(predictedRev)) + '</td><td>' + format(sumArray(predictedRev) * ethPrice) + '</td><td>' + format(12 * cost.month) + '</td></tr>';
renderer += '</table>';
document.getElementById('result').innerHTML = renderer;
}
function loadJSON(path, success, error)
{
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function()
{
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
if (success)
success(JSON.parse(xhr.responseText));
} else {
if (error)
error(xhr);
}
}
};
xhr.open("GET", path, true);
xhr.send();
}
loadJSON('https://etherchain.org/api/miningEstimator',
function(data) {
document.getElementById('network-hashrate').value = Number(data.data[0].hashRate) / Math.pow(1000, 3);
document.getElementById('blocktime').value = data.data[0].blockTime;
update();
},
function(xhr) { console.error(xhr); }
);
loadJSON('https://api.etherscan.io/api?module=stats&action=ethprice&apikey=YourApiKeyToken',
function(data) { document.getElementById('ethPrice').value = data.result.ethusd; update(); },
function(xhr) { console.error(xhr); }
);