-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistics.php
548 lines (375 loc) · 16.1 KB
/
statistics.php
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
<?php
// Pagina di statistiche delle passate 24 ore
include_once "inclusions.php";
$edition = NULL;
if ( array_key_exists("match_id", $_GET) ) {
$match_id = $_GET["match_id"];
if ( is_numeric($match_id) ) {
$match_id = (int)$match_id;
$edition = new Edition($match_id);
if ( ! ($edition->load()) ) {
$edition = NULL;
}
else {
// Carico anche il resto
$edition->load_more_information();
$edition->load_participants();
$edition->load_couples();
}
}
}
start_html("Statistiche");
make_header(true, "history");
if ( is_null($edition) ) {
// Statistiche generali di tutte le 24 ore
start_box("Statistiche generali");
/*
Tabella con le due squadre ([per ora no] numero di vittorie, numero di gol fatti in totale, numero di partecipanti, capitani
Tabella con le migliori statistiche positive
Tabella con i giocatori (tempo di gioco totale, gol fatti totali, partecipazioni con squadra/e)
*/
$stats = new GeneralStatistics();
$stats->load_teams();
$stats->load_participants();
$stats->load_couples();
// Tabella con le due squadre
$head = array();
$head[] = "";
foreach ( $stats->teams as $team ) {
$head[] = $team->name;
}
$table = array();
$row = array();
$row[] = "Gol totali";
foreach ( $stats->teams as $team ) {
$row[] = " ".$team->score;
}
$table[] = $row;
$row = array();
$row[] = "Partecipanti";
foreach ( $stats->teams as $team ) {
$row[] = " ".$team->num_participants;
}
$table[] = $row;
$row = array();
$row[] = "Capitani e vicecapitani";
foreach ( $stats->teams as $team ) {
$captains = $team->captains;
$subtable = array();
foreach ( $captains as $match_id => $couple ) {
$subtable[] = array( $couple[0]->link().", ".$couple[1]->link(), " (".$stats->editions[$match_id]->link().")" );
}
$row[] = return_table($subtable, FALSE, FALSE, FALSE, array("td" => "class=\"zero\"") );
}
$table[] = $row;
$first_width = 120;
$second_width = 380;
$col_widths = array( $first_width );
foreach ( $stats->teams as $team ) {
$col_widths[] = $second_width;
}
make_table($table, "tabella", $head, FALSE, array("col_widths" => $col_widths ) );
echo "<br />";
// Grafici
echo '<div class="graph_score">';
echo '<img src="graph_global.php?type=goals" />';
echo '<img src="graph_global.php?type=participants" />';
echo '</div>';
?>
<p><table id="tabella_scelte"><col width="220" /><col width="220" /><col width="220"><tr>
<th id="A" class="selected_choice" onclick="alpha()"><a href='javascript:void(0)'>Partecipanti</a></th>
<th id="B" class="choice" onclick="beta()"><a href='javascript:void(0)'>Statistiche individuali</a></th>
<th id="C" class="choice" onclick="gamma()" ><a href='javascript:void(0)'>Statistiche per coppie</a></th>
</tr></table></p>
<?php
// Tabella con tutti i partecipanti
echo "<div id=\"partecipanti\">";
$name_width = 220;
$time_width = 160;
$goals_width = 100;
$part_width = 300;
$head = array("<a href='javascript:void(0)'>Nome</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>", "<a href='javascript:void(0)'>Squadra e partecipazioni</a>");
$table = array();
foreach ( $stats->participants as $player ) {
$seconds = $player->seconds;
$pos_goals = $player->pos_goals;
$num_participations = count($player->participations);
// Scrivo le partecipazioni
$part = array();
foreach ( $player->participations as $p ) {
$edition = $p[0];
$team = $p[1];
if (!array_key_exists($team->name,$part)) {
$part[$team->name] = $team->name." (".$edition->link();
}
else {
$part[$team->name] .= ", ".$edition->link();
}
}
$participations = "";
$flag = TRUE;
foreach ( $part as $p ) {
if ( $flag ) $flag = FALSE;
else $participations .= ", ";
$participations .= $p.")";
}
$table[] = array( $player->link(), return_hidden_key($seconds).format_time($seconds), $player->pos_goals, return_hidden_key($num_participations).return_hidden_key($seconds).$participations );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width, $part_width) ) );
echo "</div>";
// Statistiche migliori individuali
/*
Consideriamo solo i giocatori che hanno giocato per >=30min*num_partite e con differenza reti positiva.
- Tempo giocato
- Gol fatti
- Gol subiti
- Differenza reti
- Differenza reti / tempo
- Gol fatti / tempo
- Gol subiti / tempo
Stessa cosa per le coppie
*/
echo "<div id=\"statistiche_individuali\">";
paragraph("Tutti i partecipanti con almeno 2 ore di gioco totali e differenza reti positiva.");
$name_width = 220;
$time_width = 160;
$goals_width = 100;
$part_width = 300;
$head = array("<a href='javascript:void(0)'>Nome</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>", "<a href='javascript:void(0)'>Gol subiti</a>", "<a href='javascript:void(0)'>Diff. reti</a>", "<a href='javascript:void(0)'>GF/minuto</a>", "<a href='javascript:void(0)'>GS/minuto</a>", "<a href='javascript:void(0)'>Diff/minuto</a>", "<a href='javascript:void(0)'>Squadra e partecipazioni</a>");
$table = array();
foreach ( $stats->participants as $player ) {
$seconds = $player->seconds;
$pos_goals = $player->pos_goals;
$neg_goals = $player->neg_goals;
$diff = $pos_goals - $neg_goals;
$num_participations = count($player->participations);
$num_editions = count($stats->editions);
// Check per sapere se mettere questo giocatore o no
if ( $seconds < 30*60*$num_editions || $diff <= 0 ) continue;
$minutes = $seconds / 60;
$pos_rate = $pos_goals / $minutes;
$neg_rate = $neg_goals / $minutes;
$diff_rate = $diff / $minutes;
// Scrivo le partecipazioni
$part = array();
foreach ( $player->participations as $p ) {
$edition = $p[0];
$team = $p[1];
if (!array_key_exists($team->name,$part)) {
$part[$team->name] = $team->name." (".$edition->link();
}
else {
$part[$team->name] .= ", ".$edition->link();
}
}
$participations = "";
$flag = TRUE;
foreach ( $part as $p ) {
if ( $flag ) $flag = FALSE;
else $participations .= ", ";
$participations .= $p.")";
}
$table[] = array( $player->link(), return_hidden_key($seconds).format_time($seconds), $pos_goals, $neg_goals, $diff, sprintf("%.2f",$pos_rate), sprintf("%.2f",$neg_rate), sprintf("%.2f",$diff_rate), return_hidden_key($num_participations).return_hidden_key($seconds).$participations );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $part_width) ) );
echo "</div>";
// Statistiche migliori per coppie
echo "<div id=\"statistiche_coppie\">";
paragraph("Le 60 coppie che hanno giocato per più tempo.");
$name_width = 400;
$time_width = 160;
$goals_width = 100;
$part_width = 300;
$head = array("<a href='javascript:void(0)'>Coppia</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>", "<a href='javascript:void(0)'>Gol subiti</a>", "<a href='javascript:void(0)'>Diff. reti</a>", "<a href='javascript:void(0)'>GF/minuto</a>", "<a href='javascript:void(0)'>GS/minuto</a>", "<a href='javascript:void(0)'>Diff/minuto</a>");
$table = array();
foreach ( $stats->couples as $couple ) {
$seconds = $couple->seconds;
$pos_goals = $couple->pos_goals;
$neg_goals = $couple->neg_goals;
$diff = $pos_goals - $neg_goals;
$minutes = $seconds / 60;
$pos_rate = $pos_goals / $minutes;
$neg_rate = $neg_goals / $minutes;
$diff_rate = $diff / $minutes;
$pr = sprintf("%.2f",$pos_rate);
$nr = sprintf("%.2f",$neg_rate);
$dr = sprintf("%.2f",$diff_rate);
if ( $diff <= 0 ) {
// Oscuro i dati nel caso in cui la differenza reti sia <= 0.
$neg_goals = "";
$diff = "";
$nr = "";
$dr = "";
}
$table[] = array( $couple->link(), return_hidden_key($seconds).format_time($seconds), $pos_goals, $neg_goals, $diff, $pr, $nr, $dr );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width) ) );
echo "</div>";
}
else {
// Statistiche relative ad una singola edizione della 24 ore
start_box("Statistiche 24 ore: ".$edition->year);
// Informazioni generali
$table = array( array( "Inizio:", $edition->begin->format_ita() ),
array( "Fine:", $edition->end->format_ita() ),
array( "Luogo:", $edition->place ) );
paragraph(return_table($table));
// Tabella delle due squadre
$fwidth = 380;
$swidth = 60;
echo "<table id=\"tabella\"><col width=\"" . $fwidth . "\"><col width=\"" . $swidth . "\"><col width=\"" . $swidth . "\"><col width=\"" . $fwidth . "\">\n";
echo "<tr><th class=\"center\">" . $edition->teams[0]->name . "</th><td class=\"center\">" . $edition->score[0] . "</td><td class=\"center\">" . $edition->score[1] . "</td><th class=\"center\">" . $edition->teams[1]->name . "</th></tr>\n";
echo "<tr>";
for ($i=0; $i<=1; $i++) {
echo "<td colspan=\"2\">";
$table = array();
$table[] = array( "Capitano:", $edition->captains[$i][0]->link($match_id) );
$table[] = array( "Vicecapitano:", $edition->captains[$i][1]->link($match_id) );
$table[] = array( "Prima coppia:", $edition->first_players[$i][0]->link($match_id).", ".$edition->first_players[$i][1]->link($match_id) );
$table[] = array( "Partecipanti:", count($edition->teams[$i]->participants) );
make_table($table, FALSE, FALSE, FALSE, array("td" => "class=\"zero\"") );
echo "</td>";
}
echo "</tr>\n";
echo "</table>";
// Grafico
echo '<div class="graph_score"><img src="graph_score.php?match_id='.$edition->id.'" /></div>';
?>
<br />
<p><table id="tabella_scelte"><col width="220" /><col width="220" /><col width="220"><tr>
<th id="A" class="selected_choice" onclick="alpha()"><a href='javascript:void(0)'>Partecipanti</a></th>
<th id="B" class="choice" onclick="beta()"><a href='javascript:void(0)'>Statistiche individuali</a></th>
<th id="C" class="choice" onclick="gamma()" ><a href='javascript:void(0)'>Statistiche per coppie</a></th>
</tr></table></p>
<?php
// Tabella dei partecipanti
echo "<div id=\"partecipanti\">";
echo "<table id=\"tabella_semplice\"><tr>";
echo "<th>". $edition->teams[0]->name ."</th><th>". $edition->teams[1]->name ."</th></tr><tr>";
$name_width = 220;
$time_width = 160;
$goals_width = 100;
for ($i=0; $i<=1; $i++) {
echo "<td>";
$head = array("<a href='javascript:void(0)'>Nome</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>");
$table = array();
foreach ( $edition->teams[$i]->participants as $player ) {
$seconds = $player->seconds;
$pos_goals = $player->pos_goals;
$table[] = array( $player->link($match_id), return_hidden_key($seconds).format_time($seconds), $player->pos_goals );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width) ) );
echo "</td>";
}
echo "</tr></table>";
echo "</div>";
// Tabella delle statistiche
/*
- Tempo giocato
- Gol fatti
- Differenza reti / tempo
- Gol fatti / tempo
- Gol subiti / tempo
Stessa cosa per le coppie
*/
echo "<div id=\"statistiche_individuali\">";
paragraph("Tutti i partecipanti con almeno 20 minuti di gioco e differenza reti positiva.");
$name_width = 220;
$time_width = 160;
$goals_width = 100;
$team_width = 105;
$head = array("<a href='javascript:void(0)'>Nome</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>", "<a href='javascript:void(0)'>Gol subiti</a>", "<a href='javascript:void(0)'>Diff. reti</a>", "<a href='javascript:void(0)'>GF/minuto</a>", "<a href='javascript:void(0)'>GS/minuto</a>", "<a href='javascript:void(0)'>Diff/minuto</a>", "<a href='javascript:void(0)'>Squadra</a>");
$table = array();
// Creo l'array con i partecipanti che soddisfano le condizioni
$participants = array();
for ($i=0; $i<=1; $i++) {
foreach ( $edition->teams[$i]->participants as $player ) {
$seconds = $player->seconds;
$pos_goals = $player->pos_goals;
$neg_goals = $player->neg_goals;
// Check per decidere se mettere o no questo giocatore
if ( $seconds >= 20*60 && $pos_goals > $neg_goals ) {
$participants[$player->fname." ".$player->lname." ".$player->comment." ".$player->id] = $player;
}
}
}
ksort( $participants );
foreach ( $participants as $player ) {
$seconds = $player->seconds;
$pos_goals = $player->pos_goals;
$neg_goals = $player->neg_goals;
$diff = $pos_goals - $neg_goals;
$minutes = $seconds / 60;
$pos_rate = $pos_goals / $minutes;
$neg_rate = $neg_goals / $minutes;
$diff_rate = $diff / $minutes;
$team = $player->team->name;
$table[] = array( $player->link($match_id), return_hidden_key($seconds).format_time($seconds), $pos_goals, $neg_goals, $diff, sprintf("%.2f",$pos_rate), sprintf("%.2f",$neg_rate), sprintf("%.2f",$diff_rate), $team );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $team_width) ) );
echo "</div>";
// Statistiche delle coppie che hanno giocato per più tempo
echo "<div id=\"statistiche_coppie\">";
paragraph("Le 60 coppie che hanno giocato per più tempo.");
$name_width = 360;
//$time_width = 160;
//$goals_width = 100;
//$team_width = 160;
$head = array("<a href='javascript:void(0)'>Coppia</a>", "<a href='javascript:void(0)'>Tempo di gioco</a>", "<a href='javascript:void(0)'>Gol fatti</a>", "<a href='javascript:void(0)'>Gol subiti</a>", "<a href='javascript:void(0)'>Diff. reti</a>", "<a href='javascript:void(0)'>GF/minuto</a>", "<a href='javascript:void(0)'>GS/minuto</a>", "<a href='javascript:void(0)'>Diff/minuto</a>", "<a href='javascript:void(0)'>Squadra</a>");
$table = array();
foreach ( $edition->couples as $couple ) {
$seconds = $couple->seconds;
$pos_goals = $couple->pos_goals;
$neg_goals = $couple->neg_goals;
$diff = $pos_goals - $neg_goals;
$minutes = $seconds / 60;
$pos_rate = $pos_goals / $minutes;
$neg_rate = $neg_goals / $minutes;
$diff_rate = $diff / $minutes;
$pr = sprintf("%.2f",$pos_rate);
$nr = sprintf("%.2f",$neg_rate);
$dr = sprintf("%.2f",$diff_rate);
if ( $diff <= 0 ) {
// Oscuro i dati nel caso in cui la differenza reti sia <= 0.
$neg_goals = "";
$diff = "";
$nr = "";
$dr = "";
}
$table[] = array( $couple->link($match_id), return_hidden_key($seconds).format_time($seconds), $pos_goals, $neg_goals, $diff, $pr, $nr, $dr, $couple->team->name );
}
make_table($table, "tabella", $head, FALSE, array("table" => "class=\"sortable\"", "col_widths" => array($name_width, $time_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $goals_width, $team_width) ) );
echo "</div>";
}
?>
<script type="text/javascript">
function alpha() {
show("partecipanti");
hide("statistiche_individuali");
hide("statistiche_coppie");
document.getElementById("A").setAttribute("class", "selected_choice");
document.getElementById("B").setAttribute("class", "choice");
document.getElementById("C").setAttribute("class", "choice");
}
function beta() {
hide("partecipanti");
show("statistiche_individuali");
hide("statistiche_coppie");
document.getElementById("A").setAttribute("class", "choice");
document.getElementById("B").setAttribute("class", "selected_choice");
document.getElementById("C").setAttribute("class", "choice");
}
function gamma() {
hide("partecipanti");
hide("statistiche_individuali");
show("statistiche_coppie");
document.getElementById("A").setAttribute("class", "choice");
document.getElementById("B").setAttribute("class", "choice");
document.getElementById("C").setAttribute("class", "selected_choice");
}
alpha();
</script>
<?php
end_box();
end_html();
?>