-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJust_Statistics_Latest.js
1401 lines (1296 loc) · 60.9 KB
/
Just_Statistics_Latest.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name Just statistics v1.841
// @version 1.841
// @description Collection/Creation log (Tracks drops/creates, multidrops/-creates, displays the different rarities that dropped and more...)
// @author Dominik "Bl00D4NGEL" Peters
// @match http://*.drakor.com*
// @match https://*.drakor.com*
// ==/UserScript==
var LOG; //Global variable
var RARITIES = ["Common", "Superior", "Rare", "Epic", "Legendary"];
var RARITIES_N = ["Nothing", "Common", "Superior", "Rare", "Epic", "Legendary"];
var debug = 0;
var debugId = "#debugDiv";
var version = "v1.841";
var last_change = "2017-06-25";
//Make sure the LOG variable is saved whenever the user closes/ refreshes/leaves the Drakor tab (Still needs to be tested..)
window.addEventListener("unload", function () {
SaveLog()
});
setInterval(function () { // Save the LOG variable every 10 minutes (Prevent data loss due to inactivity)
SaveLog();
}, 600000);
//Variable declaration; getting the data out of local storage
if (!localStorage.getItem("localLog")) {
console.log("No LOG object found.. Creating now!");
Create_Log_Object();
}
else {
try {
LOG = JSON.parse(localStorage.getItem("localLog"));
console.log("Log successfully loaded");
}
catch (e) {
console.log("Could not load log!");
console.log(e);
console.log(localStorage.getItem("localLog"));
Create_Log_Object();
}
}
$(document).ready(function () {
$(".bv_top_btn3").on("click", SaveLog()); //Save Log when logging out
console.log(LOG);
//Add the "button" to the menu bar
var showLog = $(document.createElement("a"))
.attr({ id: "hrefShowLog", class: "gs_topmenu_item" })
.text("Show Log")
.on("click", function () {
if ($(logDiv).dialog("isOpen")) {
$(logDiv).dialog("close");
}
else {
$(logDiv).dialog("open");
}
})
.appendTo("#gs_topmenu");
SetupLog();
Info("You're currently using Just Statistics version " + version + "\nThis version was last edited on the " + last_change);
$(document).ajaxComplete(function (event, xhr, settings) {
if (xhr.status !== 200) { //Check if ajax is OK
return
}
if (settings.url.match(/\/world\/action_/)) { //Look if the ajax is a tradeskill action
var amount, exp, gold, item, history, buffActive = false, titleData, actionStatus;
var tradeskill = settings.url.match(/action_([a-zA-Z]+).*?\//)[1];
if (tradeskill === "teleport") { Info("You teleported.. that's no tradeskill!"); return; }
tradeskill = (tradeskill[0].toUpperCase() + tradeskill.substring(1)); //Convert first char to uppercase (Just for beauty reasons)
if (!LOG[tradeskill]) {//If tradeskill is not present in log create it
Info("New Tradeskill: '" + tradeskill + "'");
LOG[tradeskill] = {};
LOG[tradeskill].Rarity = {};
for (var rar = 0; rar < RARITIES.length; rar++) {
LOG[tradeskill].Rarity[RARITIES[rar]] = 0;
}
LOG[tradeskill].Items = {};
LOG[tradeskill].Multi = {};
LOG[tradeskill].Node = {};
LOG[tradeskill].Attempts = 0;
LOG[tradeskill].Indexes = "";
LOG[tradeskill].Experience = 0;
var op = $(document.createElement("option"))
.attr({ name: tradeskill, value: tradeskill })
.text(tradeskill)
.appendTo($("#tradeSelect"));
op.clone().appendTo($("#tradeSelectRarityChart"));
}
if (!xhr.responseText.match(/depleted/i)) {
try {
var result = xhr.responseText.match(/<div class="roundResult areaName">.*?(?:exp|beginner)\s*\)?<\/span.*?><\/div>/gi);
//Attention, creating skills will confuse this because not every creation gives exp, but rather a full attempt will.
if (!result) { //This will always say true UNLESS you worked in another window thus the result will be empty -> no log entry will be made
return
}
var nodeName = $(".locationTitle").text();
//Attention! If the node is a settlement node, the level-range can be adjusted. Same goes for TH => adjust node level range to currently selected level range
if (nodeName.match(/settlement|treasure/i)) {
Debug("You're working on a Settlement node or a TH node!");
nodeName = nodeName.match(/(.*?)\(/)[1]; //Only the text is what we want for the log.
var selectLevelFrom = $("#minRange").val();
var selectLevelTo = $("#maxRange").val();
nodeName += "(Node Level " + selectLevelFrom + " - " + selectLevelTo + ")";
Debug("Changed node-name to: " + nodeName);
}
var temp = result[0].match(/^<div.*?>(.*?(?:exp|beginner)\s*\)?<\/span.*?>)<\/div>/gi);
if (result.length === 1) {
if (result[0].match(/^<div class="roundResult areaName">Your combines are complete./)) {
titleData = "Creation done!";
actionStatus = 'alert';
}
result = result[0].replace("<div class=\"roundResult areaName\">Your combines are complete.</div>", "");
result = result.match(/^<div.*?>(.*?(?:exp|beginner)\s*\)?<\/span.*?>)<\/div>/i)[1];
result = result.replace(/<script>.*?<\/script>/, "");
ProcessData(xhr.responseText, result, tradeskill, nodeName);
}
else {
for (var i = 0; i < result.length; i++) {
if (result[i].match(/^<div class="roundResult areaName">Your combines are complete./)) {
titleData = "Creation done!";
actionStatus = 'alert';
}
result[i] = result[i].replace("<div class=\"roundResult areaName\">Your combines are complete.</div>", "");
result[i] = result[i].replace(/<script>.*?<\/script>/, "");
result[i] = result[i].match(/^<div.*?>(.*?<\/span.*?>)<\/div>/i)[1];
ProcessData(xhr.responseText, result[i], tradeskill, nodeName);
}
}
LOG.Misc.Attempts.Total++;
LOG.Misc.Attempts.Node = $(".roundResult").length;
//Drop analysis done, let's start with the rest
var scripts = xhr.responseText.match(/<script>(.*?)<\/script>/g);
var miscData = scripts[scripts.length - 1];
var currentExp = miscData.match(/\(\'exp\:\s*(.*?)\s\//mi)[1].replace(",", "");
var neededExp = miscData.match(/\(\'exp\:\s*.*?\/\s*(.*?)\s\(/mi)[1].replace(",", "");
var attemptTime;
if (!settings.url.match(/Disenchanting/i)) {
attemptTime = miscData.match(/startTimer\((\d+),*/mi)[1];
if (attemptTime < 5000) { attemptTime = 60000; } //Node depleted
}
else {
attemptTime = 0;
}
//Calculate the needed attempts to next level and update div text in the dialog
GetAttemptsToNextLevel(currentExp, neededExp, attemptTime, LOG[tradeskill].Experience, LOG[tradeskill].Attempts, tradeskill);
//Titlechanging data
var buffrarity = xhr.responseText.match(/dricon\scard(\w+)\sslot_default/i);
if (buffrarity[1] !== 'None') { buffActive = true; }
if (titleData !== 'Creation done!') {
if (xhr.responseText.match(/\d+%\sof/gi)) {
titleData = xhr.responseText.match(/(\d+)%\sof/i)[1] + "% of Node left";
}
else if (xhr.responseText.match(/x\d+\.\.\./)) {
titleData = xhr.responseText.match(/x(\d+)\.\.\./)[1] + " attempts left";
}
}
DisplayData();//Rarity-, Multi- and Materialoverview
}
catch (e) {
Error("Handling Responsetext: " + e.message);
}
}
else {
titleData = "Node depleted!";
actionStatus = "alert";
}
}
else if (settings.url.match(/workers\/collectworker/)) {
var material = xhr.responseText.match(/\[(.*?)\]/)[1];
HandleOfflineWorker("delete", material);
}
else if (settings.url.match(/workers/i)) {
var text = xhr.responseText;
var items = text.match(/(<div>Worker collecting.*?<\/div><\/div>)/ig);
if (!items) { return; }
for (var i = 0; i < items.length; i++) {
var material = items[i].match(/\[(.*?)\]/);
var time = items[i].match(/Collect <b>\d+<\/b> in (.*?)<\/div>/);
if (!time) { HandleOfflineWorker("delete", material[1]); }
else {
var seconds = ConvertStringIntoSeconds(time[1]);
var utc = new Date(new Date().getTime() + parseInt(seconds) * 1000).getTime();
var param = {
"Material": material[1],
"Time": utc
};
HandleOfflineWorker("check", param);
}
}
}
});
});
function addCommas(x) {
return x.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
}
function ProcessData(responseText, history, tradeskill, nodeName) {
try {
history = history.replace(/<script>(.*?)<\/script>/, "");
var log_history = history;
log_history = log_history.replace(/<\/?.*?>/g, "");
var item, amount, multi, exp, gold, rarity;
try {
exp = history.match(/>(\d+)\s*exp/mi)[1];
}
catch (e) { //If you're max level it will display + x total exp
exp = history.match(/\+<b>(\d+)<\/b>/i);
if (!exp) { //If this still fails for whatever reason, just default to 0 exp
exp = 0;
//Log the error in the history (The last resort for this).
Error("When processing the experience gained an error occured and the gained exp was set to 0..\nMessage: " + e.message);
if (!LOG.Misc.Log[LOG.Misc.Index]) {
LOG.Misc.Log[LOG.Misc.Index] = "Something went wrong when trying to get the exp..<br/>Message: " + e.message;
}
else {
LOG.Misc.Log[LOG.Misc.Index] += "Something went wrong when trying to get the exp..<br/>Message: " + e.message;
}
}
else {
exp = exp[1];
}
}
var date = new Date();
date.setTime(date.getTime() + (-3 + date.getTimezoneOffset() / 60) * 60 * 60 * 1000);//So the date is synced with Drakor timers
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var logDate = date.getFullYear() + '-' + (month < 10 ? '0' : '') + month + '-' + (day < 10 ? '0' : '') + day;
var key = (logDate + (hour < 10 ? '0' : '') + hour).replace(/\D/g, ""); //Generate a key for the dictionary for stuff per hour mapping
if (!LOG[tradeskill][key]) {
Info("New Date-Key '" + key + "' created");
LOG[tradeskill][key] = {};
LOG[tradeskill][key].Amount = 0;
LOG[tradeskill][key].Experience = 0;
LOG[tradeskill][key].Attempts = 0;
}
if (!LOG[tradeskill].Node[nodeName]) {
Info("NEW NODE: '" + nodeName + "'");
LOG[tradeskill].Node[nodeName] = {};
LOG[tradeskill].Node[nodeName].Items = {};
LOG[tradeskill].Node[nodeName].Rarity = {};
for (var i = 0; i < RARITIES_N.length; i++) { LOG[tradeskill].Node[nodeName].Rarity[RARITIES_N[i]] = 0; }
LOG[tradeskill].Node[nodeName].Misc = {};
LOG[tradeskill].Node[nodeName].Misc.Experience = 0;
LOG[tradeskill].Node[nodeName].Misc.Attempts = 0;
}
LOG[tradeskill].Attempts++;
LOG[tradeskill].Node[nodeName].Misc.Attempts++;
if ($("#history").prop('checked')) {
LOG.Misc.Index++; //Add 1 to the index for the next attempt.
LOG.Misc.Log[LOG.Misc.Index] = logDate + log_history; //Add the log to the Object via index
LOG[tradeskill].Indexes += LOG.Misc.Index + "|";
}
if (history.match(/anything/i)) { //Nothing-drop
LOG[tradeskill].Rarity.Nothing++;
LOG[tradeskill].Node[nodeName].Rarity.Nothing++;
multi = 0;
amount = 1; //I dropped ONE item whose name is NOTHING
item = "Nothing";
rarity = "Nothing";
}
else {
if (history.match(/clink/mi)) { //Creation of clickable items with variating rarities!
try {
//Let's first check what and how many items were created
item = responseText.match(/\[(.*?)\]/)[1]; //To get the PATTERN name, not the created items name
rarity = history.match(/card(\w+)\sclink/ig);
amount = parseInt(rarity.length);
for (var i = 0; i < rarity.length; i++) { //Write the data into the log object and you should be done
var dummy_rarity = rarity[i].match(/card(\w+)\s/)[1];
LOG[tradeskill][dummy_rarity]++;
LOG[tradeskill].Node[nodeName].Rarity[dummy_rarity]++;
Info("Crafted rarity: " + dummy_rarity);
}
}
catch (e) {
Error("Error processing item<br>" + e.message);
}
}
else {
rarity = history.match(/class=\"(\w+)\s?viewmat\">/mi)[1];
LOG[tradeskill].Rarity[rarity]++;
LOG[tradeskill].Node[nodeName].Rarity[rarity]++;
item = history.match(/\[(.*?)\]/)[1];
amount = history.match(/<\/span>\s*x(\d+)/)[1];
}
multi = amount;
}
LOG[tradeskill][key].Attempts++;
LOG[tradeskill][key].Amount += parseInt(amount);
LOG[tradeskill][key].Experience += parseInt(exp);
if (!LOG[tradeskill].Multi[multi]) {//Multicounter
LOG[tradeskill].Multi[multi] = {};
LOG[tradeskill].Multi[multi].Amount = 1;
}
else {
LOG[tradeskill].Multi[multi].Amount++;
}
if (!LOG[tradeskill].Items[item]) { //Itemcounter
LOG[tradeskill].Items[item] = {};
LOG[tradeskill].Items[item].Drop = 1;
LOG[tradeskill].Items[item].Amount = parseInt(amount);
if ($("#history").prop('checked')) {
LOG[tradeskill].Items[item].Indexes = LOG.Misc.Index + "|";
}
Info("First time!!<br>Item: " + item + " | Amount: " + amount);
}
else {
LOG[tradeskill].Items[item].Drop++;
LOG[tradeskill].Items[item].Amount += parseInt(amount);
if ($("#history").prop('checked')) {
LOG[tradeskill].Items[item].Indexes += LOG.Misc.Index + "|";
}
Info("Item: " + item + " - Amount: " + amount + " - Total: " + LOG[tradeskill].Items[item].Amount);
}
if (!LOG[tradeskill].Items[item].Rarity) { //If rarity hasn't been set yet (Older versions did not have this)
LOG[tradeskill].Items[item].Rarity = rarity; //This will take the last-generated rarity on this function (Pattern that create different rarities *will* bug on this.
}
if (!LOG[tradeskill].Node[nodeName].Items[item]) {
LOG[tradeskill].Node[nodeName].Items[item] = {};
LOG[tradeskill].Node[nodeName].Items[item].Attempts = 1;
LOG[tradeskill].Node[nodeName].Items[item].Rarity = rarity; //This will take the last-generated rarity on this function (Pattern that create different rarities *will* bug on this.
}
else {
LOG[tradeskill].Node[nodeName].Items[item].Attempts++;
}
gold = history.match(/\(\+([0-9,]+)\s*gold/i);
if (!gold) { gold = 0; }
else {
gold = gold[1].replace(",", "");
if ($("#history").prop("checked")) {
LOG.Misc.GoldIndexes += LOG.Misc.Index + "|";
}
}
LOG.Misc.TotalExp += parseInt(exp);
LOG[tradeskill].Experience += parseInt(exp);
LOG[tradeskill].Node[nodeName].Misc.Experience += parseInt(exp);
LOG.Misc.Gold += parseInt(gold);
}
catch (e) {
Error("PROCESSDATA: " + e.message);
}
}
function Create_Log_Object() {
LOG = {};
LOG.Misc = {};
LOG.Misc.Attempts = {};
LOG.Misc.OfflineWorker = {};
LOG.Misc.Attempts.Node = 0;
LOG.Misc.Attempts.Total = 0;
LOG.Misc.Log = [];
LOG.Misc.TotalExp = 0;
LOG.Misc.Gold = 0;
LOG.Misc.GoldIndexes = ""; //For showing the log of gold drops
LOG.Misc.Alert = false;
LOG.Misc.History = true;
LOG.Misc.Index = 0;
localStorage.setItem("localLog", JSON.stringify(LOG));
}
function MakePieChart(data) {
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
$(document.createElement("h1")).text("Rarities for " + data[0]).appendTo($("#graph_div"));
$(svg).attr({
"viewBox": "-1 -1 2 2",
})
.css({ "transform": "rotate(-0.25turn)", "height": "200px" })
//.append(circle)
.appendTo($("#graph_div"));
var temp = 0;
for (var i = 1; i < data.length; i++) {
var d = data[i];
if (d.Percent <= 0) { continue; }
var [x, y] = GetCoordinatesForPercent(temp);
temp += Number(d.Percent);
var [x_2, y_2] = GetCoordinatesForPercent(temp);
var large = d.Percent > .5 ? 1 : 0;
var pathData = [
'M ' + x + ' ' + y, //Move
'A 1 1 0 ' + large + ' 1 ' + x_2 + " " + y_2, //Arc
'L 0 0' //Line
].join(" ");
var path = $(document.createElementNS('http://www.w3.org/2000/svg', 'path')).attr({ "d": pathData, "fill": d.Color }).appendTo(svg);
var title = $(document.createElement("title")).text(d.Title + " (" + (d.Percent * 100).toFixed(2) + "%)").appendTo(path);
}
$("#graph_div").html($("#graph_div").html());
}
function MakeBarChart(data) {
//To be implemented
}
function MakePolyChart(data) {
Dump(data);
var color = ["red", "green", "blue", "yellow", "orange", "cyan", "black", "grey"]
var logDivWidth = parseInt($("#logDiv").css("width").match(/^(\d+)/)[1]);
var logDivHeight = parseInt($("#logDiv").css("height").match(/^(\d+)/)[1]);
var ulHeight = parseInt($(".ui-tabs-nav").css("height").match(/^(\d+)/)[1]);
var ulBorderAndPadding = 4.8;
var graphDivHeight = parseInt($("#graphDiv").css("height").match(/^(\d+)/)[1]);
var maxWidth = logDivWidth - 40;
var maxHeight = logDivHeight - ulHeight - ulBorderAndPadding - graphDivHeight - 30;
Debug("Maxwidth: " + maxWidth + " | MaxHeight: " + maxHeight);
var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
$(svg).css({ "height": maxHeight + "px", "width": maxWidth + "px" }).appendTo($("#graph_div"));
//, "transform": "rotate(-0.5turn)"
var colorCounter = 0;
for (var type in data) { //Multiple lines, yay!
var poly = document.createElementNS('http://www.w3.org/2000/svg', 'polyline');
//$(poly).attr({"points": "0,40 40,40 40,80 80,80 80,120 120,120 120,160"})
// .css({"fill": "white", "stroke": "red", "stroke-width": 4}).appendTo(svg);
var dataArray = [];
var vals = {};
for (var i = 0; i < data[type].length; i++) {
var d = data[type][i];
dataArray.push(d.Index);
vals[d.Index] = d.Value;
//Implement here
}
dataArray = dataArray.sort(compareNumbersReverse);
var len = dataArray.length;
var els = [];
for (var key in vals) {
els.push(vals[key]);
}
var sortedEls = els.sort(compareNumbers);
var biggestEl = sortedEls[len - 1];
Debug("Biggest Element Value: " + biggestEl);
var hei = (maxHeight / biggestEl);
var dis = Math.floor(maxWidth / len);
Debug("LEN: " + len + " | DIS: " + dis + " | HEI: " + hei);
var pointString = "";
var circles = [];
for (var j = 0; j < len; j++) {
pointString += parseInt(j * dis) + "," + (parseInt(maxHeight) - vals[dataArray[j]] * hei) + " ";
var circle = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
$(circle).attr({
"cx": parseInt(j * dis),
"cy": maxHeight - vals[dataArray[j]] * hei,
"r": 4,
})
.css({ "fill": color[colorCounter], "stroke": "transparent" });
$(document.createElement("title")).text(type + "-> " + dataArray[j] + ": " + vals[dataArray[j]]).appendTo(circle);
circles.push(circle);
}
Debug("pointString: " + pointString);
$(poly).attr({ "points": pointString })
.css({ "fill": "transparent", "stroke": color[colorCounter], "stroke-width": 2 }).appendTo(svg);
for (var k = 0; k < circles.length; k++) {
$(circles[k]).appendTo(svg);
}
colorCounter++;
}
$("#graph_div").html($("#graph_div").html());
}
function compareNumbersReverse(a, b) {
return b - a;
}
function compareNumbers(a, b) {
return a - b;
}
function GetCoordinatesForPercent(percent) {
var x = Math.cos(2 * Math.PI * percent);
var y = Math.sin(2 * Math.PI * percent);
return [x, y];
}
function GetDate() {
var dateObj = new Date();
dateObj.setTime(dateObj.getTime() + (-3 + dateObj.getTimezoneOffset() / 60) * 60 * 60 * 1000);
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
var newdate = year + "/" + month + "/" + day;
return newdate;
}
function GetAttemptsToNextLevel(currentExp, neededExp, attemptTime, totalExp, totalAttempts, trade) {
var diffExp = neededExp - currentExp;
var averageExperience = Math.floor(totalExp / totalAttempts);
var attemptsToLevel = Math.floor(diffExp / averageExperience);
var timeToLevel = attemptsToLevel * attemptTime; //In Milliseconds
LOG.Misc.TimeToLevel = timeToLevel;
LOG.Misc.DiffExp = diffExp;
LOG.Misc.AttemptsToLevel = attemptsToLevel;
LOG.Misc.LevelupTradeskill = trade;
}
function ExportDataWithoutHistory() {
// Care! The variable needs to be copied so we don't overwrite the actual variable.
var LOG_COPY = LOG
LOG_COPY.Misc.Log = [];
LOG_COPY.Misc.GoldIndexes = "";
for (var tradeskill in LOG_COPY) {
if (tradeskill !== "Misc") {
LOG_COPY[tradeskill].Indexes = "";
for (var item in LOG_COPY[tradeskill].Items) {
LOG_COPY[tradeskill].Items[item].Indexes = "";
}
}
}
LOG_COPY.Misc.Index = 0;
return LOG_COPY;
}
function GetPercent(val1, val2) {
return (val1 / val2 * 100).toFixed(2);
}
function DisplayData() {
var colorDict = {
"Nothing": "#0aa",
"Common": "#999",
"Superior": "#48c730",
"Rare": "#2f84c7",
"Epic": "#bd33de",
"Legendary": "#f14c02"
};
var totalResources;
var totalAttempts = parseInt(LOG.Misc.Attempts.Total);
var averageGold = Math.floor(parseInt(LOG.Misc.Gold) / totalAttempts);
var averageExperience = Math.floor(parseInt(LOG.Misc.TotalExp) / totalAttempts);
var averageResources = (totalResources / totalAttempts).toFixed(2);
var miscDiv = $("#miscDiv");
miscDiv.html("");
var rarityDiv = $("#rarityDiv");
rarityDiv.html("");
var multiDiv = $("#multiDiv");
multiDiv.html("");
var materialDiv = $("#materialDiv");
materialDiv.html("");
var nodeDiv = $("#nodeDiv");
nodeDiv.html("");
if (Object.keys(LOG.Misc.OfflineWorker).length > 0) {
CreateOfflineWorkerPanel(LOG);
}
var misc = $(document.createElement("p")).html("Total Experience gained: " + LOG.Misc.TotalExp + " (" + averageExperience + " on average)<br>" +
"Total Gold gained: " + LOG.Misc.Gold + " (" + averageGold + " on average)<br>" +
"Total Collection/Creation attempts: " + totalAttempts + "<br>" +
"Experience left to levelup in " + LOG.Misc.LevelupTradeskill + ": " + LOG.Misc.DiffExp + "<br>" +
"Average time left to levelup: " + ConvertIntoSmallerTimeFormat(parseInt(LOG.Misc.TimeToLevel)) + " (" +
LOG.Misc.AttemptsToLevel + " attempts)").appendTo(miscDiv);
misc.html(addCommas(misc.html()));
for (var tradeskill in LOG) { //Iterate over tradeskills
if (!tradeskill.match(/misc/i)) { //Don't list the Misc thing
var tradeskillTitle = $(document.createElement("h2"))
.css("padding", "5px")
.html("Tradeskill: " + tradeskill);
tradeskillTitle.clone().appendTo(materialDiv);
tradeskillTitle.clone().appendTo(multiDiv);
tradeskillTitle.clone().appendTo(rarityDiv);
var tradeData = $(document.createElement("p"))
.html("Total Experience: " + LOG[tradeskill].Experience + " (" + Math.floor(LOG[tradeskill].Experience / LOG[tradeskill].Attempts) +
" on average)<br>Total Attempts: " + LOG[tradeskill].Attempts).appendTo(miscDiv);
tradeData.html(addCommas(tradeData.html()));
var materialTable = $(document.createElement("table")).css({ "width": "100%" }).attr({ "class": "materialTable" }).appendTo(materialDiv);
var tr = $(document.createElement("tr")).css("font-weight", "bold").appendTo(materialTable);
var titles = ["Material", "Amount", "Average", "Gotten/Total"];
for (var i = 0; i < titles.length; i++) {
var td = $(document.createElement("td")).html(titles[i]).css("width", 100 / titles.length + "%").appendTo(tr);
}
for (var item in LOG[tradeskill].Items) { //Iterate over dropped items
var tr = $(document.createElement("tr")).appendTo(materialTable);
var values = [item, LOG[tradeskill].Items[item].Amount,
(LOG[tradeskill].Items[item].Amount / LOG[tradeskill].Items[item].Drop).toFixed(2),
LOG[tradeskill].Items[item].Drop + "/" + LOG[tradeskill].Attempts + " (" +
GetPercent(LOG[tradeskill].Items[item].Drop, LOG[tradeskill].Attempts) + " %)"];
for (var j = 0; j < values.length; j++) {
var td = $(document.createElement("td")).html(values[j]).appendTo(tr);
}
}
var multiTable = $(document.createElement("table")).css({ "width": "100%" }).attr({ "class": "multiTable" }).appendTo(multiDiv);
var tr = $(document.createElement("tr")).css("font-weight", "bold").appendTo(multiTable);
var titles = ["Multi", "Gotten/Total"];
for (var i = 0; i < titles.length; i++) {
var td = $(document.createElement("td")).css("width", 100 / titles.length + "%").html(titles[i]).appendTo(tr);
}
for (var multi in LOG[tradeskill].Multi) { //Iterate over multis
var tr = $(document.createElement("tr")).appendTo(multiTable);
var values = [multi, LOG[tradeskill].Multi[multi].Amount + "/" + LOG[tradeskill].Attempts + " ("
+ GetPercent(LOG[tradeskill].Multi[multi].Amount, LOG[tradeskill].Attempts) + "%)"];
for (var j = 0; j < values.length; j++) {
var td = $(document.createElement("td")).html(values[j]).appendTo(tr);
}
}
var rarityTable = $(document.createElement("table")).css({ "width": "100%" }).attr({ "class": "rarityTable" }).appendTo(rarityDiv);
var tr = $(document.createElement("tr")).css("font-weight", "bold").appendTo(rarityTable);
var titles = ["Rarity", "Gotten/Total"];
for (var i = 0; i < titles.length; i++) {
var td = $(document.createElement("td")).css("width", 100 / titles.length + "%").html(titles[i]).appendTo(tr);
}
for (var rarity in colorDict) {
if (LOG[tradeskill].Rarity[rarity]) {
var tr = $(document.createElement("tr")).css("color", colorDict[rarity]).appendTo(rarityTable);
var values = [rarity, LOG[tradeskill].Rarity[rarity] + "/" + LOG[tradeskill].Attempts + " ("
+ GetPercent(LOG[tradeskill].Rarity[rarity], LOG[tradeskill].Attempts) + "%)"];
for (var j = 0; j < values.length; j++) {
var td = $(document.createElement("td")).html(values[j]).appendTo(tr);
}
}
}
for (var node in LOG[tradeskill].Node) {
var nodeHeading = $(document.createElement("h2")).html("Node: " + node).appendTo(nodeDiv);
var nodeDescription = $(document.createElement("h5"))
.html("Gained experience: " + LOG[tradeskill].Node[node].Misc.Experience + "<br>Attempts/Creations done: " +
LOG[tradeskill].Node[node].Misc.Attempts).appendTo(nodeDiv);
nodeDescription.html(addCommas(nodeDescription.html()));
var nodeTable = $(document.createElement("table")).css({ "width": "100%" }).attr({ "class": "nodeTable" }).appendTo(nodeDiv);
$(document.createElement("tr"))
.css({ "font-weight": "bold", "text-align": "center" }).html("<td colspan='2'>Items</td>").appendTo(nodeTable);
var tr = $(document.createElement("tr")).css("font-weight", "bold").appendTo(nodeTable);
var titles = ["Item", "Gotten/Total"];
for (var i = 0; i < titles.length; i++) {
var td = $(document.createElement("td")).css("width", 100 / titles.length + "%").html(titles[i]).appendTo(tr);
}
for (var item in LOG[tradeskill].Node[node].Items) {
var values = [item, LOG[tradeskill].Node[node].Items[item].Attempts + "/" + LOG[tradeskill].Node[node].Misc.Attempts + " (" +
GetPercent(LOG[tradeskill].Node[node].Items[item].Attempts, LOG[tradeskill].Node[node].Misc.Attempts) + "%)"];
var tr = $(document.createElement("tr")).css("color", colorDict[LOG[tradeskill].Node[node].Items[item].Rarity]).appendTo(nodeTable);
for (var j = 0; j < values.length; j++) {
var td = $(document.createElement("td")).html(values[j]).appendTo(tr);
}
}
$(document.createElement("tr"))
.css({ "font-weight": "bold", "text-align": "center" }).html("<td colspan='2'>Rarity</td>").appendTo(nodeTable);
var tr = $(document.createElement("tr")).css("font-weight", "bold").appendTo(nodeTable);
var titles = ["Rarity", "Gotten/Total"];
for (var i = 0; i < titles.length; i++) {
var td = $(document.createElement("td")).css("width", 100 / titles.length + "%").html(titles[i]).appendTo(tr);
}
for (var rarity in LOG[tradeskill].Node[node].Rarity) {
if (LOG[tradeskill].Node[node].Rarity[rarity]) {
var values = [rarity, LOG[tradeskill].Node[node].Rarity[rarity] + "/" + LOG[tradeskill].Node[node].Misc.Attempts + " (" +
GetPercent(LOG[tradeskill].Node[node].Rarity[rarity], LOG[tradeskill].Node[node].Misc.Attempts) + "%)"];
var tr = $(document.createElement("tr")).css("color", colorDict[rarity]).appendTo(nodeTable);
for (var j = 0; j < values.length; j++) {
var td = $(document.createElement("td")).html(values[j]).appendTo(tr);
}
}
}
}
}
}
$(".materialTable").find("td").css("border", "1px solid black");
$(".multiTable").find("td").css("border", "1px solid black");
$(".rarityTable").find("td").css("border", "1px solid black");
$(".nodeTable").find("td").css("border", "1px solid black");
}
function CreateOfflineWorkerPanel() {
var offDiv = $(document.createElement("div")).css({ "border": "1px solid black", "padding": "20px", "margin-bottom": "10px" }).appendTo("#miscDiv");
$(document.createElement("h1")).html("Offline worker").appendTo(offDiv);
var off = LOG.Misc.OfflineWorker;
var mailList = [];
for (material in off) {
Debug("MATERIAL: " + material + " VALUE: " + off[material]);
var p = $(document.createElement("p")).appendTo(offDiv);
//We save the UTC milliseconds in off[material]
if (off[material] == "done") {
p.html(material + " --> DONE (Mail sent)");
}
else {
var diff = off[material] - new Date().getTime();
Debug("MS: " + off[material]);
if (diff <= 0) {
p.html(material + " --> DONE (Sending Mail)");
mailList.push(material);
}
else if (diff <= 300000) { // Also send mail to items that are done witin 5 minutes
mailList.push(material);
}
else if (mailList.length > 0 && diff <= 400000) { //Send mail for item that ends in like 6 minutes
mailList.push(material);
}
else {
var serverOffset = 3; //In hours
var date = new Date(parseInt(off[material]));
date.setUTCHours(date.getUTCHours() - serverOffset);
var d = date.toJSON();
d = d.replace(/T/, " ");
d = d.replace(/\..*?$/, "");
p.html(material + " done at " + d + " (" + ConvertIntoSmallerTimeFormat(diff) + ")");
}
}
}
//Now let's send a mail to the user if there's anything to mail.
if (mailList.length > 0) {
Info("Sending mail..");
var mailUrl = 'https://www.drakor.com/mail/create';
var playerId;
//Find out player ID..
$(".bv_top_btn1").each(function (index, obj) {
if ($(obj).attr("href") === undefined) { return; }
var id = $(obj).attr("href").match(/profile\/(\d+)/);
if (id) { playerId = id[1]; }
});
if (!playerId) {
Error("Cannot determine player id!");
return;
}
var form = $(document.createElement("form"));
var fields = ["sendfrom", "sendto"];
for (var i = 0; i < fields.length; i++) {
$(document.createElement("input")).attr({ "type": "text", "name": fields[i], "id": fields[i] }).val(playerId).appendTo(form);
}
$(document.createElement("input")).attr({ "type": "text", "name": "subject", "id": "subject" }).val("Offline Worker").appendTo(form);
var text = "Your offline workers for:<br>";
for (var j = 0; j < mailList.length; j++) {
text += "- " + mailList[j] + "<br>";
LOG.Misc.OfflineWorker[mailList[j]] = "done";
}
text += "<br>are almost or already done.<br>Head to any Offline worker and collect them.<br><strong>Service provided by Just Statistics.</strong>";
$(document.createElement("input")).attr({ "type": "text", "name": "mail_message", "id": "mail_message" }).val(text).appendTo(form);
$.post(mailUrl, $(form).serialize());
}
}
/*
timeInMs gets calculated down to hours, minutes and seconds and gets output as a string
example ConvertIntoSmallerTimeFormat(3600000) [1 hour in milliseconds]
output: 1 Hour(s) 0 Minute(s) 0 Second(s)
*/
function ConvertIntoSmallerTimeFormat(timeInMs) {
var output = "";
var seconds = timeInMs / 1000;
var interval = Math.floor(seconds / 31536000);
if (interval > 0) {
output += interval + " year" + (interval < 2 ? " " : "s ");
seconds -= interval * 31536000;
}
interval = Math.floor(seconds / 2592000);
if (interval > 0) {
output += interval + " month" + (interval < 2 ? " " : "s ");
seconds -= interval * 2592000;
}
interval = Math.floor(seconds / 86400);
if (interval > 0) {
output += interval + " day" + (interval < 2 ? " " : "s ");
seconds -= interval * 86400;
}
interval = Math.floor(seconds / 3600);
if (interval > 0) {
output += interval + " hour" + (interval < 2 ? " " : "s ");
seconds -= interval * 3600;
}
interval = Math.floor(seconds / 60);
if (interval > 1) {
output += interval + " minute" + (interval < 2 ? " " : "s ");
seconds -= interval * 60;
}
output += Math.floor(seconds) + " seconds";
return output;
}
/*
seconds => s
minutes => m
hours => h
day => d
week => w
*/
function ConvertStringIntoSeconds(string) {
var out = 0;
var second = string.match(/(\d+)\s*?s/i);
if (second) { out += parseInt(second[1]); }
var minute = string.match(/(\d+)\s*?m/i);
if (minute) { out += (parseInt(minute[1]) * 60); }
var hour = string.match(/(\d+)\s*?h/i);
if (hour) { out += (parseInt(hour[1]) * 60 * 60); }
var day = string.match(/(\d+)\s*?d/i);
if (day) { out += (parseInt(day[1]) * 60 * 60 * 24); }
var week = string.match(/(\d+)\s*?w/i);
if (week) { out += (parseInt(day[1]) * 60 * 60 * 24 * 7); }
return out;
}
function HandleOfflineWorker(command, param) {
if (!LOG.Misc.OfflineWorker) {
Info("Creating Offline-Worker Object");
LOG.Misc.OfflineWorker = {};
}
if (command == "delete") {
Info("Removing '" + param + "' from the list");
LOG.Misc.OfflineWorker[param] = undefined;
DisplayData();
}
else if (command == "check") {
if (!LOG.Misc.OfflineWorker[param.Material]) {
HandleOfflineWorker("add", param);
return;
}
if (LOG.Misc.OfflineWorker[param.Material] != param.Time) { //Time has changed/ Offline workers have been refreshed
Info("Changing Offline Worker for " + param.Material + " FROM " + LOG.Misc.OfflineWorker[param.Material] + " TO " + param.Time);
LOG.Misc.OfflineWorker[param.Material] = param.Time;
}
}
else if (command == "add") {
Info("Adding '" + param.Material + "' to the list with UTC " + param.Time);
LOG.Misc.OfflineWorker[param.Material] = param.Time;
}
}
/*
logObject is the log object with the tradeskill you want the data for
thingsToLookFor is an Array of the keys (Amount, Attempts, Experience)
timeFrom will be the date to start at
timeTo will be the date to stop at (will stop at the current date)
*/
function CollectDataForChart(trade) {
/* new implementation */
//Percent
//Color
//Title
var data = [
trade,
];
var colorDict = {
"Nothing": "#0aa",
"Common": "#999",
"Superior": "#48c730",
"Rare": "#2f84c7",
"Epic": "#bd33de",
"Legendary": "#f14c02"
};
for (var rarity in LOG[trade].Rarity) {
var temp = {};
temp.Color = colorDict[rarity];
temp.Percent = (LOG[trade].Rarity[rarity] / LOG[trade].Attempts).toFixed(4);
temp.Title = rarity[0].toUpperCase() + rarity.substring(1);
data.push(temp);
}
Dump(data, "data");
MakePieChart(data);
/*
var returnArray = [];
var date = new Date();
date.setTime(date.getTime() + (-3 + date.getTimezoneOffset() / 60) * 60 * 60 * 1000);
var month = date.getMonth();
var day = date.getDate();
var hour = date.getHours();
var currentDate = date.getFullYear() + '' + (month < 10 ? '0' : '') + month + '' + (day < 10 ? '0' : '') + day + (hour < 10 ? '0' : '') + hour;
if (parseInt(timeTo) > parseInt(currentDate)) {
Debug("User entered a date in the future..");
timeTo = currentDate;
}
var toYear = timeTo.substring(0, 4);
var toMonth = timeTo[4] + timeTo[5];
var toDay = timeTo[6] + timeTo[7];
var toHour = timeTo[8] + timeTo[9];
date.setFullYear(toYear);
date.setMonth(toMonth);
date.setDate(toDay);
date.setHours(toHour);
var fromDate = new Date();
var fromYear = timeFrom.substring(0, 4);
var fromMonth = timeFrom[4] + timeFrom[5];
var fromDay = timeFrom[6] + timeFrom[7];
var fromHour = timeFrom[8] + timeFrom[9];
fromDate.setFullYear(fromYear);
fromDate.setMonth(fromMonth);
fromDate.setDate(fromDay);
fromDate.setHours(fromHour);
var diffHours = Math.round((date - fromDate) / 3600000);
Info("Diffhours: " + diffHours);
for (var i = 0; i < diffHours; i++) {
fromDate.setHours(fromDate.getHours() + 1);
month = fromDate.getMonth() + 1;
day = fromDate.getDate();
hour = fromDate.getHours();
var key = fromDate.getFullYear() + '' + (month < 10 ? '0' : '') + month + '' + (day < 10 ? '0' : '') + day + (hour < 10 ? '0' : '') + hour;
// console.log(key);
var dummy = {};
for (var j = 0; j < thingsToLookFor.length; j++) {
dummy.Date = key;
if (logObject[key]) {
dummy[thingsToLookFor[j]] = logObject[key][thingsToLookFor[j]];
}
else if (returnArray.length > 1) {
dummy[thingsToLookFor[j]] = 0;
}
}
// console.log(dummy);
if (!logObject[key] && returnArray.length === 0) { continue; }
returnArray.push(dummy);
// console.log(fromDate);
}
// console.log(returnArray);
return returnArray;
*/
}
function DisplayHistory(logObject) {
var indexes = [];
try {
indexes = logObject.Indexes.split("|");
}
catch (e) {
if (logObject) { //Maybe it's the goldindexes that we are looking for
try {
indexes = logObject.split("|");
}
catch (e) {
$("#log").html("Something went wrong when processing your data..<br/>" + e.message);
return;
}
}
else { //Well.. if not.. just throw an error message
$("#log").html("Something went wrong when processing your data..<br/>" + e.message);
return;
}
}
var text = "";
var start = 0;
var end = indexes.length - 2;
if (end < 0) { end = 0; }
if (indexes.length > 1000 && !$("#reverseCheckbox").prop('checked')) {
start = indexes.length - 1000;
end = indexes.length;
}
else if (indexes.length > 1000 && $("#reverseCheckbox").prop("checked")) {
start = 0;
end = 1000;
}
Debug("NEW START: " + start + " | NEW END: " + end);
if ($("#reverseCheckbox").prop('checked')) {
for (var i = start; i <= end; i++) {
//text += "R-INDEX: " + indexes[i] + " | ";
if (LOG.Misc.Log[indexes[i] - 1]) {
text += LOG.Misc.Log[indexes[i] - 1] + '<br/>';
}
}
}
else {
for (var j = end; j >= start; j--) {
//text += "N-INDEX: " + indexes[j] + " | ";
if (LOG.Misc.Log[indexes[j]]) {
text += LOG.Misc.Log[indexes[j] - 1] + '<br/>';
}
}
}
$("#log").html(text);
}
function SetupLog() {
var tradeSelectRarityChart;
var fragment = document.createDocumentFragment();
var logDiv = $(document.createElement("div")).attr({ id: "logDiv", title: "Just Statistics" })
.css({ "font-size": "14px", "background-color": "lightgrey", "display": "none" })
.html('<ul><li><a href="#materialDiv">Items</a></li>' +
'<li><a href ="#multiDiv">Multis</a></li>' +
'<li><a href ="#rarityDiv">Rarites</a></li>' +
'<li><a href ="#nodeDiv">Node data</a></li>' +
'<li><a href ="#miscDiv">Miscellaneous</a></li>' +
'<li><a href ="#optionDiv">Options</a></li>' +
'<li><a href ="#helpDiv">Help</a></li>' +
'<li><a href ="#historyDiv">History</a></li>' +
'<li><a href ="#graphDiv">Graphs</a></li>' +