-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamPlayerJS.js
More file actions
445 lines (423 loc) · 13.3 KB
/
TeamPlayerJS.js
File metadata and controls
445 lines (423 loc) · 13.3 KB
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
//Previes Teams
var glob_aloitusheitot;
var glob_heitotyli;
var glob_heitotali;
var PlayerGlobalTrows;
$( document ).ready(function() {
$( "#TeamPlayer" ).dialog({
autoOpen: false,
width: 900,
height: 700,
show:{effect: "slide",duration: 200},
hide:{effect: "slide",duration: 200}
});
});
function hae_tiedot(nimi){
var max_amount;
var Trow_Names =["Hauki", "Virkamies","1", "2", "3", "4", "5","6",">6"];
var select_year = $("#Years option:selected").text();
if (nimi != ""){
if (select_year < 2018){
max_amount = 19;
}else{
max_amount = 20;
}
}
$.getJSON("http://pinq.kapsi.fi/github/workspace/index.php", {cmd : "player",name: nimi, year : select_year})
.done(function(data){
if (data.pelaaja.nimi == "not found"){
$("#Nimi").text("Pelaaja ei löydy");
}
else{
$('#PlayerInfo th').tooltip({ delay:0, fade:250,position:{my:"center top-40",at:"center top"}});
var PlayerPoints = PlayerCountPoints(data.heitot,max_amount);
var PlayerPointsDis = pisteiden_taulukointi(data.heitot,PlayerPoints[0]);
UpdatePlayerinfo(data.pelaaja.nimi,data.pelaaja.numero,PlayerPoints,PlayerPointsDis);
Update_barchar(PlayerPoints[4][3],PlayerPointsDis,PlayerPoints[5]);
Update_pies(PlayerPoints,Trow_Names,max_amount);
}
});
}
function UpdatePlayerinfo(Pname,Pnumber,PlayerPoints,PPointsDis){
$("#PlayerName").text(Pname + " #" +Pnumber);
$("#era_maara").text(PPointsDis[4].length);
$("#max_era").text(Math.max.apply(null,PPointsDis[5][0]));
$("#min_era").text(Math.min.apply(null,PPointsDis[5][0]));
$("#average_era").text(Math.round(100*(PPointsDis[5][0].reduce(add,0)/PPointsDis[5][0].length))/100);
$("#heitot_maara").text(PlayerPoints[0].length);
$("#pisteet_maara").text(PlayerPoints[4][2]);
$("#pisteetper_maara").text(PlayerPoints[4][3]);
$("#pisteetper_eka").text(PPointsDis[7][0][0]+" ("+PPointsDis[7][0][1]+")");
$("#pisteetper_tok").text(PPointsDis[7][1][0]+" ("+PPointsDis[7][1][1]+")");
$("#pisteetper_kol").text(PPointsDis[7][2][0]+" ("+PPointsDis[7][2][1]+")");
$("#pisteetper_nel").text(PPointsDis[7][3][0]+" ("+PPointsDis[7][3][1]+")");
$("#PlayerBestTrow").text(PlayerPoints[0].max()/2);
$("#hauki_prosentti").text(PlayerPoints[4][0]+"%");
$("#nolla_prosentti").text(PlayerPoints[4][4]+"%");
$("#nolla_putki").text(PPointsDis[6]);
$("#Joulukuuset").text(PlayerPoints[4][1]);
if ($(".PlayerInfo div:eq(1)").html() == null){
$('#PlayerInfo').DataTable({
paging: false,
searching: false,
"info": false,
"bSort" : false
});
$(".PlayerInfo div:eq(1)").html("<b>Pelaajatiedot</b>");
$(".PlayerInfo div:eq(1)").css({"padding": "0px", "font-size":"1em","min-width": "542px"});
$(".PlayerInfo div:last").css("min-width", "530px");
}
}
function Update_pies(PlayerPoints,Trow_Names,max_amount){
if (glob_heitotyli != null){
glob_heitotyli.destroy();
}
if (glob_heitotali != null){
glob_heitotali.destroy();
}
if (glob_aloitusheitot != null){
glob_aloitusheitot.destroy();
}
// glob_pisteet = pisteet[2];
var bgColors = [
'#e03d07',
'#e06508',
'#e1dd0a',
'#c3f203',
'#9ef402',
'#78f702',
'#51fa01',
'#65d101',
'#00cc00'
];
prosentti_label = {label: function(tooltipItem, data) {
// console.log(data,tooltipItem.yLabel);
var dataset = data.datasets[tooltipItem.datasetIndex];
var total = dataset.data.reduce(function(previousValue, currentValue, currentIndex, array) {
return previousValue + currentValue;
});
var currentValue = dataset.data[tooltipItem.index];
var precentage = Math.floor(((currentValue/total) * 100)+0.5);
return precentage + "% (" + tooltipItem.yLabel + ")";
}}
// console.log(paikat);
$("#maara_1").text('Heittoja: '+ PlayerPoints[1].reduce(add, 0));
var ctx = document.getElementById("heitotyli").getContext('2d');
glob_heitotyli = new Chart(ctx, {
type: 'bar',
data: {
labels: Trow_Names,
datasets: [{
data: PlayerPoints[1],
backgroundColor: bgColors,
}]
},
options: {
responsive: true,
title: {
display: true,
text: 'Yli '+ max_amount
},
legend: {
display: false
},
tooltips: {
callbacks: prosentti_label
}
}
});
if (PlayerPoints[2].length != 0){
$("#maara_2").text('Heittoja: '+ PlayerPoints[2].reduce(add, 0));
var ctx2 = document.getElementById("heitotali").getContext('2d');
glob_heitotali = new Chart(ctx2, {
type: 'bar',
data: {
labels: Trow_Names,
datasets: [{
data: PlayerPoints[2],
backgroundColor: bgColors,
}
]
},
options: {
responsive: true,
title: {
display: true,
text: 'Alle '+ max_amount
},
legend: {
display:false,
},
tooltips: {
callbacks: prosentti_label
}
}
});
}else{$("#maara_2").text('')};
if (PlayerPoints[3].length != 0){
$("#maara_3").text('Heittoja: '+ PlayerPoints[3].reduce(add, 0));
var ctx3 = document.getElementById("aloitusheitot").getContext('2d');
glob_aloitusheitot = new Chart(ctx3, {
type: 'bar',
data: {
labels: Trow_Names,
datasets: [{
data: PlayerPoints[3],
backgroundColor: bgColors,
}
]
},
options: {
responsive: true,
title: {
display: true,
text: 'Aloitusheitot'
},
legend: {
display:false,
},
tooltips: {
callbacks: prosentti_label
}
}
});
}else{$("#maara_3").text('')};
if (PlayerGlobalTrows == null){
$("#js-legend").append(glob_heitotyli.generateLegend());
}
}
function Update_barchar(AvrageHeitto,PlayerPointsDis,Gamelist){
// console.log(AvrageHeitto,PlayerPointsDis,Gamelist);
if (PlayerGlobalTrows != null){
PlayerGlobalTrows.destroy();
}
$.each(PlayerPointsDis[4], function(i,val){
PlayerPointsDis[4][i] = PlayerPointsDis[5][0][i]+ " (" + PlayerPointsDis[4][i] + ")";
});
var ctx4 = document.getElementById("PlayerPoints").getContext('2d');
AvrageHeitto = Array.apply(null, Array(PlayerPointsDis[0].length)).map(Number.prototype.valueOf,AvrageHeitto);
var AvrageList = [];
PlayerGlobalTrows= new Chart(ctx4, {
type: 'bar',
data: {
labels: PlayerPointsDis[4],
datasets: [{
type: 'line',
label: 'Pelaajan keskiarvo',
borderColor: 'rgb(50, 50, 0)',
borderWidth: 1,
fill: false,
radius: 0,
data: AvrageHeitto
},{
type: 'line',
label: 'kyykat/heitto',
borderColor: 'rgb(255, 51, 51)',
borderWidth: 4,
fill: false,
data: PlayerPointsDis[5][1]
},{
type: 'bar',
label: 'Ensimmäinen',
backgroundColor: 'rgb(0, 92, 230)',
stack: 'vuoro 0',
data: PlayerPointsDis[0]
}, {
type: 'bar',
label: 'Toinen',
backgroundColor: 'rgb(102, 163, 255)',
stack: 'vuoro 0',
data: PlayerPointsDis[1]
}, {
type: 'bar',
label: 'Kolmas',
backgroundColor: 'rgb(230, 138, 0)',
stack: 'Vuoro 1',
data: PlayerPointsDis[2]
}, {
type: 'bar',
label: 'Neljas',
backgroundColor: 'rgb(255, 194, 102)',
stack: 'Vuoro 1',
data: PlayerPointsDis[3]
}]
},
options: {
title:{
display:true,
text:"Heitot"
},
tooltips: {
mode: 'index',
callbacks: {
title: function(tooltipItem) {
return Gamelist[tooltipItem[0].index];
}
},
filter: function(item, data) {
var data = data.datasets[item.datasetIndex].data[item.index];
return !isNaN(data) && data !== null;
}
},
responsive: true,
scales: {
xAxes: [{
stacked: true,
}]
}
}
});
}
function PlayerCountPoints(TrowList,max_amount){
// console.log(TrowList,max_amount);
var alle = [];
var yli = [];
var aloitus = [];
var points = [];
var Game = [0,0,0];
tieto = [0,0,0,0,0]; //1.hauuet% ;2. joulukuuset;3.points yht ;4. pistettä/heitto
var PlayerGamelist = [];
var heittoja = 0;
$.each(TrowList, function(index,val) {
if(val.kyykat != '?'){
heittoja ++;
if(Game[1] != val.ottelu_numero || Game[2] != val.era){
PlayerGamelist.push(val.vieras_joukkue);
Game[0] ++;
Game[1] = val.ottelu_numero;
Game[2] = val.era;
}
if(val.jaljella == max_amount*2){
// console.log(val.kyykat);
aloitus.push(val.kyykat);
}
if(val.jaljella >= max_amount){
yli.push(val.kyykat);
}
else if(val.jaljella < max_amount){
alle.push(val.kyykat);
}
if(val.kyykat === 'h'){
points.push(0);
tieto[0] ++;
}
else{
points.push(val.kyykat*2);
if (Number(val.kyykat) == 6){
tieto[1] ++;
}
tieto[2] += Number(val.kyykat)*2;
// tieto[3] += Number(val.kyykat);
}
if(val.kyykat === 'h' || Number(val.kyykat) == 0){
tieto[4] ++;
}
}
});
var count_yli = heittojen_maara(yli);
var count_alle = heittojen_maara(alle);
var count_aloitus = heittojen_maara(aloitus);
tieto[0] = Math.round(1000*(tieto[0]/points.length))/10;
tieto[3] = Math.round(100*((tieto[2]/2)/points.length))/100;
tieto[4] = Math.round(1000*(tieto[4]/points.length))/10;
// console.log([points,count_yli,count_alle,count_aloitus,tieto]);
return [points, count_yli, count_alle, count_aloitus, tieto, PlayerGamelist];
}
function heittojen_maara(lista){
if (lista.length === 0){
return [];
}
tulos_lista = [0,0,0,0,0,0,0,0,0];
$.each(lista, function(index, val){
if (lista[index] === 'h'){
tulos_lista[0] += 1;
}
else if(Number(lista[index]) < 7){
tulos_lista[Number(lista[index])+1] += 1;
}
else {
tulos_lista[8] += 1;
}
});
return tulos_lista;
}
function pisteiden_taulukointi(lista,piste_lista){
var label = [];
var eraScore = [[],[]];
var paikat = [[],[],[],[]];
var nollat = [0,0];
var Game = [0,0,0];
var EraPoints = 0;
var positon = 0;
var order = 0;
var Trows = [[],[],[],[]];
$.each(piste_lista, function(i,val){
if( val == 0){
nollat[0] += 1;
if (nollat[0] > nollat[1]){
nollat[1] = nollat[0];
}
}else{
nollat[0] = 0;
}
});
// console.log(lista.length/4)
// console.log(lista);
$.each(lista, function(i,val){
// console.log(val,order);
if(Game[1] != val.ottelu_numero || Game[2] != val.era){
if(Game[0] != 0){
eraScore[0].push(EraPoints);
eraScore[1].push(EraPoints/order);
EraPoints = 0;
while (order < 4){
Trows[order].push(null);
order ++;
}
}
order = 0;
label.push(val.heitto_paikka);
Game[0] ++;
Game[1] = val.ottelu_numero;
Game[2] = val.era;
}
if(val.kyykat == 'h'){
paikat[Number(val.heitto_paikka)-1].push(0);
Trows[order].push(0);
}else if(val.kyykat != '?'){
paikat[Number(val.heitto_paikka)-1].push(Number(val.kyykat));
Trows[order].push(Number(val.kyykat));
}else{
Trows[order].push(null);
}
if(isNaN(val.kyykat) == false){
EraPoints += Number(val.kyykat);
// console.log(val.kyykat);
}
// console.log(i,val)
positon = val.heitto_paikka;
order ++;
});
eraScore[0].push(EraPoints);
eraScore[1].push(EraPoints/order);
// console.log([aloitus, toka, kolmas, neljas, label ,keskiarvo ]);
$.each(paikat,function(i,val){
if(val.length != 0){
paikat[i] = [Math.round(100*(val.reduce(add,0)/val.length))/100,val.length];
}else{
paikat[i] = ["",0];
}
});
// console.log(Game[0], label, eraScore, paikat);
return [Trows[0], Trows[1], Trows[2], Trows[3], label ,eraScore, nollat[1], paikat, Game[0], ];
// return [game[0], label,eraScore ];
}
function add(a, b) {
return Number(a) + Number(b);
}
Array.prototype.max = function() {
return Math.max.apply(null, this);
};
Array.prototype.min = function() {
return Math.min.apply(null, this);
};