-
Notifications
You must be signed in to change notification settings - Fork 11
/
eventreport.php
388 lines (361 loc) · 12.5 KB
/
eventreport.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
<?php session_start();
include 'lib.php';
print_header("Event Report");
?>
<div class="grid_10 prefix_1 suffix_1">
<div id="gatherling_main" class="box">
<div class="uppertitle"> Event Report </div>
<?php
if (isset($_GET['event'])) {
$event = new Event($_GET['event']);
showReport($event);
} else {
eventList();
}
?>
</div>
</div>
<?php print_footer(); ?>
<?php
function eventList($series = "", $season = "") {
$db = Database::getConnection();
$result = $db->query("SELECT e.name AS name, e.format AS format,
COUNT(DISTINCT n.player) AS players, e.host AS host, e.start AS start,
e.finalized, e.cohost, e.series, e.season
FROM events e
LEFT OUTER JOIN entries AS n ON n.event = e.name
WHERE 1=1 AND e.start < NOW() GROUP BY e.name ORDER BY e.start DESC");
if (!isset($_POST['format'])) {
$_POST['format'] = "";
}
if (!isset($_POST['series'])) {
$_POST['series'] = "";
}
if (!isset($_POST['season'])) {
$_POST['season'] = "";
}
$onlyformat = false;
if(strcmp($_POST['format'], "") != 0) {
$onlyformat = $_POST['format'];
}
$onlyseries = false;
if(strcmp($_POST['series'], "") != 0) {
$onlyseries = $_POST['series'];
}
$onlyseason = false;
if(strcmp($_POST['season'], "") != 0) {
$onlyseason = $_POST['season'];
}
echo "<form action=\"eventreport.php\" method=\"post\">";
echo "<table id=\"EventReport\">";
echo "<tr><td colspan=\"2\" align=\"center\"><b>Filters</td></tr>";
echo "<tr><td> </td></tr>";
echo "<tr><td>Format</td><td>";
formatDropMenu($_POST['format'], 1);
echo "</td></tr>";
echo "<tr><td>Series</td><td>";
Series::dropMenu($_POST['series'], 1);
echo "</td></tr>";
echo "<tr><td>Season</td><td>";
seasonDropMenu($_POST['season'], 1);
echo "</td></tr>";
echo "<tr><td> </td></tr>";
echo "<tr><td colspan=\"2\" align=\"center\">";
echo "<input type=\"submit\" name=\"mode\" value=\"Filter Events\">";
echo "</td></tr></table>";
echo "<table style=\"border-width: 0px\" align=\"center\" cellpadding=\"3\">";
echo "<tr><td colspan=\"5\"> </td></tr>";
echo "<tr><td><b>Event</td><td><b>Format</td>";
echo "<td align=\"center\"><b>No. Players</td>";
echo "<td><b>Host(s)</td></tr>";
$count = 0;
while($count < 100 && $thisEvent = $result->fetch_assoc()) {
if (($onlyformat && strcmp($thisEvent['format'], $onlyformat) != 0)
|| ($onlyseries && strcmp($thisEvent['series'], $onlyseries) != 0)
|| ($onlyseason && strcmp($thisEvent['season'], $onlyseason) != 0)) {
continue;
}
$dateStr = $thisEvent['start'];
$dateArr = explode(" ", $dateStr);
$date = $dateArr[0];
echo "<tr><td>";
echo "<a href=\"eventreport.php?event={$thisEvent['name']}\">";
echo "{$thisEvent['name']}</a></td>";
echo "<td>{$thisEvent['format']}</td>";
echo "<td align=\"center\">{$thisEvent['players']}</td>";
echo "<td>{$thisEvent['host']}";
$ch = $thisEvent['cohost'];
if(!is_null($ch) && strcmp($ch, "") != 0) {echo "/$ch";}
echo "</td>";
#echo "<td>$date</td>";
# echo "<td align=\"center\"><input type=\"checkbox\" ";
# if($thisEvent['finalized'] == 1) {echo "checked";}
# echo "></td>";
echo "</tr>";
$count = $count + 1;
}
$result->close();
if ($count == 100) {
echo "<tr><td colspan=\"5\" width=\"500\"> </td></tr>";
echo "<tr><td colspan=\"5\" align=\"center\">";
echo "<i>This list only shows the 100 most recent results. ";
echo "Please use the filters at the top of this page to find older ";
echo "results.</i></td></tr>";
}
echo "<tr><td colspan=\"5\" width=\"500\"> </td></tr>";
echo "</table></form>";
}
function showReport($event) {
echo "<div id=\"EventReport\">";
echo "<table width=900>\n";
echo "<tr><td width=300 valign=\"top\">";
imageCell($event);
echo "</td><td width=300 valign=\"top\">";
infoCell($event);
echo "</td><td width=300 valign=\"top\">";
trophyCell($event);
echo "</td></tr></table>";
echo "<table style=\"border-width: 0px;\" width=600>\n<tr><td>";
finalists($event);
echo "</td><td align=\"right\">";
metastats($event);
echo "</td></tr></table>\n</div>";
echo "<br /><br />";
fullmetagame($event);
}
function finalists($event) {
$nfinalists = sizeof($event->getFinalists());
echo "<table>\n";
echo "<tr><td colspan=3 align=\"center\"><b>TOP {$nfinalists}</td></tr>\n";
foreach ($event->getFinalists() as $finalist) {
$finaldeck = new Deck($finalist['deck']);
if ($finaldeck->new) {
$deckinfoarr = deckInfo(NULL);
} else {
$deckinfoarr = deckInfo($finaldeck);
}
$redstar = "<font color=\"#FF0000\">*</font>";
$append = " " . $finalist['medal'];
if($finalist['medal'] == 't8' || $finalist['medal'] == 't4') {
$append = " " . strtoupper($finalist['medal']);
}
$medalSTR = medalImgStr($finalist['medal']);
$medalSTR .= $append;
$manaSTR = image_tag("colors/{$deckinfoarr[1]}.png", array("alt" => "Deck Colors"));
$deckSTR = $finaldeck->linkTo();
if($deckinfoarr[2] < 60) {$deckSTR .= $redstar;}
if($deckinfoarr[2] < 6) {$deckSTR .= $redstar;}
$thisplayer = new Player($finalist['player']);
$playerSTR = "by {$thisplayer->linkTo()}";
echo "<tr><td>$medalSTR</td>\n<td>$manaSTR</td><td>$deckSTR</td>\n";
echo "<td align=\"right\">$playerSTR</td></tr>\n";
}
echo "</table>";
}
function metastats($event) {
$archcnt = initArchetypeCount();
$colorcnt = array("w" => 0, "g" => 0, "u" => 0, "r" => 0, "b" => 0);
$decks = $event->getDecks();
$ndecks = count($decks);
foreach ($decks as $deck) {
$deckarr = deckInfo($deck);
if($deckarr[1] != "blackout") {
$archcnt[$deckarr[3]]++;
$colors = str_split($deckarr[1]);
foreach ($colors as $color) {
$colorcnt[$color]++;
}
}
else {$ndecks--;}
}
echo "<table style=\"border-width: 0px;\" width=200>\n";
echo "<tr><td colspan=5 align=\"center\"><b>Metagame Stats</td></tr>\n";
foreach($archcnt as $arch => $cnt) {
if($cnt > 0) {
$pcg = round(($cnt / $ndecks)*100);
echo "<tr><td colspan=4 align=\"left\">$arch</td>";
echo "<td align=\"right\">$pcg%</td></tr>\n";
}
}
echo "<tr><td> </td></tr><tr>";
echo "<td align=\"center\">" . image_tag("manaw.png") . "</td>\n";
echo "<td align=\"center\">" . image_tag("manag.png") . "</td>\n";
echo "<td align=\"center\">" . image_tag("manau.png") . "</td>\n";
echo "<td align=\"center\">" . image_tag("manar.png") . "</td>\n";
echo "<td align=\"center\">" . image_tag("manab.png") . "</td>\n";
echo "</tr>";
echo "<tr>";
foreach($colorcnt as $col => $cnt) {
if ($col != "") {
if ($ndecks > 0) {
$pcg = round(($cnt / $ndecks)*100);
} else {
$pcg = "??";
}
echo "<td align=\"center\">$pcg%</td>\n";
}
}
echo "</tr>\n";
echo "</table>\n";
}
function fullmetagame($event) {
$decks = $event->getDecks();
$players = array();
foreach ($decks as $deck) {
$info = array("player" => $deck->playername, "deckname" => $deck->name,
"archetype" => $deck->archetype, "medal" => $deck->medal,
"id" => $deck->id);
$arr = deckInfo($deck);
$info["colors"] = $arr[1];
if($info['medal'] == "dot") {$info['medal'] = "z";}
$players[] = $info;
}
$db = Database::getConnection();
$succ = $db->query("CREATE TEMPORARY TABLE meta(
player VARCHAR(40), deckname VARCHAR(40), archetype VARCHAR(20),
colors VARCHAR(10), medal VARCHAR(10), id BIGINT UNSIGNED,
srtordr TINYINT UNSIGNED DEFAULT 0)");
$succ or die($db->error);
$stmt = $db->prepare("INSERT INTO meta(player, deckname, archetype, colors, medal, id)
VALUES(?, ?, ?, ?, ?, ?)");
foreach ($players as $player) {
$stmt->bind_param("sssssd", $player['player'],
$player['deckname'], $player['archetype'],
$player['colors'], $player['medal'], $player['id']);
$stmt->execute() or die($stmt->error);
}
$stmt->close();
$result = $db->query("SELECT colors, COUNT(player) AS cnt FROM meta GROUP BY(colors)");
$stmt = $db->prepare("UPDATE meta SET srtordr = ? WHERE colors = ?");
while($row = $result->fetch_assoc()) {
$stmt->bind_param("ds", $row['cnt'], $row['colors']);
$stmt->execute() or die($stmt->error);
}
$stmt->close();
$result->close();
$result = $db->query("SELECT player, deckname, archetype, colors, medal, id, srtordr
FROM meta ORDER BY srtordr DESC, colors, medal, player");
$color = "orange";
echo "<table style=\"border-width: 0px;\" align=\"center\">";
echo "<tr>";
echo "<td colspan=5 align=\"center\"><b>Metagame Breakdown</td></tr>\n";
while($row = $result->fetch_assoc()) {
if($row['colors'] != $color) {
$color = $row['colors'];
echo "<tr><td>";
echo image_tag("colors/{$color}.png") . " </td>\n";
echo "<td colspan=4 align=\"left\"><i>{$row['srtordr']} Players ";
echo "</td></tr>\n";
}
echo "<tr><td></td>\n";
echo "<td align=\"left\">";
echo "</td>\n<td align=\"left\">";
if ($event->finalized == '0') {
echo "Player is anonymous for deck privacy until event is finalized.";
} else {
// puts medal next to name of person who won it
if ($row['medal'] != "z") {
echo medalImgStr($row['medal']) . " ";
}
$play = new Player($row['player']);
$entry = new Entry($event->name, $play->name);
echo $play->linkTo() . "</td>\n";
echo "<td align=\left\">{$entry->recordString()}</td>";
echo "<td align=\"left\">";
echo "<a href=\"deck.php?mode=view&id={$row['id']}\">";
echo "{$row['deckname']}</a></td>\n";
echo "<td align=\"right\">{$row['archetype']}</td></tr>\n";
}
}
$result->close();
echo "</table>\n";
}
function deckInfo($deck) {
$ret = array("No Deck Submitted", "blackout", 0, "Unclassified");
if(!is_null($deck)) {
$colorstr = "";
$row = $deck->getColorCounts();
if($row['w'] > 0) {$colorstr .= 'w';}
if($row['g'] > 0) {$colorstr .= 'g';}
if($row['u'] > 0) {$colorstr .= 'u';}
if($row['r'] > 0) {$colorstr .= 'r';}
if($row['b'] > 0) {$colorstr .= 'b';}
$row['cnt'] = array_sum($deck->maindeck_cards);
if($colorstr == "") {$colorstr = "blackout";}
$ret = array($deck->name, $colorstr, $row['cnt'], $deck->archetype);
}
return $ret;
}
function initArchetypeCount() {
$ret = array();
$db = Database::getConnection();
$result = $db->query("SELECT name FROM archetypes ORDER BY priority DESC");
while($row = $result->fetch_assoc()) {
$ret[$row['name']] = 0;
}
$result->close();
return $ret;
}
function imageCell($event) {
echo "<div class=\"series-logo\"><img src=\"displaySeries.php?series=$event->series\" alt=\"Series Logo\" /></div>";
}
function infoCell($event) {
if(!is_null($event->threadurl)) {
echo "<a href=\"{$event->threadurl}\">{$event->name}</a><br />\n";
} else {
echo "{$event->name}<br />\n";
}
$date = date('j F Y', strtotime($event->start));
echo "$date<br />\n";
echo "{$event->format} ·\n";
$playercount = $event->getPlayerCount();
echo "{$playercount} Players<br />\n";
$deckcount = count($event->getDecks());
echo "{$deckcount} Decks · ";
if ($playercount == 0) {
$deckpercentexact = 0;
$deckpercent = 0;
} else {
$deckpercentexact = round($deckcount * 100 / $playercount, 2);
$deckpercent = round($deckcount * 100 / $playercount, 0);
}
if ($deckpercentexact == $deckpercent) {
echo "{$deckpercent}% Reported <br />\n";
} else {
echo "~{$deckpercent}% Reported <br />\n";
}
foreach ($event->getSubevents() as $subevent) {
if ($subevent->type != "Single Elimination") {
echo "{$subevent->rounds} rounds {$subevent->type}<br />\n";
} else {
$finalists = pow(2, $subevent->rounds);
echo "Top $finalists playoff<br />\n";
}
}
$host = new Player($event->host);
echo "Hosted by {$host->linkTo()}<br />";
if (!is_null($event->reporturl)) {
echo "<a href=\"{$event->reporturl}\">Event Report</a><br />\n";
}
echo "<a href=\"seriesreport.php?series={$event->series}&season={$event->season}\">Season Leaderboard</a>";
}
function trophyCell($event) {
if ($event->hastrophy) {
echo Event::trophy_image_tag($event->name) . "<br />\n";
} else {
echo image_tag("notrophy.png");
}
$deck = $event->getPlaceDeck('1st');
$player = $event->getPlacePlayer('1st');
if (!$player) {
echo "No winner yet!";
} else {
$playerwin = new Player($player);
echo $playerwin->linkTo();
$info = deckInfo($deck);
echo image_tag("colors/{$info[1]}.png");
echo $deck->linkTo();
echo "<br />\n";
}
}
?>