fixed stats page to show correct number of skipped clues. reflected this change accurately in leaderboards for users and admins as to not create a bug where a skipped clue would contribute to progress

This commit is contained in:
bobbert committed 2025-03-18 22:35:04 +00:00
1 parent 2f9a6c732c
commit 4cd449c0cf
8 files changed
+46 -39

No files matched your search

+11 -18
View File
@@ -66,29 +66,16 @@ export async function GET(request) {
[token.teamId]
);
// We need to calculate skipped clues - these are clues that have higher IDs than the user's lowest unfound clue
// First, get all clue IDs
// Get all clue IDs - this part is still useful for other calculations
const allClueIds = await query("SELECT id FROM clues ORDER BY id ASC");
// Convert to a simple array of IDs
const allClueIdArray = allClueIds.map((c) => c.id);
// Create a set of found clue IDs for easy lookup
const foundClueIdSet = new Set(foundClues.map((c) => c.id));
// Find all unfound clue IDs
const unfoundClueIds = allClueIdArray.filter(
(id) => !foundClueIdSet.has(id)
);
// If there are unfound clues, the ones after the first unfound are "skipped"
let skippedCluesCount = 0;
if (unfoundClueIds.length > 0) {
const lowestUnfoundId = Math.min(...unfoundClueIds);
// Skipped clues are found clues with IDs higher than the lowest unfound
skippedCluesCount = foundClues.filter((c) => c.id > lowestUnfoundId).length;
}
// Replace the old skipped clues calculation with this simple count
let skippedCluesCount = skippedClues.length;
// Get current team rank
const teamRankings = await query(`
@@ -114,16 +101,22 @@ export async function GET(request) {
let currentRank = teamRankings.findIndex((t) => t.id === team.id) + 1;
if (currentRank === 0) currentRank = teamRankings.length + 1; // If not found (shouldn't happen)
// Update progress calculation - don't subtract skippedCluesCount since foundClues query already excludes skipped clues
const correctlyFoundCount = foundClues.length; // <-- Fixed: don't subtract again
// Construct response object
const teamStats = {
team,
totalClues,
foundClues,
remainingClues: totalClues - foundClues.length,
skippedClues,
remainingClues: totalClues - correctlyFoundCount,
skippedCluesCount,
currentRank,
progress:
totalClues > 0 ? Math.round((foundClues.length / totalClues) * 100) : 0,
totalClues > 0
? Math.round((correctlyFoundCount / totalClues) * 100)
: 0,
};
// Return only the teamStats object instead of trying to include undefined variables