Skip to content

Commit

Permalink
Update createcontest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ruufly authored Feb 9, 2024
1 parent 37b99d6 commit 0cc5249
Showing 1 changed file with 96 additions and 49 deletions.
145 changes: 96 additions & 49 deletions teacher/createcontest.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,141 @@
#!/usr/bin/env python

# Copyright 2023 distjr_
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pickle
import os, sys

def settime(year,month,day,hour,minute,second):
return (int(year),int(month),int(day),int(hour),int(minute),int(second))

def rule(rule): # IOI / OI
def settime(year, month, day, hour, minute, second):
try:
year = int(year)
except ValueError:
year = 0
try:
month = int(month)
except ValueError:
month = 0
try:
day = int(day)
except ValueError:
day = 0
try:
hour = int(hour)
except ValueError:
hour = 0
try:
minute = int(minute)
except ValueError:
minute = 0
try:
second = int(second)
except ValueError:
second = 0
return (int(year), int(month), int(day), int(hour), int(minute), int(second))


def rule(rule): # IOI / OI
return rule

def judgeway(way): # Full text comparison -> (FTC) / Special Judge -> (SPJ) / Submit answer questions -> (SAQ) / Interactive questions -> (IQ)

def judgeway(way):
# Full text comparison -> (FTC) / Special Judge -> (SPJ) / Submit answer questions -> (SAQ) / Interactive questions -> (IQ)
return way


class Problem(object):
def __init__(self,name,judgeway='FTC'):
def __init__(self, name, judgeway="FTC"):
self.name = name
self.timelimit = 0 # ms
self.memorylimit = 0 # MB
self.timelimit = 0 # ms
self.memorylimit = 0 # MB
self.data = {}
self.description = "暂无本题的描述"
self.judgeway = judgeway
self.spj = ""
def setproblem(self,description):

def setproblem(self, description):
self.description = description
def setdata(self,data,ans,datacode,datatime,datamemory,score):
self.data[datacode] = {'data':data,'timelimit':datatime,'memorylimit':datamemory,'ans':ans,'score':score}
self.timelimit = max(datatime,self.timelimit)
self.memorylimit = max(datamemory,self.memorylimit)

def setdata(self, data, ans, datacode, datatime, datamemory, score):
self.data[datacode] = {
"data": data,
"timelimit": datatime,
"memorylimit": datamemory,
"ans": ans,
"score": score,
}
self.timelimit = max(datatime, self.timelimit)
self.memorylimit = max(datamemory, self.memorylimit)


class Contest(object):
def __init__(self,name,starttime,endtime,rule):
def __init__(self, name, starttime, endtime, rule):
self.name = name
self.starttime = starttime
self.endtime = endtime
self.rule = rule
self.password = ""
self.problems = {}
def newproblem(self,problem : Problem,proid):

def newproblem(self, problem: Problem, proid):
self.problems[proid] = problem
def setpassword(self,password):

def setpassword(self, password):
self.password = password
def read(self,file):
f = open(file,"rb")

def read(self, file):
f = open(file, "rb")
datas = pickle.load(f)
f.close()
self.name = datas['name']
self.starttime = datas['start']
self.endtime = datas['end']
self.rule = datas['rule']
self.password = datas['password']
for i in datas['problem']:
problem = Problem(datas['problem'][i]['name'],datas['problem'][i]['judgeway'])
problem.setproblem(datas['problem'][i]['description'])
problem.timelimit = datas['problem'][i]['timelimit']
problem.memorylimit = datas['problem'][i]['memorylimit']
problem.data = datas['problem'][i]['data']
self.newproblem(problem,i)
def save(self,file):
f = open(file,"wb")
datas = {'name':self.name,
'start':self.starttime,
'end':self.endtime,
'rule':self.rule,
'password':self.password,
'problem':{}}
self.name = datas["name"]
self.starttime = datas["start"]
self.endtime = datas["end"]
self.rule = datas["rule"]
self.password = datas["password"]
for i in datas["problem"]:
problem = Problem(
datas["problem"][i]["name"], datas["problem"][i]["judgeway"]
)
problem.setproblem(datas["problem"][i]["description"])
problem.timelimit = datas["problem"][i]["timelimit"]
problem.memorylimit = datas["problem"][i]["memorylimit"]
problem.data = datas["problem"][i]["data"]
self.newproblem(problem, i)

def save(self, file):
f = open(file, "wb")
datas = {
"name": self.name,
"start": self.starttime,
"end": self.endtime,
"rule": self.rule,
"password": self.password,
"problem": {},
}
for i in self.problems:
datas['problem'][i] = {'name':self.problems[i].name,
'judgeway':self.problems[i].judgeway,
'timelimit':self.problems[i].timelimit,
'memorylimit':self.problems[i].memorylimit,
'description':self.problems[i].description,
'data':self.problems[i].data}
pickle.dump(datas,f)
datas["problem"][i] = {
"name": self.problems[i].name,
"judgeway": self.problems[i].judgeway,
"timelimit": self.problems[i].timelimit,
"memorylimit": self.problems[i].memorylimit,
"description": self.problems[i].description,
"data": self.problems[i].data,
}
pickle.dump(datas, f)
f.close()


if __name__ == "__main__":
a = Contest("1",(1,1,1,1,1,1),(1,1,1,1,1,1),'OI')
a = Contest("1", (1, 1, 1, 1, 1, 1), (1, 1, 1, 1, 1, 1), "OI")
a.save("lastcontest\\a.nfctmp")

0 comments on commit 0cc5249

Please sign in to comment.