def viewProblem(params, user):
    problem = Problem.get(params[0])
    
    if not problem:
        return ""

    if not user.isAdmin():
        # Hide the problems till the contest begins for non-admin users
        if not Contest.getCurrent():
            return ""
        if problem not in Contest.getCurrent().problems:
            return ""
    
    return Page(
        h.input(type="hidden", id="problem-id", value=problem.id),
        h2(problem.title, cls="page-title"),
        div(cls="problem-description", 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"),
            div(cls="samples", contents=list(map(lambda x: getSample(x[0], x[1]), zip(problem.sampleData, range(problem.samples)))))
        ]),
        CodeEditor(),
        div(cls="align-right", contents=[
            h.button("Test Code", cls="button test-samples button-white"),
            h.button("Submit Code", cls="button submit-problem")
        ])
    )
Beispiel #2
0
def viewProblem(params, user):
    problem = Problem.get(params[0])
    
    if not problem:
        return ""

    if not user.isAdmin():
        # Hide the problems till the contest begins for non-admin users
        if not Contest.getCurrent():
            return ""
        if problem not in Contest.getCurrent().problems:
            return ""
    
    return Page(
        h.input(type="hidden", id="problem-id", value=problem.id),
        h2(problem.title, cls="page-title"),
        div(cls="problem-description", 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"),       
            div(cls="samples", contents=list(map(lambda x: getSample(x[0], x[1]), zip(problem.sampleData, range(problem.samples)))))
        ]),
        CodeEditor(),
        div(cls="stmt card ui-sortable-handle", 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.button("Test Custom Code", cls="button test-custom button-white"),
            h.button("Test Code", cls="button test-samples button-white"),
            h.button("Submit Code", cls="button submit-problem")
        ])
    )
Beispiel #3
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"])
         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.inputs = details["inputs"]
         self.outputs = details["outputs"]
         self.errors = details["errors"]
         self.answers = details["answers"]
         self.result = details["result"]
     else:
         self.id = None
         self.user = None
         self.problem = None
         self.timestamp = 0
         self.language = None
         self.code = None
         self.type = None
         self.results = []
         self.inputs = []
         self.outputs = []
         self.errors = []
         self.answers = []
         self.result = []
 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"])
         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.inputs      = details["inputs"]
         self.outputs     = details["outputs"]
         self.errors      = details["errors"]
         self.answers     = details["answers"]
         self.result      = details["result"]
     else:
         self.id          = None
         self.user        = None
         self.problem     = None
         self.timestamp   = 0
         self.language    = None
         self.code        = None
         self.type        = None
         self.results     = []
         self.inputs      = []
         self.outputs     = []
         self.errors      = []
         self.answers     = []
         self.result      = []
def editContest(params, setHeader, user):
    id = params.get("id")
    contest = Contest.get(id) or Contest()

    contest.name = params["name"]
    contest.start = int(params["start"])
    contest.end = int(params["end"])
    contest.scoreboardOff = int(params["scoreboardOff"])
    contest.probInfoBlocks = params["probInfoBlocks"] == "True"
    contest.problems = [
        Problem.get(id) for id in json.loads(params["problems"])
    ]
    for i in contest.problems:
        i.contests[contest.id] = {
            "c": 0,
            "cpp": 0,
            "cs": 0,
            "java": 0,
            "python2": 0,
            "python3": 0,
            "ruby": 0,
            "vb": 0,
            "completed": []
        }
        i.save()
    if str(params["tieBreaker"]).lower() == "true":
        contest.tieBreaker = True
    else:
        contest.tieBreaker = False
    contest.save()

    return contest.id
def editContest(params, setHeader, user):
    id = params.get("id")
    contest = Contest.get(id) or Contest()

    contest.name     = params["name"]
    contest.start    = int(params["start"])
    contest.end      = int(params["end"])
    contest.scoreboardOff = int(params["scoreboardOff"])
    contest.problems = [Problem.get(id) for id in json.loads(params["problems"])]

    contest.save()

    return contest.id
def addSubmission(probId, lang, code, user, type):
    sub = Submission()
    sub.problem = Problem.get(probId)
    sub.language = lang
    sub.code = code
    sub.result = "pending"
    sub.user = user
    sub.timestamp = time.time() * 1000
    sub.type = type
    if type == "submit":
        sub.save()
    else:
        sub.id = str(uuid4())
    return sub
Beispiel #8
0
def addSubmission(probId, lang, code, user, type):
    sub = Submission()
    sub.problem = Problem.get(probId)
    sub.language = lang
    sub.code = code
    sub.result = "pending"
    sub.user = user
    sub.timestamp = time.time() * 1000
    sub.type = type
    if type == "submit":
        sub.save()
    else:
        sub.id = str(uuid4())
    return sub
