Created
May 27, 2024 14:18
-
-
Save cubercsl/0b42d2808799bec97f111c458e342250 to your computer and use it in GitHub Desktop.
DOMJudge Scoreboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import csv | |
import dj_utils | |
def problems_info(problems): | |
def problem_info(p): | |
if p['solved']: | |
return p['num_judged'], p['time'] | |
else: | |
return p['num_judged'], -1 | |
result = sum((problem_info(p) for p in problems), ()) | |
print(result) | |
return max(result[1::2]), *result | |
def main(): | |
scoreboard_data = dj_utils.do_api_request('scoreboard') | |
teams_data = dj_utils.do_api_request('teams') | |
teams = {} | |
for t in teams_data: | |
teams[t['id']] = t | |
result = [('scoreboard', '2')] | |
for row in scoreboard_data['rows']: | |
team = teams[row['team_id']] | |
result.append( | |
( | |
row['rank'], | |
team['affiliation'] if 'affiliation' in team else None, | |
team['display_name'] if 'display_name' in team and team['display_name'] else team['name'], | |
row['score']['num_solved'], | |
row['score']['total_time'], | |
*problems_info(row['problems']) | |
)) | |
with open('scoreboard.tsv', 'w', newline='') as f: | |
writer = csv.writer(f, delimiter='\t') | |
writer.writerows(result) | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print('Usage: python3 scoreboard.py <domjudge_webapp_folder_or_api_url>') | |
sys.exit(1) | |
dj_utils.domjudge_webapp_folder_or_api_url = sys.argv[1] | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment