Add average score per highest tile to stats feed - #13
Conversation
🤖 Claude has reviewed this PR — expand after forming your own opinionPerformanceN+1 query problem — the data is already in memory. The initial Accumulate the sum in PHP while iterating the existing result set — zero extra queries: $maxTileStats = array();
$scoreStats = array();
$scoreSums = array();
$result = $mysqli->query($statsQuery);
if (!$result) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
while ($row = $result->fetch_row()) {
$max_tile = (int)$row[0];
$score = (int)$row[1];
if (isset($maxTileStats[$max_tile]))
$maxTileStats[$max_tile]++;
else
$maxTileStats[$max_tile] = 1;
if (!isset($scoreSums[$max_tile]))
$scoreSums[$max_tile] = 0;
$scoreSums[$max_tile] += $score;
array_push($scoreStats, $score);
}
$result->close();
$avgScorePerTile = array();
foreach ($maxTileStats as $max_tile => $count) {
$avgScorePerTile[$max_tile] = (int)round($scoreSums[$max_tile] / $count);
}This eliminates the entire SecurityThe Code QualityNo other issues — the new |
Extends the game stats payload with an
avg_scoremap giving the average final score for each highest-tile value. This lets the stats chart show how the typical score scales as players reach larger tiles.movefeed.php.?stats=1is requested, so the normal move feed is unaffected.