def rejudgeAll(params, setHeader, user):
    probId = params["probId"]
    # curTime = params["curTime"]
    curTime = time.time() * 1000
    count = 0
    for contestant in filter(lambda c: not c.isAdmin(), User.all()):
        for sub in filter(
                lambda s: s.user.id == contestant.id and s.problem.id == probId
                and s.timestamp < curTime and s.result != "reject" and s.type
                != "test", Submission.all()):
            if os.path.exists(f"/tmp/{id}"):
                shutil.rmtree(f"/tmp/{id}")
            runCode(sub)
            count += 1
    return {"name": Problem.get(probId).title, "count": count}
Beispiel #10
0
def editContest(params, setHeader, user):
    id = params.get("id")
    contest = Contest.get(id) or Contest()

    contest.name = params["name"]
    contest.start = int(params["start"])
    contest.end = int(params["end"])
    contest.scoreboardOff = int(params["scoreboardOff"])
    contest.problems = [
        Problem.get(id) for id in json.loads(params["problems"])
    ]

    contest.save()

    return contest.id
Beispiel #11
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.problems = [Problem.get(id) for id in details["problems"]]
     else:
         self.id = None
         self.name = None
         self.start = None
         self.end = None
         self.scoreboardOff = None
         self.problems = None
 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.problems = [Problem.get(id) for id in details["problems"]]
     else:
         self.id = None
         self.name = None
         self.start = None
         self.end = None
         self.scoreboardOff = None
         self.problems = None            
Beispiel #13
0
def editContest(params, setHeader, user):
    id = params.get("id")
    contest = Contest.get(id) or Contest()

    contest.name     = params["name"]
    contest.start    = int(params["start"])
    contest.end      = int(params["end"])
    contest.scoreboardOff = int(params["scoreboardOff"])
    contest.problems = [Problem.get(id) for id in json.loads(params["problems"])]
    if str(params["tieBreaker"]).lower() == "true":
        contest.tieBreaker = True
    else:
        contest.tieBreaker = False

    contest.save()

    return contest.id
Beispiel #14
0
def viewProblem(params, user):
    problem = Problem.get(params[0])

    if not problem:
        return ""

    if not user.isAdmin():
        # Hide the problems till the contest begins for non-admin users
        if not Contest.getCurrent():
            return ""
        if problem not in Contest.getCurrent().problems:
            return ""

    cards = []
    if Contest.getCurrent() is None or Contest.getCurrent().probInfoBlocks:
        cards = [
            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"),
            Card("Time Limit",
                 formatMD(f"{problem.timeLimit} second" +
                          ("" if problem.timeLimit == 1 else "s")),
                 cls="constraints"),
        ]

    return Page(
        h.input(type="hidden", id="problem-id", value=problem.id),
        h2(problem.title, cls="page-title"),
        div(cls="problem-description",
            contents=[
                *cards,
                div(cls="samples",
                    contents=list(
                        map(lambda x: getSample(x[0], x[1]),
                            zip(problem.sampleData, range(problem.samples)))))
            ]), CodeEditor(),
        div(cls="align-right",
            contents=[
                h.button("Test Code", cls="button test-samples button-white"),
                h.button("Submit Code", cls="button submit-problem")
            ]))
Beispiel #15
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.probInfoBlocks = details["probInfoBlocks"] == "True"
            self.problems = [Problem.get(id) for id in details["problems"]]
            if str(details["tieBreaker"]).lower() == "true":
                self.tieBreaker = True
            else:
                self.tieBreaker = False

        else:
            self.id = None
            self.name = None
            self.start = None
            self.end = None
            self.scoreboardOff = None
            self.tieBreaker = False
            self.probInfoBlocks = True
            self.problems = None
