Пример #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"/messages/{id}/message.json")
         self.id = details["id"]
         self.fromUser = User.get(details["from"])
         self.toUser = User.get(details["to"])
         self.isGeneral = bool(details["general"])  # General announcement
         self.isAdmin = bool(details["admin"])  # Message sent to admin
         self.message = details["message"]
         self.timestamp = float(details["timestamp"])
         self.replyTo = details.get("replyTo")
     else:
         self.id = None
         self.fromUser = None
         self.toUser = None
         self.isGeneral = False
         self.isAdmin = False
         self.message = ""
         self.timestamp = 0
         self.replyTo = None
Пример #3
0
def sendMessage(request):
    message = Message()
    user = User.getCurrent(request)
    message.fromUser = user
    message.message = html_encode(request.POST["message"])
    message.timestamp = time.time() * 1000
    if user.isAdmin():
        message.toUser = User.get(request.POST["to"])
        message.isGeneral = request.POST["to"] == "general"
        message.replyTo = request.POST.get("replyTo")
    else:
        message.isAdmin = True
    message.save()
    return JsonResponse("ok", safe=False)
Пример #4
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))))
Пример #5
0
 def __init__(self, sub):
     checkoutUser = User.get(sub.checkout)
     self.html = h.tr(
         h.td(sub.user.username),
         h.td(sub.problem.title),
         h.td(sub.id),  # cls='time-format', contents=sub.timestamp
         h.td(sub.language),
         h.td(h.i("&nbsp;", cls=f"fa fa-{icons.get(sub.result)}"),
              h.span(verdict_name.get(sub.result))),
         h.td(contents=[
             sub.status,
             h.p(sub.version, id=f"{sub.id}-version", hidden=True)
         ]),
         h.td(
             checkoutUser.username if checkoutUser is not None else "None"),
         id=sub.id,
         cls="submit-row",
     )
Пример #6
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 []
        )
    ))
Пример #7
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
    ))