-
Notifications
You must be signed in to change notification settings - Fork 1
/
stats.php
65 lines (49 loc) · 2.78 KB
/
stats.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
<?php
/*
Tombola
Il classico gioco natalizio online.
Copyright (C) 2020 Vincenzo Padula
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
$title = "Statistiche";
include("page_header.php");
function getStat($query) {
global $dbh;
$result = mysqli_query($dbh, $query);
if($result) {
$n = (mysqli_fetch_array($result))["n"];
return ($n != null) ? $n : "-";
}
return "-";
}
function printStat($name, $query) {
$n = getStat($query);
echo "<tr><td>$name:</td><td>$n</td></tr>\n";
}
echo "<p>Statistiche</p>\n<table id='stats'>\n";
printStat("Partite concluse", "select count(*) n from ".PREFIX."server where accessibile is false and terminato is true;");
printStat("Partite in corso", "select count(*) n from ".PREFIX."server where accessibile is false and terminato is false and offlimits is false");
printStat("Partite in attesa", "select count(*) n from ".PREFIX."server where accessibile is true and offlimits is false");
printStat("Partite mai iniziate", "select count(*) n from ".PREFIX."server where accessibile is true and offlimits is true;");
printStat("Partite mai finite", "select count(*) n from ".PREFIX."server where accessibile is false and terminato is false and offlimits is true;");
$queryPartiteConcluse = "select idserver from ".PREFIX."server where accessibile is false and terminato is true";
$queryGiocatori = "select count(idserver) n from ".PREFIX."utente where privato is null and uscito is null and idserver in ($queryPartiteConcluse) group by idserver";
$queryAbbandoni = "select count(idserver) n from ".PREFIX."utente where privato is null and uscito is not null and idserver in ($queryPartiteConcluse) group by idserver";
printStat("Media giocatori per partita", "select format(avg(n), 1) n from ($queryGiocatori) t1;");
printStat("Maggior numero di giocatori in una partita", "select max(n) n from ($queryGiocatori) t1;");
printStat("Media abbandoni per partita", "select format(avg(n), 1) n from ($queryAbbandoni) t1;");
printStat("Maggior numero di abbandoni in una partita", "select max(n) n from ($queryAbbandoni) t1;");
echo "</table><br>\n".
"<button onclick='window.location.href=\"./\"'>Home</button>\n".
"<button onclick='window.location.reload()'>Ricarica</button>\n";
include("page_footer.php");
?>