-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpublicstats.php
356 lines (313 loc) · 11.2 KB
/
publicstats.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
<?php
if ($_SERVER['REQUEST_METHOD'] != "GET") {
header('HTTP/1.0 400 Invalid Request');
die();
}
$root = $_SERVER['DOCUMENT_ROOT'];
require_once $root . '/include.php';
global $dbcon;
$me = Session::CurrentUser();
?>
<!DOCTYPE html>
<html>
<head>
<?php
include "header.shtml";
$pagetitle = "Stats";
$pagedesc = "Stats";
$pagekeywords = "";
$pageimg = "";
$pageurl = "https://ktdash.app/publicstats.php";
include "og.php";
?>
<style>
<?php include "css/styles.css"; ?>
th, td {
padding-left: 15px;
padding-right: 15px;
}
</style>
</head>
<body ng-app="kt" ng-controller="ktCtrl">
<?php
include "topnav.shtml";
?>
<h1 class="m-0 p-1 orange">
<span class="fas fa-chart-line fa-fw"></span> Stats
</h1>
<div class="p-2">
<!-- Totals -->
<div class="container">
<h2 class="text-center">Totals</h2>
<?php
$sql =
"SELECT 'Users' AS CountType, COUNT(*) AS Count FROM User WHERE userid NOT IN ('prebuilt', 'vince') UNION
SELECT 'Rosters', COUNT(*) AS RosterCount FROM Roster WHERE userid NOT IN ('prebuilt', 'vince') UNION
SELECT 'RosterOps', COUNT(*) AS RosterOpCount FROM RosterOperative WHERE userid NOT IN ('prebuilt', 'vince')";
$cmd = $dbcon->prepare($sql);
// Load the stats
echo "\r\n<!-- " . floor(microtime(true) * 1000) . " - Get Totals -->\r\n";
$cmd->execute();
echo "\r\n<!-- " . floor(microtime(true) * 1000) . " - Got Totals -->\r\n";
echo "<table class=\"center\" style=\"width: 100%;\">";
echo "<tr class=\"line-bottom-light\"><th class=\"center\" width=\"33%\">Users</th><th class=\"center\" width=\"33%\">Rosters</th><th class=\"center\" width=\"33%\">RosterOps</th></tr><tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<td class="center"><?php echo number_format($row->Count) ?></td>
<?php
}
}
echo "</tr>";
echo "</table>";
?>
</div>
<hr/>
<!-- Roster Stats -->
<div class="row m-0 p-0">
<h2 class="col-12 m-0 p-0 text-center">Roster Stats</h2>
<div class="col-12 col-md-6 m-0 p-0">
<h5>Most Viewed Rosters</h5>
<?php
$sql =
"SELECT U.username, R.rostername, KT.killteamname, KT.edition, CONCAT('https://ktdash.app/r/', rosterid, '/g') AS rosterlink, CONCAT('https://ktdash.app/u/', U.username) AS userlink, viewcount
FROM Roster R
INNER JOIN User U ON U.userid = R.userid
INNER JOIN Killteam KT ON KT.factionid = R.factionid AND KT.killteamid = R.killteamid
WHERE R.userid NOT IN ('prebuilt')
ORDER BY viewcount DESC
LIMIT 10;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr>
<th>Roster</th>
<th style=\"text-align: center;\">Total Views</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr class="line-top-light">
<td>
<a href="<?php echo $row->rosterlink ?>"><?php echo $row->rostername ?></a><br/>
<?php echo $row->killteamname ?><sup><?php echo $row->edition ?></sup>
by <a class="navloader" href="<?php echo $row->userlink ?>"><span class="badge bg-secondary"><i class="fas fa-user fa-fw"></i> <?php echo $row->username ?></span></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->viewcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
<div class="col-12 col-md-6 m-0 p-0">
<h5>Most Imported Rosters</h5>
<?php
$sql =
"SELECT U.username, R.rostername, KT.killteamname, KT.edition, CONCAT('https://ktdash.app/r/', rosterid) AS rosterlink, CONCAT('https://ktdash.app/u/', U.username) AS userlink, importcount
FROM Roster R
INNER JOIN User U ON U.userid = R.userid
INNER JOIN Killteam KT ON KT.factionid = R.factionid AND KT.killteamid = R.killteamid
WHERE R.userid NOT IN ('prebuilt')
ORDER BY importcount DESC
LIMIT 10;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr>
<th>Roster</th>
<th style=\"text-align: center;\">Total Imports</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr class="line-top-light">
<td>
<a href="<?php echo $row->rosterlink ?>"><?php echo $row->rostername ?></a><br/>
<?php echo $row->killteamname ?><sup><?php echo $row->edition ?></sup>
by <a class="navloader" href="<?php echo $row->userlink ?>"><span class="badge bg-secondary"><i class="fas fa-user fa-fw"></i> <?php echo $row->username ?></span></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->importcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
</div>
<hr/>
<!-- User Stats -->
<div class="row m-0 m-0 p-0">
<h2 class="col-12 m-0 p-0 text-center">User Stats</h2>
<div class="col-12 col-md-6 m-0 p-0">
<h5>Most Viewed Users</h5>
<?php
$sql =
"SELECT U.username, CONCAT('https://ktdash.app/u/', U.username) AS userlink, SUM(viewcount) AS viewcount
FROM Roster R
INNER JOIN User U ON U.userid = R.userid
WHERE R.userid NOT IN ('prebuilt')
GROUP BY U.username, CONCAT('https://ktdash.app/u/', U.username)
ORDER BY SUM(viewcount) DESC
LIMIT 10;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr class=\"line-bottom-light\">
<th>User</th>
<th style=\"text-align: center;\">Total Views</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr>
<td>
<a class="navloader" href="<?php echo $row->userlink ?>"><span class="badge bg-secondary"><i class="fas fa-user fa-fw"></i> <?php echo $row->username ?></span></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->viewcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
<div class="col-12 col-md-6 m-0 p-0">
<h5>Most Imported Users</h5>
<?php
$sql =
"SELECT U.username, CONCAT('https://ktdash.app/u/', U.username) AS userlink, SUM(importcount) AS importcount
FROM Roster R
INNER JOIN User U ON U.userid = R.userid
WHERE R.userid NOT IN ('prebuilt')
GROUP BY U.username, CONCAT('https://ktdash.app/u/', U.username)
ORDER BY SUM(importcount) DESC
LIMIT 10;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr class=\"line-bottom-light\">
<th>User</th>
<th style=\"text-align: center;\">Total Imports</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr>
<td>
<a class="navloader" href="<?php echo $row->userlink ?>"><span class="badge bg-secondary"><i class="fas fa-user fa-fw"></i> <?php echo $row->username ?></span></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->importcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
<div class="col-12 col-md-6 m-0 p-0">
<h5>Most Spotlighted Users</h5>
<?php
$sql =
"SELECT U.username, CONCAT('https://ktdash.app/u/', U.username) AS userlink, COUNT(DISTINCT R.rosterid) AS spotlightcount
FROM Roster R
INNER JOIN User U ON U.userid = R.userid
WHERE R.userid NOT IN ('prebuilt') AND R.spotlight = 1
GROUP BY U.username, CONCAT('https://ktdash.app/u/', U.username)
ORDER BY COUNT(DISTINCT R.rosterid) DESC
LIMIT 10;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr class=\"line-bottom-light\">
<th>User</th>
<th style=\"text-align: center;\">Spotlights</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr>
<td>
<a class="navloader" href="<?php echo $row->userlink ?>"><span class="badge bg-secondary"><i class="fas fa-user fa-fw"></i> <?php echo $row->username ?></span></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->spotlightcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
</div>
<br/>
<hr/>
<!-- KillTeam Stats -->
<div class="row m-0 m-0 p-0">
<h2 class="col-12 m-0 p-0 text-center">KillTeam Stats</h2>
<div class="col-12 col-md-6 m-0 p-0">
<?php
$sql =
"SELECT KT.killteamname, KT.edition, CONCAT('https://ktdash.app/fa/', KT.factionid, '/kt/', KT.killteamid) AS killteamlink, SUM(CASE WHEN R.rosterid IS NULL THEN 0 ELSE 1 END) AS rostercount, SUM(R.spotlight) AS spotlightcount
FROM Killteam KT
LEFT JOIN Roster R
ON R.factionid = KT.factionid AND R.killteamid = KT.killteamid AND R.rostername != 'Sample Team: Intercessors'
GROUP BY KT.killteamname, KT.factionid, KT.killteamid, KT.edition
ORDER BY SUM(CASE WHEN R.rosterid IS NULL THEN 0 ELSE 1 END) DESC;";
$cmd = $dbcon->prepare($sql);
// Load the stats
$cmd->execute();
echo "<table>
<tr class=\"line-bottom-light\">
<th>KillTeam</th>
<th style=\"text-align: center;\">Rosters</th>
<th style=\"text-align: center;\">Spotlights</th>
</tr>";
if ($result = $cmd->get_result()) {
while ($row = $result->fetch_object()) {
// Got a result
?>
<tr>
<td>
<a class="navloader" href="<?php echo $row->killteamlink ?>"><?php echo $row->killteamname ?><sup><?php echo $row->edition ?></sup></a>
</td>
<td style="text-align: center;">
<?php echo number_format($row->rostercount) ?>
</td>
<td style="text-align: center;">
<?php echo number_format($row->spotlightcount) ?>
</td>
</tr>
<?php
}
}
echo "</table><br/><br/>";
?>
</div>
</div>
</div>
<?php include "footer.shtml" ?>
</body>
</html>