Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
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)
Пример #4
0
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")
                ])))
Пример #5
0
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))))
Пример #6
0
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
Пример #7
0
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)),
            )))
Пример #8
0
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)
Пример #9
0
def deleteProblem(request):
    id = request.POST["id"]
    Problem.get(id).delete()
    return JsonResponse("ok", safe=False)
Пример #10
0
def editContest(request, *args, **kwargs):
    id = kwargs.get('id')
    contest = Contest.get(id)

    title = "New Contest"
    chooseProblem = ""
    existingProblems = []
    start = time.time() * 1000
    end = (time.time() + 3600) * 1000
    scoreboardOff = end
    displayFullname = False
    showProblInfoBlocks = ""

    showProblInfoBlocks_option = [
        h.option("On", value="On"),
        h.option("Off", value="Off")
    ]

    tieBreaker = False
    if contest:
        title = contest.name
        start = contest.start
        end = contest.end
        scoreboardOff = contest.scoreboardOff

        displayFullname = contest.displayFullname

        showProblInfoBlocks = contest.showProblInfoBlocks
        if showProblInfoBlocks == "Off":
            showProblInfoBlocks_option = [
                h.option("Off", value="Off"),
                h.option("On", value="On")
            ]
        tieBreaker = contest.tieBreaker

        chooseProblem = div(cls="actions",
                            contents=[
                                h.button("+ Choose Problem",
                                         cls="button",
                                         onclick="chooseProblemDialog()")
                            ])

        problems = [ProblemCard(prob) for prob in contest.problems]
        problemOptions = [
            h.option(prob.title, value=prob.id) for prob in Problem.all()
            if prob not in contest.problems
        ]

        existingProblems = [
            Modal(
                "Choose Problem",
                h.select(cls="form-control problem-choice",
                         contents=[h.option("-"), *problemOptions]),
                div(
                    h.button(
                        "Cancel", **{
                            "type": "button",
                            "class": "button button-white",
                            "data-dismiss": "modal"
                        }),
                    h.button(
                        "Add Problem", **{
                            "type": "button",
                            "class": "button",
                            "onclick": "chooseProblem()"
                        }))),
            div(cls="problem-cards", contents=problems)
        ]

    return HttpResponse(
        Page(
            h.input(type="hidden", id="contest-id", value=id),
            h.input(type="hidden", id="pageId", value="Contest"),
            h2(title, cls="page-title"),
            chooseProblem,
            Card(
                "Contest Details",
                div(
                    cls="contest-details",
                    contents=[
                        h.form(
                            cls="row",
                            contents=[
                                div(cls="form-group col-12",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-name",
                                                "contents": "Name"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-name",
                                                id="contest-name",
                                                value=title)
                                    ]),
                                h.input(type="hidden", id="start",
                                        value=start),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for": "contest-start-date",
                                                "contents": "Start Date"
                                            }),
                                        h.input(cls="form-control",
                                                name="contest-start-date",
                                                id="contest-start-date",
                                                type="date")
                                    ]),
                                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="showProblInfoBlocks",
                                        value=showProblInfoBlocks),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "show-problem-info-blocks",
                                                "contents":
                                                "Show Problem Info Blocks"
                                            }),
                                        h.select(
                                            cls="form-control custom-select",
                                            name="show-problem-info-blocks",
                                            id="show-problem-info-blocks",
                                            contents=showProblInfoBlocks_option
                                        )
                                    ]),
                                h.input(type="hidden",
                                        id="scoreboardOff",
                                        value=scoreboardOff),
                                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="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "scoreboard-tie-breaker",
                                                "contents":
                                                "Sample Data Breaks Ties"
                                            }),
                                        h.select(
                                            cls="form-control",
                                            name="scoreboard-tie-breaker",
                                            id="scoreboard-tie-breaker",
                                            contents=[
                                                *[
                                                    h.option(
                                                        text,
                                                        value=val,
                                                        selected="selected")
                                                    if tieBreaker == val else
                                                    h.option(text, value=val)
                                                    for text, val in zip(
                                                        ("On", "Off"), (True,
                                                                        False))
                                                ]
                                            ])
                                    ]),

                                # Option to display a users' fullname
                                h.input(type="hidden",
                                        id="displayFullname",
                                        value=displayFullname),
                                div(cls="form-group col-6",
                                    contents=[
                                        h.label(
                                            **{
                                                "for":
                                                "contest-display-fullname",
                                                "contents": "Show Full Name"
                                            }),
                                        h.select(
                                            cls="form-control",
                                            name="contest-display-fullname",
                                            id="contest-display-fullname",
                                            contents=[
                                                *[
                                                    h.option(
                                                        text,
                                                        value=val,
                                                        selected="selected") if
                                                    displayFullname == val else
                                                    h.option(text, value=val)
                                                    for text, val in zip(
                                                        ("On", "Off"), (True,
                                                                        False))
                                                ]
                                            ])
                                    ]),
                            ]),
                        div(cls="align-right col-12",
                            contents=[
                                h.button("Save",
                                         cls="button",
                                         onclick="editContest()")
                            ])
                    ])),
            *existingProblems))