def correctLog(params, user):
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return Page(h1(" "), h1("No Contest Available", cls="center"))
    elif contest.scoreboardOff <= time.time() * 1000 and not user.isAdmin():
        return Page(h1("&nbsp;"), h1("Scoreboard is off.", cls="center"))

    start = contest.start
    end = contest.end

    subs = {}
    for sub in Submission.all():
        if start <= sub.timestamp <= end and not sub.user.isAdmin():
            subs[sub.user.id] = subs.get(sub.user.id) or []
            subs[sub.user.id].append(sub)

    log = createLog(subs)

    logDisplay = []
    for (tmstmp, usr, ttl, id) in log:
        logDisplay.append(
            h.tr(
                h.td(tmstmp, cls='time-format', data_timestamp=tmstmp),
                h.td(usr),
                h.td(ttl, cls="center"),
            ))

    return Page(
        h2("Correct Log", cls="page-title"),
        h.table(
            h.thead(
                h.tr(h.th("Date/Time", cls="center"), h.th("Contestant"),
                     h.th("Problem", cls="center"))), h.tbody(*logDisplay)))
Пример #2
0
 def __init__(self, contest):
     subs = filter(
         lambda sub: sub.user.type != "admin" and contest.start <= sub.
         timestamp <= contest.end, Submission.all())
     self.html = h.table(
         h.thead(
             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")
Пример #3
0
 def __init__(self,
              title,
              contents,
              link=None,
              cls=None,
              delete=None,
              reply=None,
              user=None,
              problemId=None):
     if cls == None:
         cls = "card"
     else:
         cls += " card"
     deleteLink = ""
     if delete:
         deleteLink = div(h.i("clear", cls="material-icons"),
                          cls="delete-link",
                          onclick=delete)
     elif reply:
         deleteLink = div("Reply", cls="delete-link", onclick=reply)
     result = ''
     if user != None and problemId != None:
         icon = ''
         tmstmp = 0
         result = ''
         for i in Submission.all():
             if user.isAdmin():
                 break
             if i.problem != None:
                 if i.problem.id == problemId and i.user.id == user.id and "ok" == i.result:
                     icon = "check"
                     tmstmp = i.timestamp
                     break
                 elif i.problem.id == problemId and i.user.id == user.id and "pending" != i.result:
                     icon = "times"
                     tmstmp = i.timestamp
         if icon != '':
             result = f'<i class="fa fa-{icon}"></i> '
     self.html = h.div(cls=cls,
                       contents=[
                           div(cls="card-header",
                               contents=[
                                   h2(contents=[result, title],
                                      cls="card-title"), deleteLink
                               ]),
                           div(cls="card-contents", contents=contents)
                       ])
     if link != None:
         self.html = div(a(href=link, cls="card-link"),
                         self.html,
                         cls="card-link-box")
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}
Пример #5
0
def leaderboard(params, user):
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return Page(h1("&nbsp;"), h1("No Contest Available", cls="center"))
    elif contest.scoreboardOff <= time.time() * 1000 and not user.isAdmin():
        return Page(h1("&nbsp;"), h1("Scoreboard is off.", cls="center"))

    start = contest.start
    end = contest.end

    subs = {}
    for sub in Submission.all():
        if start <= sub.timestamp <= end and not sub.user.isAdmin():
            subs[sub.user.id] = subs.get(sub.user.id) or []
            subs[sub.user.id].append(sub)

    scores = []
    for user in subs:
        scor = score(subs[user], start)
        scores.append((User.get(user).username, scor[0], scor[1], scor[2]))
    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]

    scoresDisplay = []
    for (name, solved, samples, points), rank in zip(scores, ranks):
        scoresDisplay.append(
            h.tr(h.td(name), h.td(solved, cls="center"),
                 h.td(samples, cls="center"), h.td(points, cls="center"),
                 h.td(rank, cls="center")))

    return Page(
        h2("Leaderboard", cls="page-title"),
        h.table(
            h.thead(
                h.tr(h.th("User"), h.th("Problems Solved", cls="center"),
                     h.th("Sample Cases Solved", cls="center"),
                     h.th("Penalty Points", cls="center"),
                     h.th("Rank", cls="center"))), h.tbody(*scoresDisplay)))
