Created
May 5, 2025 14:51
-
-
Save PeterJCLaw/f18eb2af9bcd8b119efe0f8fe5e7fc89 to your computer and use it in GitHub Desktop.
Script to export SRComp league & game points to a CSV
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 csv | |
| from sr.comp.comp import SRComp | |
| from sr.comp.matches import Match | |
| from sr.comp.scores import ( | |
| load_external_scores, | |
| load_external_scores_data, | |
| MatchScore, | |
| ) | |
| compstate = SRComp('../sr2025-comp') | |
| scores: list[tuple[Match, MatchScore]] = [ | |
| (match, y) | |
| for match_slot in compstate.schedule.matches | |
| for match in match_slot.values() | |
| if (y := compstate.scores.get_scores(match)) | |
| ] | |
| rows = [ | |
| { | |
| 'match_no': match.num, | |
| 'tla': tla, | |
| 'pos': score.ranking[tla], | |
| 'league_points': score.normalised[tla], | |
| 'game_points': score.game[tla], | |
| } | |
| for match, score in scores | |
| for tla in match.teams | |
| if tla | |
| ] | |
| with open('match-points.csv', mode='w') as f: | |
| writer = csv.DictWriter(f, rows[0].keys()) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| external_scores = load_external_scores( | |
| load_external_scores_data(compstate.root / 'external'), | |
| compstate.teams, | |
| ) | |
| rows2 = [ | |
| {'tla': tla, 'points': score.league_points} | |
| for tla, score in external_scores.items() | |
| ] | |
| with open('challenge-points.csv', mode='w') as f: | |
| writer = csv.DictWriter(f, rows2[0].keys()) | |
| writer.writeheader() | |
| writer.writerows(rows2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment