From d797b980ead21ac41ab21c97799dfe76a5916084 Mon Sep 17 00:00:00 2001 From: George Powell Date: Mon, 2 Feb 2026 00:48:35 -0500 Subject: [PATCH] updated ranking formula --- .env.example | 21 +++++++++++++ analyze_top_users.sh | 31 +++++++++++++++++++ daily_completions_report.sh | 34 +++++++++++++++++++++ src/lib/server/db/schema.ts | 2 -- src/routes/+page.server.ts | 9 +++++- src/routes/api/submit-completion/+server.ts | 16 ++++------ 6 files changed, 100 insertions(+), 13 deletions(-) create mode 100644 .env.example create mode 100755 analyze_top_users.sh create mode 100755 daily_completions_report.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..093733d --- /dev/null +++ b/.env.example @@ -0,0 +1,21 @@ +DATABASE_URL=example.db + +# nodemailer +SMTP_USERNAME=email@example.com +SMTP_TOKEN=TOKEN +SMTP_SERVER=smtp.example.com +SMTP_PORT=port +# note from mail provider: Enable TLS or SSL on the external service if it is supported. + +# sign in with Discord + +# sign in with google + +# sign in with apple +AUTH_SECRET=your-random-secret-here +APPLE_ID=com.yourcompany.yourapp.client +APPLE_TEAM_ID=your-team-id +APPLE_KEY_ID=your-key-id +APPLE_PRIVATE_KEY="-----BEGIN PRIVATE KEY----- +your-private-key-here +-----END PRIVATE KEY-----" diff --git a/analyze_top_users.sh b/analyze_top_users.sh new file mode 100755 index 0000000..1f33b81 --- /dev/null +++ b/analyze_top_users.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# analyze_top_users.sh +# Analyzes the daily_completions table to find the top 10 anonymous IDs by completion count + +# Set database path from argument or default to dev.db +DB_PATH="${1:-dev.db}" + +# Check if database file exists +if [ ! -f "$DB_PATH" ]; then + echo "Error: Database file not found: $DB_PATH" + echo "Usage: $0 [database_path]" + exit 1 +fi + +# Run the analysis query +sqlite3 "$DB_PATH" < c.guessCount < guessCount).length; const guessRank = betterGuesses + 1; + // Count ties: how many have the SAME guessCount (excluding self) + const tiedCount = allCompletions.filter(c => c.guessCount === guessCount && c.anonymousId !== anonymousId).length; + // Average guesses const totalGuesses = allCompletions.reduce((sum, c) => sum + c.guessCount, 0); const averageGuesses = Math.round((totalGuesses / totalSolves) * 10) / 10; + // Percentile: what percentage of people you beat (100 - your rank percentage) + const betterOrEqualCount = allCompletions.filter(c => c.guessCount <= guessCount).length; + const percentile = Math.round((betterOrEqualCount / totalSolves) * 100); + return { success: true, - stats: { solveRank, guessRank, totalSolves, averageGuesses } + stats: { solveRank, guessRank, totalSolves, averageGuesses, tiedCount, percentile } }; } }; diff --git a/src/routes/api/submit-completion/+server.ts b/src/routes/api/submit-completion/+server.ts index 0b80d09..b4e6dd7 100644 --- a/src/routes/api/submit-completion/+server.ts +++ b/src/routes/api/submit-completion/+server.ts @@ -44,11 +44,9 @@ export const POST: RequestHandler = async ({ request }) => { // Solve rank: position in time-ordered list const solveRank = allCompletions.findIndex(c => c.anonymousId === anonymousId) + 1; - // Guess rank: count how many DISTINCT guess counts are better (grouped ranking) - const uniqueBetterGuessCounts = new Set( - allCompletions.filter(c => c.guessCount < guessCount).map(c => c.guessCount) - ); - const guessRank = uniqueBetterGuessCounts.size + 1; + // Guess rank: count how many had FEWER guesses (ties get same rank) + const betterGuesses = allCompletions.filter(c => c.guessCount < guessCount).length; + const guessRank = betterGuesses + 1; // Count ties: how many have the SAME guessCount (excluding self) const tiedCount = allCompletions.filter(c => c.guessCount === guessCount && c.anonymousId !== anonymousId).length; @@ -110,11 +108,9 @@ export const GET: RequestHandler = async ({ url }) => { // Solve rank: position in time-ordered list const solveRank = allCompletions.findIndex(c => c.anonymousId === anonymousId) + 1; - // Guess rank: count how many DISTINCT guess counts are better (grouped ranking) - const uniqueBetterGuessCounts = new Set( - allCompletions.filter(c => c.guessCount < guessCount).map(c => c.guessCount) - ); - const guessRank = uniqueBetterGuessCounts.size + 1; + // Guess rank: count how many had FEWER guesses (ties get same rank) + const betterGuesses = allCompletions.filter(c => c.guessCount < guessCount).length; + const guessRank = betterGuesses + 1; // Count ties: how many have the SAME guessCount (excluding self) const tiedCount = allCompletions.filter(c => c.guessCount === guessCount && c.anonymousId !== anonymousId).length;