Пример #6
0
def detailedReport(params, user):
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return Page(h1("&nbsp;"), h1("No Contest Available", cls="center"))
    elif contest.scoreboardOff <= time.time() * 1000 and not user.isAdmin():
        return Page(h1("&nbsp;"), h1("Scoreboard is off.", cls="center"))

    start = contest.start
    end = contest.end

    subs = {}
    for sub in Submission.all():
        if start <= sub.timestamp <= end and not sub.user.isAdmin():
            subs[sub.user.id] = subs.get(sub.user.id) or []
            subs[sub.user.id].append(sub)

    problemSummary = {}
    for prob in contest.problems:
        problemSummary[prob.id] = [0, 0]

    scores = []
    for user in subs:
        usersubs = subs[user]
        scor = score(usersubs, start, problemSummary)
        atempts = []
        for i in getDetails(usersubs, contest):
            atempts.append(i)
        scores.append((User.get(user).username, User.get(user).id, scor[0],
                       scor[1], scor[2], atempts))
    scores = sorted(scores,
                    key=lambda score: score[2] * 1000000000 + score[3] *
                    10000000 - score[4],
                    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]

    scoresDisplay = []
    for (name, usrID, solved, samples, points,
         atempts), rank in zip(scores, ranks):
        atmpts = []
        for atmpt in atempts:
            atmpts.append(h.td(atmpt, cls="center"))
        scoresDisplay.append(
            h.tr(h.td(rank, cls="center"),
                 h.td(name) if contest.end <= time.time() * 1000 else '',
                 h.td(usrID, cls="center"), h.td(solved, cls="center"),
                 h.td(points, cls="center"), *atmpts))
    problemSummaryDisplay = []
    languageSummaryDisplay = []
    cnt = 1
    for problem in contest.problems:
        contestDict = problem.contests[contest.id]
        problemSummaryDisplay.append(
            h.tr(h.td(cnt), h.td(problem.title),
                 h.td(problemSummary[problem.id][0], cls="center"),
                 h.td(problemSummary[problem.id][1], cls="center")))
        languageSummaryDisplay.append(
            h.tr(h.td(cnt), h.td(problem.title),
                 h.td(contestDict["c"], cls="center"),
                 h.td(contestDict["cpp"], cls="center"),
                 h.td(contestDict["cs"], cls="center"),
                 h.td(contestDict["java"], cls="center"),
                 h.td(contestDict["python2"], cls="center"),
                 h.td(contestDict["python3"], cls="center"),
                 h.td(contestDict["ruby"], cls="center"),
                 h.td(contestDict["vb"], cls="center")))
        cnt += 1

    prblmHeader = []
    cnt = 1
    for num in contest.problems:
        prblmHeader.append(h.th(cnt, cls="center"))
        cnt += 1

    return Page(
        h2("Detailed Report", cls="page-title"),
        h.table(
            h.thead(
                h.tr(
                    h.th("Rank", cls="center"),
                    h.th("Contestant")
                    if contest.end <= time.time() * 1000 else '',
                    h.th("ContestantID", cls="center"),
                    h.th("Correct", cls="center"), h.th("Penalty",
                                                        cls="center"),
                    *prblmHeader)), h.tbody(*scoresDisplay)),
        h2("Problem Summary", cls="page-title"),
        h.table(
            h.thead(
                h.tr(
                    h.th("#"),
                    h.th("Title"),
                    h.th("Attempts", cls="center"),
                    h.th("Correct", cls="center"),
                )), h.tbody(*problemSummaryDisplay)),
        h2("Problem Summary", cls="page-title"),
        h.table(
            h.thead(
                h.tr(h.th("#"), h.th("Title"), h.th("c", cls="center"),
                     h.th("cpp", cls="center"), h.th("cs", cls="center"),
                     h.th("java", cls="center"), h.th("python2", cls="center"),
                     h.th("python3", cls="center"), h.th("ruby", cls="center"),
                     h.th("vb", cls="center"))),
            h.tbody(*languageSummaryDisplay)))
