analyze with different clue counts
This commit is contained in:
parent
c98e9f3c7e
commit
8bd1f3bc25
1 changed files with 45 additions and 1 deletions
46
get_sheet.py
46
get_sheet.py
|
@ -8,7 +8,7 @@ from hanabi.database import global_db_connection_manager
|
||||||
from hanabi.live.site_api import get
|
from hanabi.live.site_api import get
|
||||||
|
|
||||||
from bdr import describe_game
|
from bdr import describe_game
|
||||||
from endgames import analyze_game_cached
|
from endgames import analyze_game_cached, full_analyze_game_cached
|
||||||
|
|
||||||
# Init db connection
|
# Init db connection
|
||||||
global_db_connection_manager.read_config()
|
global_db_connection_manager.read_config()
|
||||||
|
@ -112,6 +112,15 @@ def analyze_endgames(games):
|
||||||
print(result)
|
print(result)
|
||||||
return retval
|
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):
|
def sort_players_by_num_games(games_dict):
|
||||||
nums = {}
|
nums = {}
|
||||||
|
@ -124,6 +133,20 @@ def sort_players_by_num_games(games_dict):
|
||||||
return sorted(player_cols, key = lambda col: -nums[col])
|
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__":
|
if __name__ == "__main__":
|
||||||
games = collect_player_games()
|
games = collect_player_games()
|
||||||
analysis = analyze_games(games)
|
analysis = analyze_games(games)
|
||||||
|
@ -173,6 +196,27 @@ if __name__ == "__main__":
|
||||||
endgame['Game ID'] = "<a href='https://hanab.live/replay/{}'>{}</a>".format(game_id, game_id)
|
endgame['Game ID'] = "<a href='https://hanab.live/replay/{}'>{}</a>".format(game_id, game_id)
|
||||||
writer.writerow(endgame)
|
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 = pandas.read_csv("games.csv")
|
||||||
a.to_html("games.html", escape=False)
|
a.to_html("games.html", escape=False)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue