From 8bd1f3bc2501a7a032032853d1d93a1bb243d1e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Sat, 11 Nov 2023 04:20:59 +0100 Subject: [PATCH] analyze with different clue counts --- get_sheet.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/get_sheet.py b/get_sheet.py index 14978d1..cb129a4 100644 --- a/get_sheet.py +++ b/get_sheet.py @@ -8,7 +8,7 @@ from hanabi.database import global_db_connection_manager from hanabi.live.site_api import get from bdr import describe_game -from endgames import analyze_game_cached +from endgames import analyze_game_cached, full_analyze_game_cached # Init db connection global_db_connection_manager.read_config() @@ -112,6 +112,15 @@ def analyze_endgames(games): print(result) return retval +def full_analyze_endgames(games): + retval = {} + for game_id in games.keys(): + print('Analysing all endgames of game {}'.format(game_id)) + result = full_analyze_game_cached(game_id) + retval[game_id] = result + print(result) + return retval + def sort_players_by_num_games(games_dict): nums = {} @@ -124,6 +133,20 @@ def sort_players_by_num_games(games_dict): return sorted(player_cols, key = lambda col: -nums[col]) +def lookup_val(endgame_dict, clue_modifier): + if clue_modifier > 0: + for lookup in range(clue_modifier, 0, -1): + val = endgame_dict.get('+' + str(lookup), None) + if val is not None: + return val + if clue_modifier < 0: + for lookup in range(clue_modifier, 0): + val = endgame_dict.get(str(lookup)) + if val is not None: + return val + return endgame_dict.get('+0', None) + + if __name__ == "__main__": games = collect_player_games() analysis = analyze_games(games) @@ -173,6 +196,27 @@ if __name__ == "__main__": endgame['Game ID'] = "{}".format(game_id, game_id) writer.writerow(endgame) + all_endgames = full_analyze_endgames(games) + fieldnames = ['Game ID'] + [str(i) for i in range(1, 11)] + for clue_modifier in range(-2, 3): + filename = 'endgames{}.csv'.format(clue_modifier) + with open(filename, 'w') as f: + f.writelines([','.join(fieldnames), "\n"]) + with open(filename, 'a') as f: + writer = csv.DictWriter(f, fieldnames=fieldnames) + for game_id, endgame in sorted(all_endgames.items()): + row = {'Game ID': game_id} + for deck_size in range(1, 11): + val = lookup_val(endgame.get(str(deck_size), {}), clue_modifier) + if val is not None: + row[str(deck_size)] = val + writer.writerow(row) + + print('processed file {}'.format(filename)) + + x = pandas.read_csv(filename) + x.to_html('endgames_{}.html'.format(clue_modifier), escape=False) + a = pandas.read_csv("games.csv") a.to_html("games.html", escape=False)