-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.js
160 lines (142 loc) · 5.16 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
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
var regions = ["Demacia", "Freljord", "Ionia", "Noxus", "PiltoverZaun", "ShadowIsles", "Bilgewater"]
var regionWinrate = [];
const Store = require('electron-store');
const data = new Store({name:"data"});
var regionIcons = {
"Demacia": "icons/icon-demacia.png",
"Noxus": "icons/icon-noxus.png",
"Freljord": "icons/icon-freljord.png",
"PiltoverZaun": "icons/icon-piltover.png",
"Ionia": "icons/icon-ionia.png",
"ShadowIsles": "icons/icon-shadowisles.png",
"Bilgewater": "icons/icon-bilgewater.png",
"Targon": "icons/icon-targon.png",
"Shurima": "icons/icon-shurima.png",
"BandleCity": "icons/icon-bandlecity.png"
};
var table = $('<table></table>').addClass("pure-table");
for (var i = 0; i < regions.length + 2; i++) {
row = $('<tr></tr>');
if (i % 2 == 0) {
row.addClass("pure-table-odd")
}
let regionWins = 0;
let regionLosses = 0;
for (var j = 0; j < regions.length + 2; j++) {
let rowData;
if (i == 0 && j == 0) {
rowData = $('<td></td>').text("");
}
else if (i == 0 && j !== regions.length + 1) {
rowData = $('<td></td>').html(`<img src="${regionIcons[regions[j - 1]]}" class="regionPicture">`);
}
else if (j == 0 && i !== regions.length + 1) {
rowData = $('<td></td>').html(`<img src="${regionIcons[regions[i - 1]]}" class="regionPicture">`);
}
else if (i == regions.length + 1) {
if (j == 0) {
rowData = $('<td></td>');
}
else if (j == regions.length + 1) {
rowData = $('<td></td>');
// Add up all
}
else {
rowData = $('<td></td>').addClass("text-center").text(regionWinrate[j - 1]).css("white-space", "pre-line");
}
}
else if (j == regions.length + 1) {
if (i == 0 || i == regions.length + 1) {
rowData = $('<td></td>');
}
else {
let text = ""
///
let showWinrate = false;
let showWinLoss = true;
let showTotalGames = true;
///
if (showWinrate) {
if (text.length !== 0)
text += "\n";
text += (regionWins / (regionWins + regionLosses) * 100).toFixed(0) + "%"
}
if (showTotalGames) {
if (text.length !== 0)
text += "\n";
text += regionWins + regionLosses
}
if (showWinLoss) {
if (text.length !== 0)
text += "\n";
text += regionWins + " - " + regionLosses
}
rowData = $('<td></td>').addClass("text-center").text(text).css("white-space", "pre-line");
regionWinrate.push(text);
}
}
else {
let tempRegions;
if (regions[i - 1] == regions[j - 1]) {
tempRegions = [regions[i - 1]]
}
else {
tempRegions = [regions[i - 1], regions[j - 1]]
}
let wins = 0;
let losses = 0;
for ( let deck of data.get("decks").filter(o => arraysEqual(o.regions, tempRegions))) {
wins += deck.wins;
losses += deck.losses;
}
regionWins += wins;
regionLosses += losses;
let text = "";
///
let showWinrate = false;
let showWinLoss = true;
let showTotalGames = true;
///
if (wins + losses == 0) {
text = "-"
//rowData = $('<td></td>').addClass("text-center").text("-");
}
else {
if (showWinrate) {
if (text.length !== 0)
text += "\n";
text += (wins / (wins + losses) * 100).toFixed(0) + "%"
}
if (showTotalGames) {
if (text.length !== 0)
text += "\n";
text += wins + losses
}
if (showWinLoss) {
if (text.length !== 0)
text += "\n";
text += wins + " - " + losses
}
}
rowData = $('<td></td>').addClass("text-center").text(text).css("white-space", "pre-line");
}
row.append(rowData);
}
table.append(row);
}
function arraysEqual(a, b) {
if (a === b) return true;
if (a == null || b == null) return false;
if (a.length !== b.length) return false;
a.sort();
b.sort();
// If you don't care about the order of the elements inside
// the array, you should sort both arrays here.
// Please note that calling sort on an array will modify that array.
// you might want to clone your array first.
for (var i = 0; i < a.length; ++i) {
if (a[i] !== b[i]) return false;
}
return true;
}
$("body").append(table)