From 2fda0d05247c785d3c375fa0363174dc0bf86b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 10 Nov 2023 11:03:08 +0100 Subject: [PATCH] analyze bdrs. add links --- get_sheet.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/get_sheet.py b/get_sheet.py index 08d58bd..3870fce 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -4,6 +4,13 @@ import json import csv import pandas +from bdr import describe_game +from hanabi.live.site_api import get + +from hanabi.database import global_db_connection_manager +global_db_connection_manager.read_config() +global_db_connection_manager.connect() + session = requests_cache.CachedSession('.hanab-live.cache',expire_after=300) player_mapping = { @@ -32,7 +39,7 @@ allowed_team_members = ['Carunty', 'HelanaAshryvr', 'rz'] allowed_players = [s.lower() for s in player_mapping.keys()] + [s.lower() for s in allowed_team_members] -excluded_games = [1056958] +excluded_games = [1056958, 1044951] player_cols = set() for _, p in player_mapping.items(): @@ -82,6 +89,15 @@ def collect_player_games(): return global_games +def analyze_bdrs(games): + retval = {} + for game_id in games.keys(): + game = get("export/" + str(game_id)) + bdrs = describe_game(game) + print(game_id, bdrs) + retval[game_id] = bdrs + return retval + def sort_players_by_num_games(games_dict): nums = {} @@ -93,10 +109,12 @@ def sort_players_by_num_games(games_dict): nums[col] = num + 1 return sorted(player_cols, key = lambda col: -nums[col]) + if __name__ == "__main__": games = collect_player_games() + bdrs = analyze_bdrs(games) streaks = {} - fieldnames = ['Replay Number', 'Seed Name', 'Player #', 'W/L(1/0)'] + fieldnames = ['Replay Number', 'Link', 'Seed Name', 'Player #', 'W/L(1/0)', 'BDR'] fieldnames += sort_players_by_num_games(games) fieldnames += ['Other'] @@ -105,12 +123,14 @@ if __name__ == "__main__": with open('games.csv', 'a', newline='') as f: writer = csv.DictWriter(f, fieldnames=fieldnames) - for _, entry in sorted(games.items()): + for game_id, entry in sorted(games.items()): row = { 'Replay Number': entry.game_id, + 'Link': 'https://hanab.live/replay/{}'.format(entry.game_id), 'Seed Name': entry.seed, 'Player #': entry.num_players, - 'W/L(1/0)': entry.won + 'W/L(1/0)': entry.won, + 'BDR': len(bdrs[game_id]) } for player in entry.players: col = player_mapping.get(player, None)