Skip to main content

Challenge

The Challenge model represents regular mathematical challenges. Table name: challenge

Fields

id
Integer
required
Primary key, auto-incrementing
title
String(100)
required
Challenge title (indexed)
content
Text
required
Challenge description and instructions
date_posted
DateTime
default:"datetime.datetime.now"
required
Publication timestamp (indexed)
file_url
String(100)
Optional file attachment URL
key_stage
String(3)
required
Educational key stage (indexed)
first_correct_submission
DateTime
Timestamp of first correct answer
release_at
DateTime
Scheduled release time (indexed, nullable)
is_manually_locked
Boolean
default:"false"
required
Manual lock override flag
lock_after_hours
Integer
Hours until automatic lock (nullable)

Relationships

Properties

is_locked
property
@property
def is_locked(self) -> bool
Check if challenge is locked (manually or by time)Logic:
  1. Returns True if is_manually_locked is set
  2. If lock_after_hours and release_at are set, returns True if current time exceeds release_at + lock_after_hours
  3. Otherwise returns False
Returns:
  • bool: Lock status

ChallengeAnswerBox

Represents individual answer inputs for multi-part challenges. Table name: challenge_answer_box

Fields

id
Integer
required
Primary key, auto-incrementing
challenge_id
Integer
required
Foreign key to challenge.id (indexed)
box_label
String(100)
required
Display label (e.g., “Part A”, “Step 1”)
correct_answer
String(100)
required
The correct answer value
order
Integer
required
Display order within challenge

Relationships

Indexes

  • Composite index: ix_challenge_answer_box_challenge_order on (challenge_id, order)

Methods

check_answer
method
def check_answer(self, submitted_answer: str) -> bool
Check if submitted answer is correct using mathematical expression comparison or string matchingLogic:
  1. Attempts mathematical expression comparison using compare_mathematical_expressions utility
  2. Falls back to case-insensitive string comparison if mathematical comparison fails
Parameters:
  • submitted_answer (str): User’s submitted answer
Returns:
  • bool: True if correct, False otherwise

SummerChallenge

The SummerChallenge model represents time-limited summer competition challenges. Table name: summer_challenge

Fields

id
Integer
required
Primary key, auto-incrementing
title
String(100)
required
Challenge title (indexed)
content
Text
required
Challenge description and instructions
date_posted
DateTime
default:"datetime.datetime.now"
required
Publication timestamp
duration_hours
Integer
default:"24"
required
Challenge duration in hours
file_url
String(100)
Optional file attachment URL
key_stage
String(3)
required
Educational key stage (indexed)
is_manually_locked
Boolean
default:"false"
required
Manual lock override flag
release_at
DateTime
Scheduled release time (indexed, nullable)

Relationships

Properties

is_locked
property
@property
def is_locked(self) -> bool
Check if challenge is lockedLogic:
  • Returns True if is_manually_locked is set OR current time exceeds date_posted + duration_hours
Returns:
  • bool: Lock status
lock_reason
property
@property
def lock_reason(self) -> str | None
Returns the reason why the challenge is lockedReturns:
  • "manually_locked": If is_manually_locked is True
  • "time_expired": If current time exceeds date_posted + duration_hours
  • None: If challenge is not locked

SummerChallengeAnswerBox

Represents individual answer inputs for multi-part summer challenges. Table name: summer_challenge_answer_box

Fields

id
Integer
required
Primary key, auto-incrementing
challenge_id
Integer
required
Foreign key to summer_challenge.id (indexed)
box_label
String(100)
required
Display label (e.g., “Part A”, “Question 1”)
correct_answer
String(100)
required
The correct answer value
order
Integer
required
Display order within challenge

Relationships

Indexes

  • Composite index: ix_summer_answer_box_challenge_order on (challenge_id, order)

Methods

check_answer
method
def check_answer(self, submitted_answer: str) -> bool
Check if submitted answer is correct using mathematical expression comparison or string matchingLogic:
  1. Attempts mathematical expression comparison using compare_mathematical_expressions utility
  2. Falls back to case-insensitive string comparison if mathematical comparison fails
Parameters:
  • submitted_answer (str): User’s submitted answer
Returns:
  • bool: True if correct, False otherwise

Build docs developers (and LLMs) love