Skip to content

Commit 3f5c024

Browse files
committed
Update win rate calc
1 parent 4e02517 commit 3f5c024

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

codeclash/ratings/win_rate.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,38 +28,38 @@ def main(log_dir: Path):
2828
# - game.log
2929
# - metadata.json
3030
model_profiles = {}
31-
for user_folder in log_dir.iterdir():
32-
print(f"Processing games under user `{user_folder.name}`")
33-
for game_log_folder in tqdm(list(user_folder.iterdir())):
34-
if not game_log_folder.is_dir():
35-
continue
36-
game_id = game_log_folder.name.split(".")[1]
37-
player_ids = [x.name for x in (game_log_folder / "players").iterdir() if x.is_dir()]
38-
metadata = json.load(open(game_log_folder / "metadata.json"))
39-
player_to_model = {x["name"]: x["config"]["model"]["model_name"] for x in metadata["config"]["players"]}
40-
print(player_to_model)
41-
num_rounds = len(metadata["round_stats"])
31+
for game_log_folder in tqdm([x.parent for x in log_dir.rglob("game.log")]):
32+
game_id = game_log_folder.name.split(".")[1]
33+
player_ids = [x.name for x in (game_log_folder / "players").iterdir() if x.is_dir()]
34+
metadata = json.load(open(game_log_folder / "metadata.json"))
35+
try:
36+
player_to_model = {
37+
x["name"]: x["config"]["model"]["model_name"].strip("@") for x in metadata["config"]["players"]
38+
}
39+
except KeyError:
40+
continue
41+
num_rounds = len(metadata["round_stats"])
4242

43-
# Only count each unique model once per game
44-
unique_models = {player_to_model[player] for player in player_ids}
45-
for model_name in unique_models:
46-
k = f"{game_id}.{model_name}"
47-
if k in model_profiles:
48-
model_profiles[k].count += num_rounds
49-
else:
50-
# Use the first player_id that matches this model_name for display
51-
player_id = next(pid for pid in player_ids if player_to_model[pid] == model_name)
52-
model_profiles[k] = PlayerGameProfile(
53-
player_id=player_id, model_name=model_name, game_id=game_id, count=num_rounds
54-
)
43+
# Only count each unique model once per game
44+
unique_models = {player_to_model[player] for player in player_ids}
45+
for model_name in unique_models:
46+
k = f"{game_id}.{model_name}"
47+
if k in model_profiles:
48+
model_profiles[k].count += num_rounds
49+
else:
50+
# Use the first player_id that matches this model_name for display
51+
player_id = next(pid for pid in player_ids if player_to_model[pid] == model_name)
52+
model_profiles[k] = PlayerGameProfile(
53+
player_id=player_id, model_name=model_name, game_id=game_id, count=num_rounds
54+
)
5555

56-
for round, details in metadata["round_stats"].items():
57-
if round == "0":
58-
# Skip initial round
59-
continue
60-
winner = details["winner"]
61-
if winner != RESULT_TIE:
62-
model_profiles[f"{game_id}.{player_to_model[winner]}"].wins += 1
56+
for round, details in metadata["round_stats"].items():
57+
if round == "0":
58+
# Skip initial round
59+
continue
60+
winner = details["winner"]
61+
if winner != RESULT_TIE:
62+
model_profiles[f"{game_id}.{player_to_model[winner]}"].wins += 1
6363

6464
print("Player profiles:")
6565
for profile in model_profiles.values():

0 commit comments

Comments
 (0)