-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstats.php
145 lines (132 loc) · 3.9 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
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
<?php
require("lib/common.php");
list($db, $loggedIn) = colonyHTMLStart();
if(!colonyGet("playerID"))
colonyError("Must provide a playerID");
$playerID = intval($_GET["playerID"]);
$statement = $db->prepare("
SELECT displayName
FROM col_players
WHERE ID = :playerID
");
$statement->bindValue("playerID", $playerID);
$statement->execute();
while(FALSE !== ($row = $statement->fetch()))
{
$displayName = htmlspecialchars($row["displayName"]);
}
$statement->closeCursor();
$statement = $db->prepare("
SELECT COUNT(*) AS gamesPlaying
FROM col_games JOIN col_playing ON col_games.ID = col_playing.gameID
WHERE
col_games.state != :complete AND
col_games.isHidden = 0 AND
col_playing.playerID = :playerID
");
$statement->bindValue("complete", COMPLETE);
$statement->bindValue("playerID", $playerID);
$statement->execute();
while(FALSE !== ($row = $statement->fetch()))
{
$gamesPlaying = intval($row["gamesPlaying"]);
}
$statement->closeCursor();
$statement = $db->prepare("
SELECT
COUNT(*) AS gamesPlayed,
col_games.playerLimit AS playerLimit
FROM col_games JOIN col_playing ON col_games.ID = col_playing.gameID
WHERE
col_games.state = :complete AND
col_games.isHidden = 0 AND
col_playing.playerID = :playerID
GROUP BY col_games.playerLimit
");
$statement->bindValue("complete", COMPLETE);
$statement->bindValue("playerID", $playerID);
$statement->execute();
$gamesPlayedPerPlayerLimit = [];
$totalGamesPlayed = 0;
while(FALSE !== ($row = $statement->fetch()))
{
$gamesPlayed = intval($row["gamesPlayed"]);
$playerLimit = intval($row["playerLimit"]);
$gamesPlayedPerPlayerLimit[$playerLimit] = $gamesPlayed;
$totalGamesPlayed += $gamesPlayed;
}
$statement->closeCursor();
$statement = $db->prepare("
SELECT
COUNT(*) AS gamesWon,
col_games.playerLimit AS playerLimit
FROM col_games JOIN col_playing ON
col_games.ID = col_playing.gameID AND
col_games.activePlayerIndex = col_playing.playIndex
WHERE
col_games.state = :complete AND
col_games.isHidden = 0 AND
col_playing.playerID = :playerID
GROUP BY col_games.playerLimit
");
$statement->bindValue("complete", COMPLETE);
$statement->bindValue("playerID", $playerID);
$statement->execute();
$gamesWonPerPlayerLimit = [];
while(FALSE !== ($row = $statement->fetch()))
{
$gamesWon = intval($row["gamesWon"]);
$playerLimit = intval($row["playerLimit"]);
$gamesWonPerPlayerLimit[$playerLimit] = $gamesWon;
}
$statement->closeCursor();
$statement = $db->prepare("
SELECT MAX(longestRoadAmount) AS longestLongestRoad
FROM col_games
WHERE longestRoadID = :playerID
");
$statement->bindValue("playerID", $playerID);
$statement->execute();
while(FALSE !== ($row = $statement->fetch()))
{
$longestLongestRoad = intval($row["longestLongestRoad"]);
}
$statement->closeCursor();
$statement = $db->prepare("
SELECT MAX(largestArmyAmount) AS largestLargestArmy
FROM col_games
WHERE largestArmyID = :playerID
");
$statement->bindValue("playerID", $playerID);
$statement->execute();
while(FALSE !== ($row = $statement->fetch()))
{
$largestLargestArmy = intval($row["largestLargestArmy"]);
}
$statement->closeCursor();
?>
<div class="row">
<div class="col-xs-12">
<h1>Statistics</h1>
<p><?php echo($displayName);?></p>
<ul>
<li>Games playing: <?php echo($gamesPlaying);?></li>
<li>Total games played: <?php echo($totalGamesPlayed);?></li>
<?php
foreach($gamesWonPerPlayerLimit as $playerLimit => $gamesWon)
{
$numerator = $gamesWonPerPlayerLimit[$playerLimit];
$denominator = $gamesPlayedPerPlayerLimit[$playerLimit];
?>
<li><?php echo($playerLimit);?>-player games won: <?php echo($numerator);?>/<?php echo($denominator);?> (<?php echo(round(100 * $numerator / $denominator, 2));?>%)</li>
<?php
}
?>
<li>Longest longest road: <?php echo($longestLongestRoad);?></li>
<li>Largest largest army: <?php echo($largestLargestArmy);?></li>
</ul>
</div>
</div>
<?php
colonyHTMLEnd();
?>