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