analyze bdrs. add links

This commit is contained in:
Maximilian Keßler 2023-11-10 11:03:08 +01:00
parent 7f1df756b2
commit 2fda0d0524
Signed by: max
GPG key ID: BCC5A619923C0BA5

View file

@ -4,6 +4,13 @@ import json
import csv import csv
import pandas 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) session = requests_cache.CachedSession('.hanab-live.cache',expire_after=300)
player_mapping = { 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] 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() player_cols = set()
for _, p in player_mapping.items(): for _, p in player_mapping.items():
@ -82,6 +89,15 @@ def collect_player_games():
return global_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): def sort_players_by_num_games(games_dict):
nums = {} nums = {}
@ -93,10 +109,12 @@ def sort_players_by_num_games(games_dict):
nums[col] = num + 1 nums[col] = num + 1
return sorted(player_cols, key = lambda col: -nums[col]) return sorted(player_cols, key = lambda col: -nums[col])
if __name__ == "__main__": if __name__ == "__main__":
games = collect_player_games() games = collect_player_games()
bdrs = analyze_bdrs(games)
streaks = {} 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 += sort_players_by_num_games(games)
fieldnames += ['Other'] fieldnames += ['Other']
@ -105,12 +123,14 @@ 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 _, entry in sorted(games.items()): for game_id, entry in sorted(games.items()):
row = { row = {
'Replay Number': entry.game_id, 'Replay Number': entry.game_id,
'Link': 'https://hanab.live/replay/{}'.format(entry.game_id),
'Seed Name': entry.seed, 'Seed Name': entry.seed,
'Player #': entry.num_players, '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: for player in entry.players:
col = player_mapping.get(player, None) col = player_mapping.get(player, None)