feat: add math engine and puzzle services
This commit is contained in:
@@ -192,3 +192,57 @@ class CheatFlag(models.Model):
|
||||
evidence = models.JSONField(default=dict)
|
||||
status = models.CharField(max_length=16, choices=Status.choices, default=Status.OPEN)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
||||
|
||||
class MathGameAttempt(models.Model):
|
||||
class Kind(models.TextChoices):
|
||||
SUDOKU = "sudoku", "数独"
|
||||
TWENTY_FOUR = "twenty_four", "24 点"
|
||||
|
||||
class Difficulty(models.TextChoices):
|
||||
EASY = "easy", "入门"
|
||||
STANDARD = "standard", "标准"
|
||||
HARD = "hard", "进阶"
|
||||
|
||||
class Status(models.TextChoices):
|
||||
ACTIVE = "active", "进行中"
|
||||
COMPLETED = "completed", "已完成"
|
||||
FAILED = "failed", "未通过"
|
||||
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
user = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
on_delete=models.CASCADE,
|
||||
related_name="math_game_attempts",
|
||||
)
|
||||
kind = models.CharField(max_length=20, choices=Kind.choices)
|
||||
difficulty = models.CharField(
|
||||
max_length=16,
|
||||
choices=Difficulty.choices,
|
||||
default=Difficulty.STANDARD,
|
||||
)
|
||||
puzzle = models.JSONField(default=dict)
|
||||
solution = models.JSONField(default=dict)
|
||||
submission = models.JSONField(default=dict, blank=True)
|
||||
status = models.CharField(max_length=16, choices=Status.choices, default=Status.ACTIVE)
|
||||
score = models.PositiveIntegerField(default=0)
|
||||
duration_ms = models.PositiveIntegerField(default=0)
|
||||
hints_used = models.PositiveSmallIntegerField(default=0)
|
||||
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)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=("user", "submission_key"),
|
||||
name="unique_user_math_game_submission",
|
||||
)
|
||||
]
|
||||
indexes = [
|
||||
models.Index(
|
||||
fields=("kind", "status", "-score", "duration_ms"),
|
||||
name="math_game_ranking_idx",
|
||||
)
|
||||
]
|
||||
ordering = ["-started_at"]
|
||||
|
||||
Reference in New Issue
Block a user