-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
50 lines (39 loc) · 1.83 KB
/
stats.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
(function () {
var pubnub = PUBNUB.init({
subscribe_key : "sub-c-0329d2b6-bd99-11e2-b58e-02ee2ddab7fe"
});
pubnub.subscribe({
channel : "candybox",
message : update
});
function safe_div(numer, denom) {
return denom ? numer / denom : 0;
}
function avg(sum, count) {
return Math.round(safe_div(sum, count) * 1000) / 1000;
}
function pct(fraction, total) {
return (Math.round(safe_div(fraction, total) * 10000) / 100) + "%";
}
function update(msg) {
$("#date").text((new Date()).toUTCString());
$("#_NumberOfSaves").text(msg._NumberOfSaves);
$("#TotalCandies").text(msg.TotalCandies);
$("#CandiesPerSecond").text(avg(msg.CandiesPerSecond, msg._NumberOfSaves));
$("#TotalLollipops").text(msg.TotalLollipops);
$("#LollipopsPerSecond").text(avg(msg.LollipopsPerSecond, msg._NumberOfSaves));
$("#SwordOfLife").text(pct(msg["Sword of Life"], msg.NumberOfSwords));
$("#SwordOfFlames").text(pct(msg["Sword of Flames"], msg.NumberOfSwords));
$("#SwordOfSummoning").text(pct(msg["Sword of Summoning"], msg.NumberOfSwords));
$("#MultiplyCandies").text(pct(msg.MultiplyCandies, msg.NumberOfWishes));
$("#MultiplyLollipops").text(pct(msg.MultiplyLollipops, msg.NumberOfWishes));
$("#PotionsAndScrolls").text(pct(msg.PotionsAndScrolls, msg.NumberOfWishes));
$("#AnsweredFrogsQuestions").text(msg.AnsweredFrogsQuestions);
$("#KilledTheWhale").text(msg.KilledTheWhale);
$("#FoundTheHorn").text(msg.FoundTheHorn);
$("#KilledTheDevil").text(msg.KilledTheDevil);
$("#FinishedTheGame").text(msg.FinishedTheGame);
$("#EncounteredWoodPony").text(msg.EncounteredWoodPony);
$("#AnnoyedCandyMerchant").text(msg.AnnoyedCandyMerchant);
}
})();