feat: add unified contest pool and realtime game modes

This commit is contained in:
2026-08-10 00:31:21 +08:00
parent 97ca20413e
commit 40e9462842
18 changed files with 822 additions and 152 deletions
+25 -2
View File
@@ -87,6 +87,11 @@ class RealtimeMatch(models.Model):
COMPLETED = "completed", "已完成"
CANCELLED = "cancelled", "已取消"
class GameKind(models.TextChoices):
QUIZ = "quiz", "口算竞速"
SUDOKU = "sudoku", "数独 Timerun"
TWENTY_FOUR = "twenty_four", "24 点竞速"
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
contest = models.ForeignKey(Contest, on_delete=models.PROTECT)
match_type = models.CharField(
@@ -95,6 +100,11 @@ class RealtimeMatch(models.Model):
default=MatchType.RANDOM,
)
challenge_code = models.CharField(max_length=8, unique=True, null=True, blank=True)
game_kind = models.CharField(
max_length=20,
choices=GameKind.choices,
default=GameKind.QUIZ,
)
player_one = models.ForeignKey(
settings.AUTH_USER_MODEL, on_delete=models.PROTECT, related_name="matches_as_player_one"
)
@@ -126,11 +136,12 @@ class RealtimeMatch(models.Model):
fields=(
"contest",
"match_type",
"game_kind",
"status",
"player_one_rating",
"created_at",
),
name="matchmaking_lookup_idx",
name="matchmaking_mode_idx",
)
]
@@ -152,6 +163,7 @@ class ContestAttempt(models.Model):
correct_count = models.PositiveIntegerField(default=0)
answer_count = models.PositiveIntegerField(default=0)
duration_ms = models.PositiveIntegerField(default=0)
question_order = models.JSONField(default=list, blank=True)
submission_key = models.CharField(max_length=80, null=True, blank=True)
started_at = models.DateTimeField(auto_now_add=True)
submitted_at = models.DateTimeField(null=True, blank=True)
@@ -232,6 +244,13 @@ class MathGameAttempt(models.Model):
on_delete=models.CASCADE,
related_name="math_game_attempts",
)
match = models.ForeignKey(
RealtimeMatch,
null=True,
blank=True,
on_delete=models.PROTECT,
related_name="game_attempts",
)
kind = models.CharField(max_length=20, choices=Kind.choices)
difficulty = models.CharField(
max_length=16,
@@ -254,7 +273,11 @@ class MathGameAttempt(models.Model):
models.UniqueConstraint(
fields=("user", "submission_key"),
name="unique_user_math_game_submission",
)
),
models.UniqueConstraint(
fields=("match", "user"),
name="unique_user_realtime_math_game",
),
]
indexes = [
models.Index(