include loss reasons and urls into table

This commit is contained in:
Maximilian Keßler 2023-11-10 12:01:08 +01:00
parent b65c4fe43f
commit 87cbc700ee
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -89,13 +89,12 @@ def collect_player_games():
return global_games return global_games
def analyze_bdrs(games): def analyze_games(games):
retval = {} retval = {}
for game_id in games.keys(): for game_id in games.keys():
game = get("export/" + str(game_id)) game = get("export/" + str(game_id))
bdrs = describe_game(game) bdrs, termination = describe_game(game)
print(game_id, bdrs) retval[game_id] = bdrs, termination
retval[game_id] = bdrs
return retval return retval
@ -112,9 +111,9 @@ def sort_players_by_num_games(games_dict):
if __name__ == "__main__": if __name__ == "__main__":
games = collect_player_games() games = collect_player_games()
bdrs = analyze_bdrs(games) analysis = analyze_games(games)
streaks = {} streaks = {}
fieldnames = ['Replay Number', 'Link', 'Seed Name', 'Player #', 'W/L(1/0)', 'BDR'] fieldnames = ['Replay Number', 'Seed Name', 'Player #', 'Result', 'BDR']
fieldnames += sort_players_by_num_games(games) fieldnames += sort_players_by_num_games(games)
fieldnames += ['Other'] fieldnames += ['Other']
@ -124,13 +123,13 @@ if __name__ == "__main__":
with open('games.csv', 'a', newline='') as f: with open('games.csv', 'a', newline='') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames) writer = csv.DictWriter(f, fieldnames=fieldnames)
for game_id, entry in sorted(games.items()): for game_id, entry in sorted(games.items()):
bdrs, termination = analysis[game_id]
row = { row = {
'Replay Number': entry.game_id, 'Replay Number': "<a href='https://hanab.live/replay/{}'>{}</a>".format(entry.game_id, entry.game_id),
'Link': 'https://hanab.live/replay/{}'.format(entry.game_id), 'Seed Name': "<a href='https://hanab.live/seed/{}'>{}</a>".format(entry.seed, entry.seed),
'Seed Name': entry.seed,
'Player #': entry.num_players, 'Player #': entry.num_players,
'W/L(1/0)': entry.won, 'Result': 'Win' if entry.won else termination,
'BDR': len(bdrs[game_id]) 'BDR': len(bdrs),
} }
for player in entry.players: for player in entry.players:
col = player_mapping.get(player, None) col = player_mapping.get(player, None)
@ -148,4 +147,4 @@ if __name__ == "__main__":
row['Other'] = num_others + 1 row['Other'] = num_others + 1
writer.writerow(row) writer.writerow(row)
a = pandas.read_csv("games.csv") a = pandas.read_csv("games.csv")
a.to_html("games.html") a.to_html("games.html", escape=False)