-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayers.php
More file actions
161 lines (134 loc) · 4.15 KB
/
Copy pathplayers.php
File metadata and controls
161 lines (134 loc) · 4.15 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
<?php
require_once __DIR__ . '/lib/config.php';
echo html::menu();
// Get filter vars.
$filter = get_timefilter();
$usefilter = false;
if (isset($filter['sql'])) {
$usefilter = true;
echo html::filter($filter);
}
// Define table columns.
$orderby = 6;
$table['cols'] = ['Name'];
if ($filter['col'] != 'date') {
$table['cols'][] = 'S';
$orderby += 1;
}
$table['cols'][] = 'G';
$table['cols'][] = 'W';
$table['cols'][] = 'L';
$table['cols'][] = 'W%';
$table['cols'][] = 'G+/-';
// Session.
if ($filter['col'] == 'date') {
$table['cols'][] = 'ELO';
// Season.
} elseif ($filter['col'] == 'season') {
$table['cols'][] = 'ELO';
$table['cols'][] = 'sELO';
$orderby += 1;
// Alltime.
} else {
$table['cols'][] = 'ELO';
}
// Table rows.
$table['rows'] = [];
$players = $DB->query("SELECT * FROM players")->fetchAll();
// Regulars only?
if ($filter['filter'] == 'regulars') {
$gamecount = $DB->count('games');
$cutoff = $gamecount / 10;
}
foreach ($players as $player) {
// Get teams and games.
$player_id = $player['id'];
$team_ids = get_team_ids($player_id);
$wins = get_wins($team_ids);
$losses = get_losses($team_ids);
// Get season sessions.
if ($filter['col'] == 'season') {
$sessions = get_player_sessions($player_id, false, $filter['default']);
} else {
$sessions = get_player_sessions($player_id, false);
}
// Calculate ELO and goals.
$gp = 0;
$gm = 0;
$elo_diff = 0;
$s_elo_diff = 0;
foreach ($wins as $key => $win) {
// Filter - ToDo: move to SQL query.
if ($usefilter) {
$value = $filter['default'];
$col = $filter['col'];
if ($win[$col] != $value) {
unset($wins[$key]);
continue;
}
}
$gp += $win['wg'];
$gm += $win['lg'];
$elo_diff += $win['elo_diff'];
$s_elo_diff += $win['s_elo_diff'];
}
foreach ($losses as $key => $loss) {
// Filter - ToDo: move to SQL query.
if ($usefilter) {
$value = $filter['default'];
$col = $filter['col'];
if ($loss[$col] != $value) {
unset($losses[$key]);
continue;
}
}
$gm += $loss['wg'];
$gp += $loss['lg'];
$elo_diff -= $loss['elo_diff'];
$s_elo_diff -= $loss['s_elo_diff'];
}
$win = count($wins);
$loss = count($losses);
$games = $win + $loss;
// Skip players that didnt compete this session/season.
if ($games == 0 || (isset($cutoff) && $games < $cutoff)) {
continue;
}
// Add to table.
$row = [];
$row[] = ['class' => 'player-cell', 'value' => write_player($player)];
if ($filter['col'] != 'date') {
$row[] = ['class' => 'number-cell', 'value' => $sessions];
}
$row[] = ['class' => 'number-cell', 'value' => $games];
$row[] = ['class' => 'number-cell', 'value' => $win];
$row[] = ['class' => 'number-cell', 'value' => $loss];
$win_percentage = $games > 0 ? number_format(($win / $games) * 100, 1) . '%' : '0%';
$row[] = ['class' => 'number-cell ', 'value' => $win_percentage];
$avg_goals = number_format(($gp - $gm) / $games, 2);
$row[] = ['class' => 'number-cell' , 'value' => $avg_goals];
// Session.
if ($filter['col'] == 'date') {
$row[] = ['class' => 'elo-cell ', 'value' => format_elo($elo_diff, '', '')];
// Season.
} elseif ($filter['col'] == 'season') {
$row[] = ['class' => 'elo-cell', 'value' => format_elo($elo_diff, '', '')];
$row[] = ['class' => 'number-cell', 'value' => ELO::current($player_id, $filter['default'])];
// Alltime.
} else {
$row[] = ['class' => 'number-cell', 'value' => $player['elo']];
}
$table['rows'][] = $row;
}
echo html::table($table);
?>
<a class="button add-button" href="./addplayer.php"></a>
<script>
$(document).ready(function() {
var dtOptions = <?php echo json_encode($datatables_config); ?>;
dtOptions.order = [[<?php echo $orderby ?>, 'desc']];
dtOptions.language.info = '_TOTAL_ players';
$('#table').DataTable(dtOptions);
});
</script>
<?php echo html::footer();?>