OnlineJudge/problem/models.py

84 lines
2.8 KiB
Python
Raw Normal View History

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
class ProblemTag(models.Model):
name = models.CharField(max_length=30)
class Meta:
db_table = "problem_tag"
2017-02-02 08:59:15 +00:00
class ProblemRuleType(object):
ACM = "ACM"
OI = "OI"
class ProblemDifficulty(object):
High = "High"
Mid = "Mid"
Low = "Low"
2017-09-24 01:48:17 +00:00
class Problem(models.Model):
# display ID
_id = models.CharField(max_length=24, db_index=True)
contest = models.ForeignKey(Contest, null=True, blank=True)
# for contest problem
is_public = models.BooleanField(default=False)
2017-02-02 08:59:15 +00:00
title = models.CharField(max_length=128)
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()
test_case_id = models.CharField(max_length=32)
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()
2016-09-25 09:00:52 +00:00
hint = RichTextField(blank=True, 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
last_update_time = models.DateTimeField(blank=True, null=True)
created_by = models.ForeignKey(User)
# ms
time_limit = models.IntegerField()
# MB
memory_limit = models.IntegerField()
# special judge related
spj = models.BooleanField(default=False)
2017-02-02 08:59:15 +00:00
spj_language = models.CharField(max_length=32, blank=True, null=True)
2016-09-25 09:00:52 +00:00
spj_code = models.TextField(blank=True, null=True)
spj_version = models.CharField(max_length=32, blank=True, null=True)
2017-11-16 14:12:17 +00:00
spj_compile_ok = models.BooleanField(default=False)
2017-02-02 08:59:15 +00:00
rule_type = models.CharField(max_length=32)
2016-09-25 09:00:52 +00:00
visible = models.BooleanField(default=True)
2017-02-02 08:59:15 +00:00
difficulty = models.CharField(max_length=32)
tags = models.ManyToManyField(ProblemTag)
source = models.CharField(max_length=200, blank=True, null=True)
2017-09-24 01:48:17 +00:00
# for OI mode
total_score = models.IntegerField(default=0, blank=True)
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)
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):
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):
self.accepted_number = models.F("accepted_number") + 1
self.save(update_fields=["accepted_number"])