def editProblem(params, user):
    probId = params[0]
    prob = Problem.get(probId)
    return Page(
        h.input(type="hidden", id="prob-id", value=probId),
        h.input(type="hidden", id="pageId", value="Problem"),
        h2(prob.title, cls="page-title"),
        div(cls="actions", contents=[
            h.button("View Problem", cls="button", onclick=f"window.location='/problems/{probId}'"),
            h.button("+ Create Test Data", cls="button", onclick="createTestDataDialog()")
        ]),
        Card("Problem Details", div(cls="problem-details", contents=[
            h.form(cls="row", contents=[
                div(cls="form-group col-12", contents=[
                    h.label(**{"for": "problem-title", "contents":"Title"}),
                    h.input(cls="form-control", name="problem-title", id="problem-title", value=prob.title)
                ]),
                div(cls="form-group col-12", contents=[
                    h.label(**{"for": "problem-description", "contents":"Description"}),
                    h.textarea(cls="form-control", name="problem-description", id="problem-description", contents=escape(prob.description))
                ]),
                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=escape(prob.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=escape(prob.input))
                ]),
                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=escape(prob.output))
                ]),
                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=escape(prob.constraints))
                ]),
                div(cls="form-group col-12", contents=[
                    h.label(**{"for": "problem-samples", "contents":"Number of Sample Cases"}),
                    h.input(cls="form-control", type="number", name="problem-samples", id="problem-samples", value=prob.samples)
                ]),
            ]),
            div(cls="align-right col-12", contents=[
                h.button("Save", cls="button", onclick="editProblem()")
            ])
          ])),
        Modal(
            "Create Test Data",
            div(
                h.h5("Input"),
                h.textarea(rows="5", cls="test-data-input col-12 monospace margin-bottom"),
                h.h5("Output"),
                h.textarea(rows="5", cls="test-data-output col-12 monospace")
            ),
            div(
                h.button("Cancel", **{"type":"button", "class": "button button-white", "data-dismiss": "modal"}),
                h.button("Add Test Data", **{"type":"button", "class": "button", "onclick": "createTestData()"})
            )
        ),
        div(cls="test-data-cards", contents=list(map(TestDataCard, zip(range(prob.tests), prob.testData, [prob.samples] * prob.tests))))
    )
Beispiel #17
0
def editProblem(params, user):
    probId = params[0]
    prob = Problem.get(probId)
    return Page(
        h.input(type="hidden", id="prob-id", value=probId),
        h.input(type="hidden", id="pageId", value="Problem"),
        h2(prob.title, cls="page-title"),
        div(cls="actions",
            contents=[
                h.button("View Problem",
                         cls="button",
                         onclick=f"window.location='/problems/{probId}'"),
                h.button("+ Create Test Data",
                         cls="button",
                         onclick="createTestDataDialog()")
            ]),
        Card(
            "Problem Details",
            div(cls="problem-details",
                contents=[
                    h.form(
                        cls="row",
                        contents=[
                            div(cls="form-group col-12",
                                contents=[
                                    h.label(
                                        **{
                                            "for": "problem-title",
                                            "contents": "Title"
                                        }),
                                    h.input(cls="form-control",
                                            name="problem-title",
                                            id="problem-title",
                                            value=prob.title)
                                ]),
                            div(cls="form-group col-12",
                                contents=[
                                    h.label(
                                        **{
                                            "for": "problem-description",
                                            "contents": "Description"
                                        }),
                                    h.textarea(cls="form-control",
                                               name="problem-description",
                                               id="problem-description",
                                               contents=escape(
                                                   prob.description))
                                ]),
                            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=escape(prob.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=escape(prob.input))
                                ]),
                            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=escape(prob.output))
                                ]),
                            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=escape(
                                                   prob.constraints))
                                ]),
                            div(cls="form-group col-6",
                                contents=[
                                    h.label(
                                        **{
                                            "for": "problem-time-limit",
                                            "contents": "Time Limit (seconds)"
                                        }),
                                    h.input(cls="form-control",
                                            type="number",
                                            name="problem-time-limit",
                                            id="problem-time-limit",
                                            value=prob.timeLimit)
                                ]),
                            div(cls="form-group col-6",
                                contents=[
                                    h.label(
                                        **{
                                            "for": "problem-samples",
                                            "contents":
                                            "Number of Sample Cases"
                                        }),
                                    h.input(cls="form-control",
                                            type="number",
                                            name="problem-samples",
                                            id="problem-samples",
                                            value=prob.samples)
                                ]),
                        ]),
                    div(cls="align-right col-12",
                        contents=[
                            h.button("Save",
                                     cls="button",
                                     onclick="editProblem()")
                        ])
                ])),
        Modal(
            "Create Test Data",
            div(
                h.h5("Input"),
                h.textarea(
                    rows="5",
                    cls="test-data-input col-12 monospace margin-bottom"),
                h.h5("Output"),
                h.textarea(rows="5", cls="test-data-output col-12 monospace")),
            div(
                h.button(
                    "Cancel", **{
                        "type": "button",
                        "class": "button button-white",
                        "data-dismiss": "modal"
                    }),
                h.button(
                    "Add Test Data", **{
                        "type": "button",
                        "class": "button",
                        "onclick": "createTestData()"
                    }))),
        div(cls="test-data-cards",
            contents=list(
                map(
                    TestDataCard,
                    zip(range(prob.tests), prob.testData,
                        [prob.samples] * prob.tests)))))