2016-09-25 17:00:52 +08:00
|
|
|
from django.db import models
|
2017-10-11 21:43:29 +08:00
|
|
|
from utils.models import JSONField
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
from account.models import User
|
2017-02-17 20:14:03 +08:00
|
|
|
from contest.models import Contest
|
2016-09-25 17:00:52 +08:00
|
|
|
from utils.models import RichTextField
|
2017-12-03 18:52:32 +08:00
|
|
|
from utils.constants import Choices
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
class ProblemTag(models.Model):
|
2018-05-01 12:54:27 +08:00
|
|
|
name = models.TextField()
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "problem_tag"
|
|
|
|
|
|
|
|
|
2017-12-03 18:52:32 +08:00
|
|
|
class ProblemRuleType(Choices):
|
2017-02-02 16:59:15 +08:00
|
|
|
ACM = "ACM"
|
|
|
|
OI = "OI"
|
|
|
|
|
|
|
|
|
2017-05-01 13:03:48 +08:00
|
|
|
class ProblemDifficulty(object):
|
|
|
|
High = "High"
|
|
|
|
Mid = "Mid"
|
|
|
|
Low = "Low"
|
|
|
|
|
|
|
|
|
2019-03-12 16:10:21 +08:00
|
|
|
class ProblemIOMode(Choices):
|
|
|
|
standard = "Standard IO"
|
|
|
|
file = "File IO"
|
|
|
|
|
|
|
|
|
|
|
|
def _default_io_mode():
|
|
|
|
return {"io_mode": ProblemIOMode.standard, "input": "input.txt", "output": "output.txt"}
|
|
|
|
|
|
|
|
|
2017-09-24 09:48:17 +08:00
|
|
|
class Problem(models.Model):
|
|
|
|
# display ID
|
2018-05-01 12:54:27 +08:00
|
|
|
_id = models.TextField(db_index=True)
|
2019-03-11 11:25:10 +08:00
|
|
|
contest = models.ForeignKey(Contest, null=True, on_delete=models.CASCADE)
|
2017-09-24 09:48:17 +08:00
|
|
|
# for contest problem
|
|
|
|
is_public = models.BooleanField(default=False)
|
2018-05-01 12:54:27 +08:00
|
|
|
title = models.TextField()
|
2016-09-25 17:00:52 +08:00
|
|
|
# HTML
|
|
|
|
description = RichTextField()
|
2017-02-02 16:59:15 +08:00
|
|
|
input_description = RichTextField()
|
|
|
|
output_description = RichTextField()
|
2016-09-25 17:00:52 +08:00
|
|
|
# [{input: "test", output: "123"}, {input: "test123", output: "456"}]
|
2017-02-02 16:59:15 +08:00
|
|
|
samples = JSONField()
|
2018-05-01 12:54:27 +08:00
|
|
|
test_case_id = models.TextField()
|
2017-09-24 09:48:17 +08:00
|
|
|
# [{"input_name": "1.in", "output_name": "1.out", "score": 0}]
|
2017-02-02 16:59:15 +08:00
|
|
|
test_case_score = JSONField()
|
2018-05-01 12:54:27 +08:00
|
|
|
hint = RichTextField(null=True)
|
2017-02-02 16:59:15 +08:00
|
|
|
languages = JSONField()
|
2017-02-06 15:46:17 +08:00
|
|
|
template = JSONField()
|
2016-09-25 17:00:52 +08:00
|
|
|
create_time = models.DateTimeField(auto_now_add=True)
|
|
|
|
# we can not use auto_now here
|
2018-05-01 12:54:27 +08:00
|
|
|
last_update_time = models.DateTimeField(null=True)
|
2019-03-11 11:25:10 +08:00
|
|
|
created_by = models.ForeignKey(User, on_delete=models.CASCADE)
|
2016-09-25 17:00:52 +08:00
|
|
|
# ms
|
|
|
|
time_limit = models.IntegerField()
|
|
|
|
# MB
|
|
|
|
memory_limit = models.IntegerField()
|
2019-03-12 16:10:21 +08:00
|
|
|
# io mode
|
|
|
|
io_mode = JSONField(default=_default_io_mode)
|
2016-09-25 17:00:52 +08:00
|
|
|
# special judge related
|
|
|
|
spj = models.BooleanField(default=False)
|
2018-05-01 12:54:27 +08:00
|
|
|
spj_language = models.TextField(null=True)
|
|
|
|
spj_code = models.TextField(null=True)
|
|
|
|
spj_version = models.TextField(null=True)
|
2017-11-16 22:12:17 +08:00
|
|
|
spj_compile_ok = models.BooleanField(default=False)
|
2018-05-01 12:54:27 +08:00
|
|
|
rule_type = models.TextField()
|
2016-09-25 17:00:52 +08:00
|
|
|
visible = models.BooleanField(default=True)
|
2018-05-01 12:54:27 +08:00
|
|
|
difficulty = models.TextField()
|
2017-02-02 16:59:15 +08:00
|
|
|
tags = models.ManyToManyField(ProblemTag)
|
2018-05-01 12:54:27 +08:00
|
|
|
source = models.TextField(null=True)
|
2017-09-24 09:48:17 +08:00
|
|
|
# for OI mode
|
2018-05-01 12:54:27 +08:00
|
|
|
total_score = models.IntegerField(default=0)
|
2017-08-26 08:41:29 +08:00
|
|
|
submission_number = models.BigIntegerField(default=0)
|
|
|
|
accepted_number = models.BigIntegerField(default=0)
|
2017-10-15 18:36:55 +08:00
|
|
|
# {JudgeStatus.ACCEPTED: 3, JudgeStaus.WRONG_ANSWER: 11}, the number means count
|
2017-10-11 21:43:29 +08:00
|
|
|
statistic_info = JSONField(default=dict)
|
2019-03-13 17:57:41 +08:00
|
|
|
share_submission = models.BooleanField(default=False)
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
db_table = "problem"
|
2017-09-24 09:48:17 +08:00
|
|
|
unique_together = (("_id", "contest"),)
|
2017-10-21 20:39:39 +08:00
|
|
|
ordering = ("create_time",)
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
def add_submission_number(self):
|
2017-08-26 08:41:29 +08:00
|
|
|
self.submission_number = models.F("submission_number") + 1
|
|
|
|
self.save(update_fields=["submission_number"])
|
2016-09-25 17:00:52 +08:00
|
|
|
|
|
|
|
def add_ac_number(self):
|
2017-08-26 08:41:29 +08:00
|
|
|
self.accepted_number = models.F("accepted_number") + 1
|
|
|
|
self.save(update_fields=["accepted_number"])
|