This repository has been archived by the owner on May 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
210 lines (136 loc) · 6.66 KB
/
index.html
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
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>
FLDC Distribution Calculator
</title>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<script type="text/javascript" language="Javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script>
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
};
var settoken = getUrlParameter('token');
var startstats = getUrlParameter('start');
var endstats = getUrlParameter('end');
var tokenstodistribute = getUrlParameter('total');
$( document ).ready(function() {
$("#token").html(settoken);
$( "#loadstats" ).click(function() {
$("#stats").append("<thead><th>Address</th><th>" + endstats + "</th><th>"+ startstats + "</th><th>Difference</th></thead>");
var endstatsdata = "getdata.php?date="+endstats;
var startstatsdata = "getdata.php?date="+startstats;
$.getJSON(startstatsdata, function(startdata){
startdata.sort(function(a, b){
if(a.address < b.address) return -1;
if(a.address > b.address) return 1;
return 0;
})
var startaddresssort = new Array();
var startamountsort = new Array();
for (var i = 0; i < startdata.length; i++) {
var token = startdata[i]["token"];
if (token == "ALL" || token == settoken) {
startaddresssort.push(startdata[i]["address"]);
startamountsort.push(startdata[i]["newcredit"]);
}
};
var startresult = startaddresssort.reduce(function(res, n, i) {
res[n] = (res[n] + +startamountsort[i]) || +startamountsort[i];
return res;
}, {});
console.log(startresult);
$.getJSON(endstatsdata, function(data){
$("#csvcontainer").show();
var totalcred = 0;
var checkpercent = 0;
data.sort(function(a, b){
if(a.address < b.address) return -1;
if(a.address > b.address) return 1;
return 0;
})
var addresssort = new Array();
var amountsort = new Array();
for (var i = 0; i < data.length; i++) {
var token = data[i]["token"];
var newcredit = data[i]["newcredit"];
//uncomment to enable FLDC distribution to all users
//if (settoken != "FLDC") {
if (token == "ALL" || token == settoken) {
totalcred += parseInt(newcredit);
addresssort.push(data[i]["address"]);
amountsort.push(data[i]["newcredit"]);
}
//} else {
// totalcred += parseInt(newcredit);
// addresssort.push(data[i]["address"]);
// amountsort.push(data[i]["newcredit"]);
//}
};
var result = addresssort.reduce(function(res, n, i) {
res[n] = (res[n] + +amountsort[i]) || +amountsort[i];
return res;
}, {});
var totalcreditdiff = 0;
var newdist = new Array();
for (var key in result) {
var address = key;
var newcredit = result[key];
if (typeof startresult[address] === 'undefined') {
var oldcredit = 0;
} else {
var oldcredit = startresult[address];
}
var creditdiff = parseInt(newcredit) - parseInt(oldcredit);
totalcreditdiff += creditdiff;
if (creditdiff > 0) {
newdist.push({address: address, creditdiff: creditdiff})
}
var percentofdist = (parseInt(newcredit) / totalcred) * 100;
$("#stats").append("<tr><td>"+address+"</td><td>"+newcredit+"</td><td>"+oldcredit+"</td><td>"+creditdiff+"</td></tr>");
checkpercent = checkpercent + percentofdist;
};
var totalpctnewdist = 0;
for (var i = 0; i < newdist.length; i++) {
var address = newdist[i]["address"];
var percentofnewdist = (newdist[i]["creditdiff"] / totalcreditdiff) * tokenstodistribute;
$("#csv").append(address + ", " + percentofnewdist.toFixed(8) + "<br />");
totalpctnewdist += parseFloat(percentofnewdist * 100000000);
}
var viewpctnewdist = totalpctnewdist / 100000000;
$("#totalpctnewdist").html(viewpctnewdist.toFixed(8));
$("#statsoverview").html("Total Credits: "+totalcred);
});
});
});
});
</script>
</head>
<body>
<h1 align="center" id="token">FLDC</h1>
<div class="row" style="margin: auto; padding: 30px;">
<div class="col-xs-12" style="padding: 10px;">
<button id="loadstats" class="btn btn-block btn-primary">Show Stats</button>
</div>
</div>
<div id="statsoverview" align="center"></div>
<div style="padding: 40px;">
<table class="table" id="stats"></table>
</div>
<div id="csvcontainer" style="padding: 40px; display: none;">
<pre id="csv"></pre>
</div>
<div id="totalpctnewdist" align="center" style="padding: 40px;"></div>
</body>
</html>