add team statistics
This commit is contained in:
parent
92f8e124bf
commit
b832a3aa5c
2 changed files with 54 additions and 7 deletions
2
bdr.py
2
bdr.py
|
@ -13,7 +13,7 @@ def analyze_game(instance: HanabLiveInstance, actions: List[Action]) -> Tuple[Li
|
||||||
discard = instance.deck[action.target]
|
discard = instance.deck[action.target]
|
||||||
if not game.is_trash(discard):
|
if not game.is_trash(discard):
|
||||||
if game.is_critical(discard):
|
if game.is_critical(discard):
|
||||||
termination = 'Discard crit'
|
termination = 'Discard crit' if action.type == ActionType.Discard else 'Bomb crit'
|
||||||
break
|
break
|
||||||
if discard.rank != 1:
|
if discard.rank != 1:
|
||||||
if discard in game.deck[game.progress:]:
|
if discard in game.deck[game.progress:]:
|
||||||
|
|
59
get_sheet.py
59
get_sheet.py
|
@ -3,7 +3,7 @@ import requests_cache
|
||||||
import json
|
import json
|
||||||
import csv
|
import csv
|
||||||
import pandas
|
import pandas
|
||||||
from typing import List, Optional
|
from typing import List, Optional, Dict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from hanabi.database import global_db_connection_manager
|
from hanabi.database import global_db_connection_manager
|
||||||
|
@ -73,7 +73,7 @@ def get_player_games(player: str):
|
||||||
return json.loads(r.text)
|
return json.loads(r.text)
|
||||||
|
|
||||||
|
|
||||||
def collect_player_games():
|
def collect_player_games() -> Dict[int, Entry]:
|
||||||
global_games = {}
|
global_games = {}
|
||||||
for player in player_mapping.keys():
|
for player in player_mapping.keys():
|
||||||
print('Parsing games for player {}'.format(player))
|
print('Parsing games for player {}'.format(player))
|
||||||
|
@ -201,9 +201,7 @@ def make_endgame_tables(ids: List[int], strategy: Optional[str] = None):
|
||||||
x.to_html(Path(filename).with_suffix('.html'), escape=False)
|
x.to_html(Path(filename).with_suffix('.html'), escape=False)
|
||||||
|
|
||||||
|
|
||||||
def make_results_table(games):
|
def make_results_table(games, analysis):
|
||||||
analysis = analyze_games(games)
|
|
||||||
|
|
||||||
streaks = {}
|
streaks = {}
|
||||||
fieldnames = ['Game ID', 'Seed', 'Player #', 'Result', 'BDR']
|
fieldnames = ['Game ID', 'Seed', 'Player #', 'Result', 'BDR']
|
||||||
fieldnames += sort_players_by_num_games(games)
|
fieldnames += sort_players_by_num_games(games)
|
||||||
|
@ -243,6 +241,51 @@ def make_results_table(games):
|
||||||
a.to_html("out/games.html", escape=False)
|
a.to_html("out/games.html", escape=False)
|
||||||
|
|
||||||
|
|
||||||
|
def make_team_table(games, analysis):
|
||||||
|
stats = {3: {}, 4: {}, 5: {}}
|
||||||
|
for game_id, entry in games.items():
|
||||||
|
normalized_players = sorted(map(lambda player: player_mapping.get(player, 'Other'), entry.players))
|
||||||
|
if 'Other' in normalized_players:
|
||||||
|
continue
|
||||||
|
|
||||||
|
num_p = len(normalized_players)
|
||||||
|
|
||||||
|
key = ", ".join(normalized_players)
|
||||||
|
|
||||||
|
bdr, termination = analysis[game_id]
|
||||||
|
|
||||||
|
if key not in stats[num_p]:
|
||||||
|
stats[num_p][key] = {
|
||||||
|
'Games': 0,
|
||||||
|
'BDR': 0,
|
||||||
|
'Win': 0,
|
||||||
|
'Discard crit': 0,
|
||||||
|
'Bomb crit': 0,
|
||||||
|
'Strikeout': 0,
|
||||||
|
'VTK': 0,
|
||||||
|
'Lost Endgame': 0
|
||||||
|
}
|
||||||
|
|
||||||
|
stats[num_p][key]['Games'] += 1
|
||||||
|
stats[num_p][key]['BDR'] += len(bdr)
|
||||||
|
if entry.won:
|
||||||
|
stats[num_p][key]['Win'] += 1
|
||||||
|
else:
|
||||||
|
stats[num_p][key][termination] += 1
|
||||||
|
|
||||||
|
for num_p in range(3, 6):
|
||||||
|
filename = Path('out/teams_{}.csv'.format(num_p))
|
||||||
|
with open(filename, 'w') as f:
|
||||||
|
writer = csv.DictWriter(f, fieldnames=['Team', 'Games', 'Win', 'BDR', 'Discard crit', 'Bomb crit', 'Strikeout', 'VTK', 'Lost Endgame'])
|
||||||
|
writer.writeheader()
|
||||||
|
for team, row in sorted(stats[num_p].items(), key=lambda item: -item[1]['Games']):
|
||||||
|
row['Team'] = team
|
||||||
|
writer.writerow(row)
|
||||||
|
|
||||||
|
x = pandas.read_csv(filename)
|
||||||
|
x.to_html(filename.with_suffix('.html'))
|
||||||
|
|
||||||
|
|
||||||
def create_replay_links(ids: List[int], strategy: str):
|
def create_replay_links(ids: List[int], strategy: str):
|
||||||
outfile = Path('out/{}_links.csv'.format(strategy))
|
outfile = Path('out/{}_links.csv'.format(strategy))
|
||||||
with open(outfile, 'w') as f:
|
with open(outfile, 'w') as f:
|
||||||
|
@ -263,10 +306,14 @@ def create_replay_links(ids: List[int], strategy: str):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
games = collect_player_games()
|
games = collect_player_games()
|
||||||
|
analysis = analyze_games(games)
|
||||||
game_ids = sorted(int(key) for key in games.keys())
|
game_ids = sorted(int(key) for key in games.keys())
|
||||||
|
|
||||||
# This is the main table, tracking streaks, loss reasons, BDRs
|
# This is the main table, tracking streaks, loss reasons, BDRs
|
||||||
make_results_table(games)
|
make_results_table(games, analysis)
|
||||||
|
|
||||||
|
# This tracks team statistics
|
||||||
|
make_team_table(games, analysis)
|
||||||
|
|
||||||
# Additional endgame analysis stats:
|
# Additional endgame analysis stats:
|
||||||
# For the real games
|
# For the real games
|
||||||
|
|
Loading…
Reference in a new issue