Ejemplo n.º 1
0
def getSubmissions(request, *args, **kwargs):
    submissions = []

    cont = Contest.getCurrent()
    if not cont:
        return HttpResponse(
            Page(h1(" "), h1("Contest is Over", cls="center")))

    user = User.getCurrent(request)
    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 HttpResponse(Page(h1("No Submissions Yet", cls="page-title"), ))
    return HttpResponse(
        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")])
                ])))
Ejemplo n.º 2
0
def judge(request):
    cont = Contest.getCurrent() or Contest.getPast()
    if not cont:
        return HttpResponse(
            Page(h1("&nbsp;"), h1("No Contest Available", cls="center")))
    return HttpResponse(
        Page(
            h2("Judge Submissions", cls="page-title judge-width"),
            div(cls="actions",
                contents=[
                    h.button("Reset Filter",
                             cls="button",
                             onclick="resetJudgeFilter()"),
                ]),
            div(id="judge-table",
                cls="judge-width",
                contents=[SubmissionTable(cont)]),
            div(cls="modal",
                tabindex="-1",
                role="dialog",
                contents=[
                    div(cls="modal-dialog",
                        role="document",
                        contents=[div(id="modal-content")])
                ]),
            cls='wide-content'  # Use a wide format for this page
        ))
Ejemplo n.º 3
0
def generateLogReport(request):
    user = User.getCurrent(request)
    contest = Contest.getCurrent() or Contest.getPast()
    if not contest:
        return HttpResponse(
            Page(h1("&nbsp;"), h1("No Contest Available", cls="center")))
    elif contest.isScoreboardOff(user):
        return HttpResponse(
            Page(h1("&nbsp;"), 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))))
Ejemplo n.º 4
0
 def __init__(self, title, endtimestamp=None):
     timeRemaining = ""
     if endtimestamp:
         timeRemaining = str(int(((endtimestamp / 1000) - time.time())))
     self.html = div(
         cls="top",
         contents=[
             div(cls="header",
                 contents=[
                     h1(title),
                     div(cls="spacer"),
                     div(cls="header-right",
                         contents=[
                             h.span(cls="time-remaining",
                                    data_timeremaining=timeRemaining),
                             h.br(),
                             h.span(cls="login-user")
                         ])
                 ])
         ])
Ejemplo n.º 5
0
def listProblems(request):
    user = User.getCurrent(request)
    if Contest.getCurrent() or (Contest.getPast() and user.isAdmin()):
        contest = Contest.getCurrent() or Contest.getPast()
        probCards = []
        for prob in contest.problems:
            probCards.append(ProblemCard(prob, user))

        return HttpResponse(Page(h2("Problems", cls="page-title"), *probCards))
    elif Contest.getFuture():
        contest = Contest.getFuture()
        return HttpResponse(
            Page(h1("&nbsp;"), h1("Contest Starts in", cls="center"),
                 h1(contest.start, cls="countdown jumbotron center")))
    elif Contest.getPast():
        return HttpResponse(
            Page(h1("&nbsp;"), h1("Contest is Over", cls="center")))
    return HttpResponse(
        Page(h1("&nbsp;"), h1("No Contest Created", cls="center")))
Ejemplo n.º 6
0
def fake_privacy(request):
    return HttpResponse(Page(
        h2("Privacy Policy", cls="page-title"),
        h1("LOL", cls="jumbotron center"),
        h1("After all, you use Facebook", cls="center")
    ))
Ejemplo n.º 7
0
def leaderboard(request):
    contest = Contest.getCurrent() or Contest.getPast()
    user = User.getCurrent(request)
    if not contest:
        return HttpResponse(Page(
            h1("&nbsp;"),
            h1("No Contest Available", cls="center")
        ))
    elif contest.isScoreboardOff(user):
        return HttpResponse(Page(
            h1("&nbsp;"),
            h1("Scoreboard is off.", cls="center")
        ))

    start = contest.start
    end = contest.end

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

    scores = []
    for userid in subs:
        usersubs = subs[userid]
        scor = score(usersubs, contest, problemSummary)

        # Set displayName to fullname if displayFullname option is true,
        # otherwise, use the username
        displayName = User.get(userid).fullname if contest.displayFullname == True else User.get(userid).username
        
        scores.append((
            displayName,
            scor[0],
            scor[1],
            scor[2],
            scor[3]
        ))
    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 HttpResponse(Page(
        h2("Leaderboard", cls="page-title"),
        div(cls="actions", contents=[
            h.button("Detailed Contest Report", cls="button create-message", onclick="window.location.href='/contestreport'")
        ]),
        h.table(cls="banded", contents=[
            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(cls="banded", contents=[
            h.thead(
                h.tr(
                    h.th("Problem", cls="center"),
                    h.th("Attempts", cls="center"),
                    h.th("Solved", cls="center"),
                )
            ),
            h.tbody(
                *problemSummaryDisplay
            )
        ]),
        div(cls="align-right", contents=[
            h.br(),
            h.button("Correct Log", cls="button", onclick="window.location='/correctlog'")
        ] if user and user.isAdmin() else []
        )
    ))
Ejemplo n.º 8
0
def contestreport(request):
    contest = Contest.getCurrent() or Contest.getPast()
    user = User.getCurrent(request)
    if not contest:
        return HttpResponse(Page(
            h1("&nbsp;"),
            h1("No Contest Available", cls="center")
        ))
    elif contest.isScoreboardOff(user):
        return HttpResponse(Page(
            h1("&nbsp;"),
            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
    ))