| 25 | |
| 26 | |
| 27 | class Instance(BaseModel): |
| 28 | player_name: str |
| 29 | round_number: int |
| 30 | tournament_name: str |
| 31 | trajectory_path: Path |
| 32 | |
| 33 | @property |
| 34 | def game_name(self) -> str: |
| 35 | return self.tournament_name.split(".")[1] |
| 36 | |
| 37 | @property |
| 38 | def instance_id(self) -> str: |
| 39 | return f"{self.tournament_name}__{self.player_name}__r{self.round_number}" |
| 40 | |
| 41 | @property |
| 42 | def tournament_path(self) -> Path: |
| 43 | return self.trajectory_path.parent.parent.parent |
| 44 | |
| 45 | @property |
| 46 | def metadata_path(self) -> Path: |
| 47 | return self.tournament_path / "metadata.json" |
| 48 | |
| 49 | def get_lm_name_self_opponent(self) -> tuple[str, str]: |
| 50 | metadata = json.loads(self.metadata_path.read_text()) |
| 51 | player_configs = metadata["config"]["players"] |
| 52 | player_config = [pc for pc in player_configs if pc["name"] == self.player_name][0] |
| 53 | other_player_config = [pc for pc in player_configs if pc["name"] != self.player_name][0] |
| 54 | return player_config["config"]["model"]["model_name"].removeprefix("@"), other_player_config["config"]["model"][ |
| 55 | "model_name" |
| 56 | ].removeprefix("@") |
| 57 | |
| 58 | def get_current_next_round_win_rate(self) -> tuple[float | None, float | None]: |
| 59 | metadata = json.loads(self.metadata_path.read_text()) |
| 60 | current_round_stats = metadata["round_stats"].get(str(self.round_number)) |
| 61 | next_round_stats = metadata["round_stats"].get(str(self.round_number + 1)) |
| 62 | current_win_rate = None |
| 63 | next_win_rate = None |
| 64 | if current_round_stats is not None: |
| 65 | current_win_rate = get_scores(current_round_stats).get(self.player_name) |
| 66 | if next_round_stats is not None: |
| 67 | next_win_rate = get_scores(next_round_stats).get(self.player_name) |
| 68 | return current_win_rate, next_win_rate |
| 69 | |
| 70 | |
| 71 | class InstanceBatch(BaseModel): |
no outgoing calls
no test coverage detected