if user.isAdmin(): filter = div( a(href='inbox', contents="Inbox "), a(href='processed', contents="Handled "), a(href='announcements', contents="Announcements"), ) else: filter = div() return Page( h2("Messages", cls="page-title"), div(cls="actions", contents=[ h.button("+ Send Message", cls="button create-message", onclick="createMessage()") ]), filter, Modal( "Send Message", div( *adminDetails, h.textarea(cls="message col-12") ), div( h.button("Cancel", **{"type":"button", "class": "button button-white", "data-dismiss": "modal"}), h.button("Send", **{"type":"button", "class": "button", "onclick": "sendMessage()"}) ) ), div(cls="message-cards", contents=messages), ) register.web("/messages/([a-z]+)", "loggedin", getMessages)
def listProblems(params, user): if Contest.getCurrent(): contest = Contest.getCurrent() probCards = [] for prob in contest.problems: probCards.append( Card(prob.title, prob.description, f"/problems/{prob.id}", None, None, None, user, prob.id)) if user.isAdmin(): probCards.append(h.span(" ")) probCards.append( h.button("Rejudge All", type="button", id=f"rejudgeAll{prob.id}", onclick=f"rejudgeAll('{prob.id}')", cls="btn btn-primary")) probCards.append(h.br()) probCards.append(h.br()) return Page(h2("Problems", cls="page-title"), *probCards) elif Contest.getFuture(): contest = Contest.getFuture() return Page(h1(" "), h1("Contest Starts in", cls="center"), h1(contest.start, cls="countdown jumbotron center")) elif Contest.getPast(): return Page(h1(" "), h1("Contest is Over", cls="center")) return Page(h1(" "), h1("No Contest Created", cls="center")) register.web("/problems$", "loggedin", listProblems) register.web("/problems/([0-9a-f-]+)", "loggedin", viewProblem)
else: sampleSolved = True if sub.result != "ok": # Unsuccessful submissions count for 20 penalty points # But only if the problem is eventually solved points += 20 else: # The first successful submission adds a penalty point for each # minute since the beginning of the contest # The timestamp is in millis points += (sub.timestamp - contestStart) // 60000 solved = True break # Increment attempts problemSummary[sub.problem.id][0] += 1 # A problem affects the score only if it was successfully solved if solved: solvedProbs += 1 penPoints += points problemSummary[sub.problem.id][1] += 1 elif sampleSolved: sampleProbs += 1 # The user's score is dependent on the number of solved problems and the number of penalty points return solvedProbs, sampleProbs, int(penPoints) register.web("/detailedReport", "loggedin", detailedReport)
probName = submission.problem.title cls = "red" if submission.result != "ok" else "" self.html = Card("Submission to {} at <span class='time-format'>{}</span>".format(probName, subTime), [ h.strong("Language: <span class='language-format'>{}</span>".format(submission.language)), h.br(), h.strong("Result: <span class='result-format'>{}</span>".format(submission.result)), h.br(), h.br(), h.strong("Code:"), h.code(submission.code.replace("\n", "<br/>").replace(" ", " ")) ], cls=cls) def getSubmissions(params, user): submissions = [] cont = Contest.getCurrent() if not cont: return "" Submission.forEach(lambda x: submissions.append(x) if x.user.id == user.id and cont.start <= x.timestamp <= cont.end else None) if len(submissions) == 0: return Page( h2("No Submissions Yet", cls="page-title"), ) return Page( h2("Your Submissions", cls="page-title"), *map(SubmissionDisplay, submissions) ) register.web("/submissions", "loggedin", getSubmissions)
userLists = [] tmp = [] for user in User.all(): tmp.append(user) if len(tmp) == 16: userLists.append(tmp) tmp = [] if tmp != []: userLists.append(tmp) users = [] for lst in userLists: users.append(div(*map(UserCard, lst), cls="page-break row")) return Page( h2("Users", cls="page-title"), div(cls="actions", contents=[ h.button("+ Create Admin", cls="button button-blue create-admin", onclick="createUser('admin')"), h.button("+ Create Participant", cls="button create-participant", onclick="createUser('participant')") ]), div(cls="user-cards", contents=users)) register.web("/users", "admin", getUsers)
for sub in subs: for res in sub.results[:sub.problem.samples]: if res != "ok": break else: sampleSolved = True if sub.result != "ok": # Unsuccessful submissions count for 20 penalty points # But only if the problem is eventually solved points += 20 else: # The first successful submission adds a penalty point for each # minute since the beginning of the contest # The timestamp is in millis points += (sub.timestamp - contestStart) // 60000 solved = True break # A problem affects the score only if it was successfully solved if solved: solvedProbs += 1 penPoints += points elif sampleSolved: sampleProbs += 1 # The user's score is dependent on the number of solved problems and the number of penalty points return solvedProbs, sampleProbs, int(penPoints) register.web("/leaderboard", "loggedin", leaderboard)
break else: sampleSolved = True if sub.result != "ok": # Unsuccessful submissions count for 20 penalty points # But only if the problem is eventually solved points += 20 else: # The first successful submission adds a penalty point for each # minute since the beginning of the contest # The timestamp is in millis points += (sub.timestamp - contestStart) // 60000 solved = True break # Increment attempts problemSummary[sub.problem.id][0] += 1 # A problem affects the score only if it was successfully solved if solved: solvedProbs += 1 penPoints += points problemSummary[sub.problem.id][1] += 1 elif sampleSolved: sampleProbs += 1 # The user's score is dependent on the number of solved problems and the number of penalty points return solvedProbs, sampleProbs, int(penPoints) register.web("/leaderboard", "loggedin", leaderboard)
*map(lambda sub: SubmissionRow(sub), subs) ), id="submissions" ) def judge(params, user): cont = Contest.getCurrent() if not cont: return Page( h1(" "), h1("No Contest Available", cls="center") ) return Page( h2("Judge Submissions", cls="page-title"), div(id="judge-table", contents=[ SubmissionTable(cont) ]), div(cls="modal", tabindex="-1", role="dialog", contents=[ div(cls="modal-dialog", role="document", contents=[ div(id="modal-content") ]) ]) ) def judge_submission(params, user): return SubmissionCard(Submission.get(params[0])) register.web("/judgeSubmission/([a-zA-Z0-9-]*)", "admin", judge_submission) register.web("/judge", "admin", judge)
usersubs = submissions[user] # Put the submissions into the probs list for sub in usersubs: if all(i == "ok" for i in sub.results): foundMatch = False for (j, k, l, m) in log: if k == User.get( user ).username and m == sub.problem.id and j < sub.timestamp: foundMatch = True break elif k == User.get( user ).username and m == sub.problem.id and j > sub.timestamp: foundMatch = False log.remove((j, k, l, m)) break if not foundMatch: temp = (sub.timestamp, User.get(user).username, sub.problem.title, sub.problem.id) log.append(temp) log.sort(key=operator.itemgetter(0), reverse=True) print(log) return log register.web("/correctLog", "loggedin", correctLog)
cont = Contest.getCurrent() if not cont: return "" Submission.forEach(lambda x: submissions.append(x) if x.user.id == user.id and cont.start <= x.timestamp <= cont.end else None) if len(submissions) == 0: return Page(h2("No Submissions Yet", cls="page-title"), ) return Page( h2("Your Submissions", cls="page-title"), SubmissionTable( sorted(submissions, key=lambda sub: (sub.problem.title, -sub.timestamp))), div(cls="modal", tabindex="-1", role="dialog", contents=[ div(cls="modal-dialog", role="document", contents=[div(id="modal-content")]) ])) def contestant_submission(params, user): return SubmissionCard(Submission.get(params[0])) register.web("/submissions", "loggedin", getSubmissions) register.web("/contestantSubmission/([a-zA-Z0-9-]*)", "loggedin", contestant_submission)
("On", "Off"), (True, False)) ] ]) ]), div(cls="form-group col-6", contents=[ h.label( **{ "for": "scoreboard-off-time", "contents": "Turn Scoreboard Off Time" }), h.input(cls="form-control", name="scoreboard-off-time", id="scoreboard-off-time", type="time") ]) ]), div(cls="align-right col-12", contents=[ h.button("Save", cls="button", onclick="editContest()") ]) ])), *existingProblems) register.web("/contests$", "admin", listContests) register.web("/contests/([a-f0-9-]*)", "admin", editContest) register.web("/contests/new", "admin", editContest)
return Page( h2("Messages", cls="page-title"), div(cls="actions", contents=[ h.button("+ Send Message", cls="button create-message", onclick="createMessage()") ]), filter, Modal( "Send Message", div(*adminDetails, h.textarea(cls="message col-12")), div( h.button( "Cancel", **{ "type": "button", "class": "button button-white", "data-dismiss": "modal" }), h.button( "Send", **{ "type": "button", "class": "button", "onclick": "sendMessage()" }))), div(cls="message-cards", contents=messages), ) register.web("/messages/([a-z]+)", "loggedin", getMessages)
h.tr(h.th("Name"), h.th("Problem"), h.th("Time"), h.th("Language"), h.th("Result"))), h.tbody(*map(lambda sub: SubmissionRow(sub), subs)), id="submissions") def judge(params, user): cont = Contest.getCurrent() if not cont: return Page(h1(" "), h1("No Contest Available", cls="center")) return Page( h2("Judge Submissions", cls="page-title"), div(id="judge-table", contents=[SubmissionTable(cont)]), div(cls="modal", tabindex="-1", role="dialog", contents=[ div(cls="modal-dialog", role="document", contents=[div(id="modal-content")]) ])) def judge_submission(params, user): return SubmissionCard(Submission.get(params[0])) register.web("/judgeSubmission/([a-zA-Z0-9-]*)", "admin", judge_submission) register.web("/judge", "admin", judge)
div(cls="form-group col-6", contents=[ h.label(**{"for": "contest-start-time", "contents":"Start Time"}), h.input(cls="form-control", name="contest-start-time", id="contest-start-time", type="time") ]), h.input(type="hidden", id="end", value=end), div(cls="form-group col-6", contents=[ h.label(**{"for": "contest-end-date", "contents":"End Date"}), h.input(cls="form-control", name="contest-end-date", id="contest-end-date", type="date") ]), div(cls="form-group col-6", contents=[ h.label(**{"for": "contest-end-time", "contents":"End Time"}), h.input(cls="form-control", name="contest-end-time", id="contest-end-time", type="time") ]), h.input(type="hidden", id="scoreboardOff", value=scoreboardOff), div(cls="form-group col-6"), div(cls="form-group col-6", contents=[ h.label(**{"for": "scoreboard-off-time", "contents":"Turn Scoreboard Off Time"}), h.input(cls="form-control", name="scoreboard-off-time", id="scoreboard-off-time", type="time") ]) ]), div(cls="align-right col-12", contents=[ h.button("Save", cls="button", onclick="editContest()") ]) ])), *existingProblems ) register.web("/contests$", "admin", listContests) register.web("/contests/([a-f0-9-]*)", "admin", editContest) register.web("/contests/new", "admin", editContest)
]), div(cls="form-group col-12 rich-text", contents=[ h.label(**{"for": "problem-statement", "contents":"Problem Statement"}), h.textarea(cls="form-control", name="problem-statement", id="problem-statement", contents="Problem Statement") ]), div(cls="form-group col-12 rich-text", contents=[ h.label(**{"for": "problem-input", "contents":"Input Format"}), h.textarea(cls="form-control", name="problem-input", id="problem-input", contents="Input Format") ]), div(cls="form-group col-12 rich-text", contents=[ h.label(**{"for": "problem-output", "contents":"Output Format"}), h.textarea(cls="form-control", name="problem-output", id="problem-output", contents="Output Format") ]), div(cls="form-group col-12 rich-text", contents=[ h.label(**{"for": "problem-constraints", "contents":"Constraints"}), h.textarea(cls="form-control", name="problem-constraints", id="problem-constraints", contents="Input Constraints") ]), div(cls="form-group col-12", contents=[ h.input(cls="form-control", type="hidden", name="problem-samples", id="problem-samples", value=0) ]), ]), div(cls="align-right col-12", contents=[ h.button("Save", cls="button", onclick="editProblem()") ]) ])) ) register.web("/problems_mgmt", "admin", listProblems) register.web("/problems/([0-9a-f-]+)/edit", "admin", editProblem) register.web("/problems/new", "admin", newProblem)
h.br(), h.strong( "Result: <span class='result-format'>{}</span>".format( submission.result)), h.br(), h.br(), h.strong("Code:"), h.code( submission.code.replace("\n", "<br/>").replace( " ", " ")) ], cls=cls) def getSubmissions(params, user): submissions = [] cont = Contest.getCurrent() if not cont: return "" Submission.forEach(lambda x: submissions.append(x) if x.user.id == user.id and cont.start <= x.timestamp <= cont.end else None) if len(submissions) == 0: return Page(h2("No Submissions Yet", cls="page-title"), ) return Page(h2("Your Submissions", cls="page-title"), *map(SubmissionDisplay, submissions)) register.web("/submissions", "loggedin", getSubmissions)
]), div(cls="form-group col-12", contents=[ h.input(cls="form-control", type="hidden", name="problem-time-limit", id="problem-time-limit", value=5) ]), div(cls="form-group col-12", contents=[ h.input(cls="form-control", type="hidden", name="problem-samples", id="problem-samples", value=0) ]), ]), div(cls="align-right col-12", contents=[ h.button("Save", cls="button", onclick="editProblem()") ]) ]))) register.web("/problems_mgmt", "admin", listProblems) register.web("/problems/([0-9a-f-]+)/edit", "admin", editProblem) register.web("/problems/new", "admin", newProblem)
div(cls="modal", tabindex="-1", role="dialog", contents=[ div(cls="modal-dialog", role="document", contents=[div(id="modal-content")]) ])) def judge_submission(params, user): submission = Submission.get(params[0]) force = params[1] == "force" if submission.checkout is not None and not force: return f"CONFLICT:{User.get(submission.checkout).username}" return SubmissionCard(submission, user, force) def judge_submission_close(params, setHeader, user): submission = Submission.get(params["id"]) if submission.version == int(params["version"]): submission.checkout = None submission.save() return "ok" register.web("/judgeSubmission/([a-zA-Z0-9-]*)(?:/(force))?", "admin", judge_submission) register.post("/judgeSubmissionClose", "admin", judge_submission_close) register.web("/judge", "admin", judge)
probCards = [] for prob in contest.problems: probCards.append(Card( prob.title, prob.description, f"/problems/{prob.id}" )) return Page( h2("Problems", cls="page-title"), *probCards ) elif Contest.getFuture(): contest = Contest.getFuture() return Page( h1(" "), h1("Contest Starts in", cls="center"), h1(contest.start, cls="countdown jumbotron center") ) elif Contest.getPast(): return Page( h1(" "), h1("Contest is Over", cls="center") ) return Page( h1(" "), h1("No Contest Created", cls="center") ) register.web("/problems$", "loggedin", listProblems) register.web("/problems/([0-9a-f-]+)", "loggedin", viewProblem)
from code.generator.lib.htmllib import * from code.generator.lib.page import * from code.util.db.simple import * from code.util import register register.web("/login", "any", lambda params, user: Page( div(cls="login-box", contents=[ h2("Login", cls="login-header"), h.label("Username", cls="form-label"), h.input(name="username", cls="form-control"), h.label("Password", cls="form-label"), h.input(name="password", cls="form-control", type="password"), div(cls="align-right", contents=[ h.button("Login", cls="button login-button") ]) ]) )) register.web("/setup", "admin", lambda params, user: Page( h2("Setup", cls="page-title"), Card("Problems", "Create problems to go in the contests", "/problems_mgmt"), Card("Contests", "Create contests", "/contests"), Card("Users", "Create users who will participate in contests, as well as other admin users who can create and judge contests and problems", "/users") )) class FAQ(UIElement): def __init__(self, q, a): id = str(uuid()) self.html = div( h.h4(q, cls="qa-question collapsed", **{"data-toggle": "collapse", "data-target": f"#qa-{id}"}),