def __init__(self, id=None): if id != None: details = getKey(f"/submissions/{id}/submission.json") self.id = details["id"] self.user = User.get(details["user"]) or User.getByName(details["user"]) # Ensures backward compatibility with older db's self.problem = Problem.get(details["problem"]) self.timestamp = int(details["timestamp"]) self.language = details["language"] self.code = details["code"] self.type = details["type"] self.results = details["results"] self.result = details["result"] self.status = details.get("status", None) self.checkout = None # On server restart, all judges lose their checkouts self.version = 0 else: self.id = None self.user = None # Instance of User self.problem = None # Instance of Problem self.timestamp = 0 # Time of submission (in milliseconds from time.time() * 1000) self.language = None self.code = None # Source code self.type = None self.results = [] # One result for each test case self.result = None # Overall result self.status = None # One of Submission.STATUS_REVIEW, Submission.STATUS_JUDGED self.checkout = None # id of judge that has submission checked out self.version = 1 # Version number for judge changes to this record self.inputs = [] # For display only self.outputs = [] # For display only self.errors = [] # For display only self.answers = [] # For display only self.compile = None # Compile error
def __init__(self, id=None): if id != None: details = getKey(f"/contests/{id}/contest.json") self.id = details["id"] self.name = details["name"] self.start = int(details["start"]) self.end = int(details["end"]) self.scoreboardOff = int(details.get("scoreboardOff", self.end)) self.showProblInfoBlocks = details.get("showProblInfoBlocks", "Off") self.problems = [Problem.get(id) for id in details["problems"]] self.tieBreaker = str(details.get( "tieBreaker", "")).lower() == "true" # True = sample correct breaks ties self.displayFullname = str(details.get( "displayFullname", "")).lower( ) == "true" # True = full names displayed in reports else: self.id = None self.name = None self.start = None # timestamp in milliseconds from time.time() * 1000 self.end = None self.scoreboardOff = None self.showProblInfoBlocks = None self.problems = None self.tieBreaker = False self.displayFullname = False
def viewProblem(request, *args, **kwargs): problem = Problem.get(kwargs.get('id')) user = User.getCurrent(request) contest = Contest.getCurrent() if not problem: return JsonResponse(data='', safe=False) if not user.isAdmin(): # Hide the problems till the contest begins for non-admin users if not Contest.getCurrent(): return JsonResponse(data='', safe=False) if problem not in Contest.getCurrent().problems: return JsonResponse(data='', safe=False) contents = [] if contest == None or contest.showProblInfoBlocks == "On": contents = [ Card("Problem Statement", formatMD(problem.statement), cls="stmt"), Card("Input Format", formatMD(problem.input), cls="inp"), Card("Output Format", formatMD(problem.output), cls="outp"), Card("Constraints", formatMD(problem.constraints), cls="constraints"), ] contents.append( div(cls="samples", contents=list( map(lambda x: getSample(x[0], x[1]), zip(problem.sampleData, range(problem.samples)))))) return HttpResponse( Page( h.input(type="hidden", id="problem-id", value=problem.id), h2(problem.title, cls="page-title"), div(cls="problem-description", contents=contents), CodeEditor(), div(cls="stmt card ui-sortable-handle blk-custom-input", contents=[ div(cls="card-header", contents=[h2("Custom Input", cls="card-title")]), div(cls="card-contents", contents=[h.textarea(id="custom-input", cls="col-12")]) ]), div(cls="align-right", id="custom-code-text", contents=[ h.input("Custom Input", type="checkbox", id="use-custom-input"), h.button("Test Code", cls="button test-samples button-white"), h.button("Submit Code", cls="button submit-problem") ])))
def generateLogReport(request): user = User.getCurrent(request) contest = Contest.getCurrent() or Contest.getPast() if not contest: return HttpResponse( Page(h1(" "), h1("No Contest Available", cls="center"))) elif contest.isScoreboardOff(user): return HttpResponse( Page(h1(" "), h1("Scoreboard is off.", cls="center"))) start = contest.start end = contest.end users = {} for sub in Submission.all(): if start <= sub.timestamp <= end and not sub.user.isAdmin( ) and sub.result == "ok": username = User.get(sub.user.id).username problemName = Problem.get(sub.problem.id).title if username not in users.keys(): users[username] = {} if problemName not in users[username].keys(): users[username][problemName] = sub if sub.timestamp < users[username][problemName].timestamp: users[username][problemName] = sub correctSubmissions = [] for user in users.keys(): for problem in users[user].keys(): correctSubmissions.append( (user, problem, users[user][problem].timestamp)) correctSubmissions.sort(key=lambda entry: entry[2]) tableRows = constructTableRows(correctSubmissions) return HttpResponse( Page( h2("Correct Submissions Log", cls="page-title"), h.table( h.thead( h.tr( h.th("Contestant Name"), h.th("Problem title"), h.th("Time"), )), h.tbody(*tableRows))))
def addSubmission(probId, lang, code, user, type, custominput): sub = Submission() sub.problem = Problem.get(probId) sub.language = lang sub.code = code sub.result = Submission.RESULT_PENDING sub.custominput = custominput sub.user = user sub.timestamp = time.time() * 1000 sub.type = type sub.status = Submission.STATUS_REVIEW if type == Submission.TYPE_SUBMIT: sub.save() else: sub.id = str(uuid4()) return sub
def systemStatus(request): contestName = Contest.getCurrent().name if Contest.getCurrent() else "None" submissionsTesting = OC_MAX_CONCURRENT_SUBMISSIONS - Submission.runningSubmissions._value if Status.instance().isRejudgeInProgress(): progress = Status.instance().rejudgeProgress problem = Problem.get(progress[0]) rejudgeProgress = f"Rejudged {progress[1]} of {progress[2]} submissions of {problem.title}" else: rejudgeProgress = "none" return HttpResponse( Page( h2("System Status", cls="page-title"), h.table( h.tr(h.th("Current contest:"), h.td(contestName)), h.tr(h.th("Submissions testing:"), h.td(submissionsTesting)), h.tr(h.th("Rejudge progress:"), h.td(rejudgeProgress)), )))
def createProblem(request): id = request.POST.get("id") problem = Problem.get(id) or Problem() problem.title = request.POST["title"] problem.description = request.POST["description"] problem.statement = request.POST["statement"] problem.input = request.POST["input"] problem.output = request.POST["output"] problem.constraints = request.POST["constraints"] problem.samples = int(request.POST["samples"]) testData = json.loads(request.POST["testData"]) logger.debug('testData: %s', repr(testData)) problem.testData = [Datum(d["input"], d["output"]) for d in testData] problem.tests = len(testData) problem.timelimit = request.POST["timelimit"] problem.save() return JsonResponse(problem.id, safe=False)
def createContest(request): """POSTing a freshly-created contest redirects here courtesy of script.js.""" id = request.POST.get("id") contest = Contest.get(id) or Contest() contest.name = request.POST.get("name") contest.start = int(request.POST.get("start")) contest.end = int(request.POST.get("end")) contest.scoreboardOff = int(request.POST.get("scoreboardOff")) contest.showProblInfoBlocks = request.POST.get("showProblInfoBlocks") contest.problems = [Problem.get(id) for id in json.loads(request.POST.get("problems"))] if str(request.POST.get("tieBreaker")).lower() == "true": contest.tieBreaker = True else: contest.tieBreaker = False # True if "displayFullname" == "true" contest.displayFullname = str(request.POST.get("displayFullname")).lower() == "true" contest.save() return JsonResponse(contest.id, safe=False)
def deleteProblem(request): id = request.POST["id"] Problem.get(id).delete() return JsonResponse("ok", safe=False)