-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinclude.php
213 lines (166 loc) · 4.63 KB
/
include.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
<?php
##
## include.php
## by Naomi Peori ([email protected])
##
$title = "Street Fighter Halifax";
$subtitle = "Tuesday Night Ranking Battles";
$sponsor = "Hosted by <a href='http://www.twitch.tv/lastgs'>The Last Game Store</a>";
$arguments = explode ( "&", urldecode ( $_SERVER['QUERY_STRING'] ) );
$argument = $arguments[ 0 ];
##
## Configuration
##
$matchesFiles = array ( "data/saltshaker.csv", "data/challonge.csv" );
##
## CSV Functions
##
function GetCSV ( $matchesFiles )
{
$csvRows = array ( );
foreach ( $matchesFiles as $filename )
{
if ( $file = fopen ( $filename, "r" ) )
{
while ( ! feof ( $file ) )
{
if ( $values = fgetcsv ( $file ) )
{
array_push ( $csvRows, array_combine ( array ( "season", "event", "winner", "winnerElo", "loser", "loserElo", "eloChange" ), $values ) );
}
}
fclose ( $file );
}
}
return $csvRows;
}
$csvRows = GetCSV ( $matchesFiles );
##
## Row Functions
##
function GetRows ( $season = "", $event = "" )
{
$rows = array ( );
global $csvRows;
foreach ( $csvRows as $row )
{
if ( $row != "" )
{
if ( $season == "" || $row[ "season" ] == $season )
{
if ( $event == "" || $row[ "event" ] == $event )
{
array_push ( $rows, $row );
}
}
}
}
return $rows;
}
function SortRows ( $rows, $sortby, $reverse = "false" )
{
usort ( $rows, function ( $a, $b ) use ( $sortby ) { return $a[ $sortby ] <=> $b[ $sortby ]; } );
if ( $reverse ) { rsort ( $rows ); }
}
##
## Value Functions
##
function GetValues ( $fields, $season = "", $event = "" )
{
$values = array ( );
foreach ( GetRows ( $season, $event ) as $row )
{
if ( is_scalar ( $fields ) )
{
array_push ( $values, $row[ $fields ] );
}
else
{
foreach ( $fields as $field )
{
array_push ( $values, $row[ $field ] );
}
}
}
return $values;
}
function GetUniqueValues ( $fields, $season = "", $event = "" )
{
return array_unique ( GetValues ( $fields, $season, $event ) );
}
##
## Helper Functions
##
function GetRanks ( $season = "", $event = "" )
{
$ranks = array ( );
foreach ( GetUniqueValues ( array ( "winner", "loser" ), $season, $event ) as $player )
{
$ranks[ $player ] = array ( 'name' => $player, 'wins' => 0, 'losses' => 0, 'total' => 0, 'percentage' => 0, 'elo' => 0, 'eloChange' => 0 );
}
foreach ( GetRows ( $season, $event ) as $row )
{
$winner = $row[ "winner" ];
$loser = $row[ "loser" ];
$ranks[ $winner ][ "wins" ] += 1;
$ranks[ $loser ][ "losses" ] += 1;
$ranks[ $winner ][ "total" ] += 1;
$ranks[ $loser ][ "total" ] += 1;
$ranks[ $winner ][ "percentage" ] = ( $ranks[ $winner ][ "wins" ] / $ranks[ $winner ][ "total" ] ) * 100;
$ranks[ $loser ][ "percentage" ] = ( $ranks[ $loser ][ "wins" ] / $ranks[ $loser ][ "total" ] ) * 100;
$ranks[ $winner ][ "eloChange" ] += $row[ "eloChange" ];
$ranks[ $loser ][ "eloChange" ] -= $row[ "eloChange" ];
if ( $season != "" )
{
$ranks[ $winner ][ "elo" ] = 1200 + $ranks[ $winner ][ "eloChange" ];
$ranks[ $loser ][ "elo" ] = 1200 + $ranks[ $loser ][ "eloChange" ];
}
else if ( $event != "" )
{
$ranks[ $winner ][ "elo" ] = $row [ "winnerElo" ] + $ranks[ $winner ][ "eloChange" ];
$ranks[ $loser ][ "elo" ] = $row [ "loserElo" ] + $ranks[ $loser ][ "eloChange" ];
}
}
return $ranks;
}
function GetAttendances ( $season )
{
$attendances = array ( );
$events = GetUniqueValues ( "event", $season );
foreach ( $events as $event )
{
$attendances[ $event ][ "season" ] = $season;
$attendances[ $event ][ "event" ] = $event;
$attendances[ $event ][ "players" ] = count ( GetUniqueValues ( array ( "winner", "loser" ), $season, $event ) );
$attendances[ $event ][ "matches" ] = count ( GetRows ( $season, $event ) );
$attendances[ $event ][ "average" ] = ( $attendances[ $event ][ "matches" ] / $attendances[ $event ][ "players" ] * 2 );
}
return $attendances;
}
##
## Utility Functions
##
function GetRange ( $rows, $field, $offset = 0 )
{
$range = 0;
foreach ( $rows as $row )
{
$value = abs ( $row[ $field ] - $offset );
if ( $value > $range )
{
$range = $value;
}
}
return $range;
}
function GetColour ( $value, $offset, $range )
{
$value = ( $value - $offset ) / $range;
if ( $value < -1 ) { $value = -1; }
if ( $value > 1 ) { $value = 1; }
$red = ( $value < 0 ) ? 255 : 255 - ( $value * 255 );
$green = ( $value > 0 ) ? 255 : 255 - ( -$value * 255 );
$blue = 0;
return sprintf ( "#%02X%02X%02X", $red, $green, $blue );
}
?>