Overview
Leaderboard routes display rankings for regular and autumn competition participants, separated by key stage.Regular Leaderboard
Display leaderboards separated by key stages
Top 20 KS3 (Years 7-8) leaderboard entries, ordered by score descending
Top 20 KS4 (Years 9-11) leaderboard entries, ordered by score descending
Top 20 KS5 (Years 12-13) leaderboard entries, ordered by score descending
Last 15 activities including:
- Challenge completions (with challenge title)
- Points awarded events
- Timestamps for each activity
Competition statistics:
ks3_participants: Number of KS3 participantsks4_participants: Number of KS4 participantsks5_participants: Number of KS5 participantstotal_points_awarded: Sum of all pointstotal_challenges: Total challenge counttotal_submissions: Total submission count
- Leaderboard entries from
LeaderboardEntrymodel - Recent submissions from
AnswerSubmission(correct answers only) - Key stage filtering using lowercase comparison (
'ks3','ks4','ks5')
main/leaderboard.html template
Autumn Competition Leaderboard
Display autumn competition leaderboards by key stage with school rankings
Individual Rankings
Top 15 KS3 individual leaders with:
- User details (name, year, school)
- Current score
- School affiliation
Top 15 KS4 individual leaders
Top 15 KS5 individual leaders
School Rankings
Top 8 KS3 schools with:
id: School IDname: School nametotal_score: Sum of all student scoresparticipant_count: Number of students from schoolaverage_score: Average score per student
Top 8 KS4 schools (same structure)
Top 8 KS5 schools (same structure)
Activity Feed
Last 15 correct submissions with points awarded:
- User name
- School name
- Challenge title
- Points awarded
- Submission timestamp
Competition Statistics
Autumn competition metrics:
ks3_participants: KS3 participant countks4_participants: KS4 participant countks5_participants: KS5 participant counttotal_participants: All participantstotal_schools: Number of participating schoolstotal_submissions: All submissionscorrect_submissions: Correct submissions onlytotal_points_awarded: Sum of all pointsactive_challenges: Number of unlocked challenges
- Individual leaders from
SummerLeaderboardjoined withUserandSchool - School rankings aggregated using SQLAlchemy
func.sum(),func.count(),func.avg() - Recent activity from
SummerSubmission(whereis_correct=Trueandpoints_awarded > 0) - Key stage filtering using uppercase (
'KS3','KS4','KS5')
main/summer_leaderboard.html template
Leaderboard Update Logic
Regular Competition
Function:update_leaderboard(user_id, score, challenge_key_stage)
Updates user’s points for specific challenge key stage:
ID of the user to update
Points to add to user’s total
Key stage of completed challenge (KS3/KS4/KS5)
- Looks for existing
LeaderboardEntryfor user + key stage - If exists: Adds score to existing total
- If new: Creates entry with initial score
- Updates
last_updatedtimestamp to current time
Autumn Competition
Function:update_summer_leaderboard(user_id, school_id, points)
Updates summer leaderboard and school rankings:
ID of the user
ID of user’s school
Points to add (1 or 3)
- Finds
SummerLeaderboardentry by user + school - Adds points to existing score or creates new entry
- Updates
last_updatedtimestamp - School rankings automatically recalculated on next view
Point Distribution
Regular Challenges
- First to complete all boxes: 3 points
- Subsequent completions: 1 point
- Partial completion: 0 points (no credit until all boxes correct)
Summer Challenges
- First to complete entire challenge: 3 points
- Everyone else who completes: 1 point
- Partial answers: 0 points (encouragement message only)
Recent Activity Tracking
Both leaderboards show recent activity feed: Regular Leaderboard:- Sources from
AnswerSubmission(correct answers) - Joins with
User,ChallengeAnswerBox,Challenge - Sorted by
submitted_atdescending - Limit: 10 submissions
- Sources from
SummerSubmissionwherepoints_awarded > 0 - Joins with
User,SummerChallenge,School - Sorted by
submitted_atdescending - Limit: 15 submissions with points
Key Stage Filtering Differences
Important: Key stage filtering uses different cases:- Regular leaderboard: Lowercase (
'ks3','ks4','ks5') - Summer leaderboard: Uppercase (
'KS3','KS4','KS5')