Пример #7
0
def leaderboard(params, user):
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return Page(h1("&nbsp;"), h1("No Contest Available", cls="center"))
    elif contest.scoreboardOff <= time.time() * 1000 and not user.isAdmin():
        return Page(h1("&nbsp;"), h1("Scoreboard is off.", cls="center"))

    start = contest.start
    end = contest.end

    subs = {}
    for sub in Submission.all():
        if start <= sub.timestamp <= end and not sub.user.isAdmin():
            subs[sub.user.id] = subs.get(sub.user.id) or []
            subs[sub.user.id].append(sub)

    problemSummary = {}
    for prob in contest.problems:
        problemSummary[prob.id] = [0, 0]

    scores = []
    for user in subs:
        usersubs = subs[user]
        scor = score(usersubs, start, problemSummary)

        scores.append((User.get(user).username, scor[0], scor[1], scor[2],
                       len(usersubs)))
    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]

    scoresDisplay = []
    for (name, solved, samples, points, attempts), rank in zip(scores, ranks):

        scoresDisplay.append(
            h.tr(h.td(rank, cls="center"), h.td(name),
                 h.td(attempts, cls="center"), h.td(solved, cls="center"),
                 h.td(samples, cls="center"), h.td(points, cls="center")))

    problemSummaryDisplay = []
    for problem in contest.problems:
        problemSummaryDisplay.append(
            h.tr(h.td(problem.title),
                 h.td(problemSummary[problem.id][0], cls="center"),
                 h.td(problemSummary[problem.id][1], cls="center")))

    return Page(
        h2("Leaderboard", cls="page-title"),
        h.table(
            h.thead(
                h.tr(h.th("Rank", cls="center"), h.th("User"),
                     h.th("Attempts", cls="center"),
                     h.th("Problems Solved", cls="center"),
                     h.th("Sample Cases Solved", cls="center"),
                     h.th("Penalty Points", cls="center"))),
            h.tbody(*scoresDisplay)), h2("Problem Summary", cls="page-title"),
        h.table(
            h.thead(
                h.tr(
                    h.th("Problem", cls="center"),
                    h.th("Attempts", cls="center"),
                    h.th("Solved", cls="center"),
                )), h.tbody(*problemSummaryDisplay)), h.br(), h.br(), h.br(),
        div(cls="actions",
            contents=[
                h.button("Detailed Report",
                         cls="button correct-log",
                         onclick="window.location='/detailedReport'"),
                h.button("Correct Log",
                         cls="button correct-log",
                         onclick="window.location='/correctLog'")
            ]))
Пример #8
0
 def __init__(self, x, cont):
     num, prob = x
     subs = filter(
         lambda sub: sub.problem == prob and cont.start <= sub.timestamp <=
         cont.end, Submission.all())
     self.html = div(*map(SubmissionCard, subs), id=f"tabs-{num}")
Пример #9
0
 def __init__(self, contest):
     subs = filter(lambda sub: sub.user.type != "admin" and contest.start <= sub.timestamp <= contest.end, Submission.all())
     self.html = h.table(
         h.thead(
             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"
     )
Пример #10
0
 def __init__(self, x, cont):
     num, prob = x
     subs = filter(lambda sub: sub.problem == prob and cont.start <= sub.timestamp <= cont.end, Submission.all())
     self.html = div(*map(SubmissionCard, subs), id=f"tabs-{num}")
Пример #11
0
def leaderboard(params, user):
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return Page(
            h1("&nbsp;"),
            h1("No Contest Available", cls="center")
        )
    elif contest.scoreboardOff <= time.time() * 1000 and not user.isAdmin():
        return Page(
            h1("&nbsp;"),
            h1("Scoreboard is off.", cls="center")
        )

    start = contest.start
    end = contest.end

    
    subs = {}
    for sub in Submission.all():
        if start <= sub.timestamp <= end and not sub.user.isAdmin():
            subs[sub.user.id] = subs.get(sub.user.id) or []
            subs[sub.user.id].append(sub)            
    
    problemSummary = {}
    for prob in contest.problems:
        problemSummary[prob.id] = [0, 0]

    scores = []
    for user in subs:
        usersubs = subs[user]
        scor = score(usersubs, start, problemSummary)
        scores.append((
            User.get(user).username,
            scor[0],
            scor[1],
            scor[2],
            len(usersubs)
        ))
    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]
    
    scoresDisplay = []
    for (name, solved, samples, points, attempts), rank in zip(scores, ranks):
        scoresDisplay.append(h.tr(
            h.td(rank, cls="center"),
            h.td(name),
            h.td(attempts, cls="center"),
            h.td(solved, cls="center"),
            h.td(samples, cls="center"),
            h.td(points, cls="center")
        ))

    problemSummaryDisplay = []
    for problem in contest.problems:
        problemSummaryDisplay.append(h.tr(
            h.td(problem.title),
            h.td(problemSummary[problem.id][0], cls="center"),
            h.td(problemSummary[problem.id][1], cls="center")
        ))

    return Page(
        h2("Leaderboard", cls="page-title"),
        h.table(
            h.thead(
                h.tr(
                    h.th("Rank", cls="center"),
                    h.th("User"),
                    h.th("Attempts", cls="center"),
                    h.th("Problems Solved", cls="center"),
                    h.th("Sample Cases Solved", cls="center"),
                    h.th("Penalty Points", cls="center")
                )
            ),
            h.tbody(
                *scoresDisplay
            )
        ),
        h2("Problem Summary", cls="page-title"),
        h.table(
            h.thead(
                h.tr(
                    h.th("Problem", cls="center"),
                    h.th("Attempts", cls="center"),
                    h.th("Solved", cls="center"),
                )
            ),
            h.tbody(
                *problemSummaryDisplay
            )

        )
    )