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 deleteUser(request): username = request.POST["username"] user = User.getByName(username) user.delete() return JsonResponse("ok", safe=False)
def contestreport(request): contest = Contest.getCurrent() or Contest.getPast() user = User.getCurrent(request) 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 problemSummaryreport = [] subs = get_user_subs_map(contest) if start <= time.time() <= end: reportcols = [h.th("Rank"), h.th("Contestant"), h.th("Contestant ID"), h.th("Correct"), h.th("Penalty"), ] else: reportcols = [h.th("Rank"), h.th("Contestant ID"), h.th("Correct"), h.th("Penalty"), ] problemSummary = {} problems = [] problemNum = 0 for prob in contest.problems: problemSummary[prob.id] = [0, 0] problemNum += 1 problems.append(prob.id) problemSummaryreport.append({"id":prob.id,"title":prob.title,"attempts":0,"correct":0}) reportcols.append(h.th(f"{problemNum}", cls="center")) scores = [] for user in subs: usersubs = subs[user] scor = score(usersubs, contest, problemSummary) scores.append(( User.get(user).username, scor[0], scor[1], scor[2], scor[3], user )) scores = sorted(scores, key=lambda score: score[1] * 1000000000 + score[2] * 10000000 - score[3], reverse=True) ranks = [i + 1 for i in range(len(scores))] for i in range(1, len(scores)): u1 = scores[i] u2 = scores[i - 1] if (u1[1], u1[2], u1[3]) == (u2[1], u2[2], u2[3]): ranks[i] = ranks[i - 1] log = [] for (name, solved, samples, points, attempts, userid), rank in zip(scores, ranks): log.append({"rank": rank, "name": name, "userid": userid, "solved": solved, "points": points}) detailedContestDisplay = [] for person in log: outproblems = [] submissions = sorted(subs[person["userid"]], key=lambda sub: sub.timestamp) for p in problems: p_trys = 0 earliest_time = 0 for s in submissions: if p == s.problem.id: p_trys += 1 if s.result == "ok": earliest_time = s.timestamp break if earliest_time: outproblems.append(h.td(f"({p_trys}) {datetime.utcfromtimestamp((earliest_time - start) / 1000).strftime('%H:%M')}")) for prob in problemSummaryreport: if prob['id'] == p: prob["attempts"] += p_trys prob["correct"] += 1 prob[s.language] = prob.get(s.language, 0) + 1 elif p_trys: outproblems.append(h.td(f"({p_trys}) -- ")) for prob in problemSummaryreport: if prob['id'] == p: prob["attempts"] += p_trys else: outproblems.append(h.td(f"")) # Previous logic checked to make sure user was a valid object # before retrieving its members. That is why this code does as # well user = User.getByName(person["name"]) if user: # Set displayName to fullname if displayFullname option is true, # otherwise, use the username displayName = user.fullname if contest.displayFullname == True else user.username else: displayName = person["name"] detailedContestDisplay.append(h.tr( h.td(person["rank"]), h.td(displayName), h.td(person["name"]) if start <= time.time() <= end else "", h.td(person["solved"]), h.td(person["points"]), *outproblems )) lang_col = [h.td("#"), h.td("Title")] for lan in all_languages: lang_col.append(h.td(all_languages[lan])) lang_col.append(h.td("Total Count")) problemSummaryDisplay =[] LanguageDisplay = [] i = 0 for prob in problemSummaryreport: i += 1 problemSummaryDisplay.append(h.tr( h.td(i), h.td(prob["title"]), h.td(prob["attempts"]), h.td(prob["correct"]), )) langcount = [] total = 0 for lan in all_languages: if lan in prob: total += prob[lan] langcount.append(h.td(prob[lan])) else: langcount.append(h.td("")) LanguageDisplay.append(h.tr( h.td(i), h.td(prob["title"]), *langcount, h.td(total) if total > 0 else h.td("") )) return HttpResponse(Page( h2("DETAILED STANDINGS", cls="page-title"), h.table(cls="banded", contents=[ h.thead(h.tr(*reportcols)), h.tbody(*detailedContestDisplay) ]), h2("Problem Summary", cls="page-title"), h.table(cls="banded", contents=[ h.thead( h.tr( h.td("#"), h.td("Title"), h.td("Attempts"), h.td("Correct") ) ), h.tbody(*problemSummaryDisplay) ]), h2("Language Breakdown", cls="page-title"), h.table(cls="banded", contents=[ h.thead(h.tr(*lang_col) ),h.tbody(*LanguageDisplay) ]), cls='wide-content' # Use a wide format for this page ))
It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ """ import os from django.core.wsgi import get_wsgi_application from contest.auth import generatePassword from contest.models.user import User os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'opencontest.settings') user = '******' usr = User.getByName(user) if usr: password = usr.password else: password = generatePassword() usr = User(user, 'Administrator', password, 'admin') usr.save() print(f'Admin username is "{user}".') print(f'Admin password is "{password}".') print('Starting server...') application = get_wsgi_application()