forked from One-Piece-Online/OPOnline
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzzGameStats.php
More file actions
183 lines (158 loc) · 6.04 KB
/
zzGameStats.php
File metadata and controls
183 lines (158 loc) · 6.04 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
<?php
include_once 'MenuBar.php';
include_once "CardDictionary.php";
include_once "./Libraries/UILibraries2.php";
include_once './includes/functions.inc.php';
include_once "./includes/dbh.inc.php";
if (!isset($_SESSION["useruid"])) {
echo ("Please login to view this page.");
exit;
}
if(!isset($forIndividual)) $forIndividual = TryGet("forIndividual", false);
$forIndividual = ($forIndividual ? true : false);//If it evaluates to true, explicitly cast it to boolean
$useruid = $_SESSION["useruid"];
$userID = $_SESSION["userid"];
if (!$forIndividual) exit;
if ($forIndividual && !isset($_SESSION["isPatron"])) {
echo ("Please subscribe to our Patreon to access this page.");
exit;
}
$numDays = TryGet("numDays", 365);
echo ("<script src=\"./jsInclude.js\"></script>");
echo ("<style>
table {
border-radius: 10px;
border-spacing: 0;
border-collapse: collapse;
font-size: 1em;
line-height: 24px;
text-shadow: 2px 0 0 #1a1a1a, 0 -2px 0 #1a1a1a, 0 2px 0 #1a1a1a, -2px 0 0 #1a1a1a;
margin-left:auto;
margin-right:auto;
}
td {
border-bottom: 1px solid black;
text-align: center;
vertical-align: middle;
height: 50px;
padding: 10px;
font-size:0.95em;
}
tr:hover {
background-color: darkred;
}
h3 {
text-align: center;
font-size: 1.15em;
}
</style>");
echo ("<div id=\"cardDetail\" style=\"z-index:100000; display:none; position:fixed;\"></div>");
$winnerQuery = ($forIndividual ? "where WinningPID = ?" : "where WinningHero<>\"DUMMY\" and LosingHero<>\"DUMMY\" and CompletionTime >= DATE(NOW() - INTERVAL ? DAY)");
$loserQuery = ($forIndividual ? "where LosingPID = ?" : "where WinningHero<>\"DUMMY\" and LosingHero<>\"DUMMY\" and CompletionTime >= DATE(NOW() - INTERVAL ? DAY)");
$winnerQuery .= " and numTurns>1";
$loserQuery .= " and numTurns>1";
$sql = "SELECT Hero,sum(Count) AS Total FROM
(
select WinningHero As Hero,count(WinningHero) AS Count
from completedgame " . $winnerQuery . " group by WinningHero
union all
select LosingHero As Hero,count(LosingHero) AS Count
from completedgame
$loserQuery
group by LosingHero
) AS internalQuery
GROUP BY Hero
ORDER BY Total DESC";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
//header("location: ../Signup.php?error=stmtfailed");
echo ("ERROR");
exit();
}
$param = ($forIndividual ? $userID : $numDays);
mysqli_stmt_bind_param($stmt, "ss", $param, $param);
mysqli_stmt_execute($stmt);
// "Get result" returns the results from a prepared statement
$playData = mysqli_stmt_get_result($stmt);
$sql = "SELECT WinningHero,count(WinningHero) AS Count
FROM completedgame
$winnerQuery
GROUP by WinningHero
ORDER BY Count";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
//header("location: ../Signup.php?error=stmtfailed");
echo ("ERROR");
exit();
}
$param = ($forIndividual ? $userID : $numDays);
mysqli_stmt_bind_param($stmt, "s", $param);
mysqli_stmt_execute($stmt);
// "Get result" returns the results from a prepared statement
$winData = mysqli_stmt_get_result($stmt);
$blitzPlays = 0;
$ccPlays = 0;
$gameData = [];
while ($row = mysqli_fetch_array($playData, MYSQLI_NUM)) {
array_push($gameData, []);
$index = count($gameData) - 1;
$gameData[$index][0] = $row[0];
$gameData[$index][1] = $row[1];
if (CharacterHealth($row[0]) > 25) $ccPlays += $row[1];
else $blitzPlays += $row[1];
}
while ($row = mysqli_fetch_array($winData, MYSQLI_NUM)) {
$heroID = $row[0];
for ($i = 0; $i < count($gameData) && $gameData[$i][0] != $heroID; ++$i);
array_push($gameData[$i], $row[1]);
}
echo ("<div id='wrapper' style='text-align: center; position:relative;'>");
if(!$forIndividual) echo ("<section class='game-stats'>");
echo ("<div><table>");
echo ("<tr><td>Hero</td><td>Num Wins</td><td>Num Plays</td><td>Win %</td><td>Played %</td></tr>");
echo ("<h2>CC Heroes</h2>");
foreach ($gameData as $row) {
//while ($row = mysqli_fetch_array($playData, MYSQLI_NUM)) {
if (CharacterHealth($row[0]) <= 25) continue; //Filter out blitz heroes for now
if (CardType($row[0]) != "C") continue;
//if(CharacterHealth($row[0]) > 25) continue;//Filter out cc heroes for now
$formatDenominator = (CharacterHealth($row[0]) > 25 ? $ccPlays : $blitzPlays);
$winPercent = (((count($row) > 2 ? $row[2] : 0) / $row[1]) * 100);
$playPercent = ($row[1] / $formatDenominator * 100);
echo ("<tr>");
if($forIndividual) echo ("<td><a href='./zzPlayerHeroStats.php?heroID=$row[0]'>" . CardName($row[0]) . "</a></td>");
else echo ("<td><a href='./zzHeroStats.php?heroID=$row[0]'>" . CardName($row[0]) . "</a></td>");
//echo ("<td>" . CardLink($row[0], $row[0], true) . "</td>");
echo ("<td>" . (count($row) > 2 ? $row[2] : 0) . "</td>");
echo ("<td>" . $row[1] . "</td>");
echo ("<td>" . number_format($winPercent, 2, ".", "") . "% </td>");
echo ("<td>" . number_format($playPercent, 2, ".", "") . "% </td>");
echo ("</tr>");
}
echo ("</table>");
echo ("<BR>");
echo ("<h2>Young Heroes</h2>");
echo ("<table>");
echo ("<tr><td>Hero</td><td>Num Wins</td><td>Num Plays</td><td>Win %</td><td>Played %</td></tr>");
foreach ($gameData as $row) {
//while ($row = mysqli_fetch_array($playData, MYSQLI_NUM)) {
if (CharacterHealth($row[0]) > 25) continue; //Filter out cc heroes for now
if (CardType($row[0]) != "C") continue;
$formatDenominator = (CharacterHealth($row[0]) > 25 ? $ccPlays : $blitzPlays);
$winPercent = (((count($row) > 2 ? $row[2] : 0) / $row[1]) * 100);
$playPercent = ($row[1] / $formatDenominator * 100);
echo ("<tr>");
if($forIndividual) echo ("<td><a href='./zzPlayerHeroStats.php?heroID=$row[0]'>" . CardName($row[0]) . "</a></td>");
else echo ("<td><a href='./zzHeroStats.php?heroID=$row[0]'>" . CardName($row[0]) . "</a></td>");
//echo ("<td>" . CardLink($row[0], $row[0], true) . "</td>");
echo ("<td>" . (count($row) > 2 ? $row[2] : 0) . "</td>");
echo ("<td>" . $row[1] . "</td>");
echo ("<td>" . number_format($winPercent, 2, ".", "") . "% </td>");
echo ("<td>" . number_format($playPercent, 2, ".", "") . "% </td>");
echo ("</tr>");
}
echo ("</table><div>");
if(!$forIndividual) echo ("</section>");
echo ("</div>");
echo ("</div>");
echo ("</div>");