Skip to content

Commit 2f72ff9

Browse files
committed
Enh: Save configs for every object
1 parent 514c510 commit 2f72ff9

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

codeclash/agents/abstract.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import time
23
import uuid
34
from abc import ABC, abstractmethod
45

@@ -37,6 +38,8 @@ def __init__(
3738
"player_unique_id": self._player_unique_id,
3839
"diff": {0: ""}, # mapping round -> diff
3940
"incremental_diff": {0: ""}, # mapping round -> diff
41+
"created_timestamp": int(time.time()),
42+
"config": self.config,
4043
}
4144

4245
# --- Main methods ---

codeclash/games/abstract.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import json
21
import os
32
import subprocess
3+
import time
44
from abc import ABC, abstractmethod
55
from pathlib import Path
66

@@ -32,21 +32,28 @@ def __init__(self, config: dict, *, tournament_id: str, local_output_dir: Path):
3232
self.url_gh: str = f"git@github.com:{GH_ORG}/{self.name}.git"
3333
self.artifacts: list[Path] = []
3434
"""Artifact objects that we might want to clean up after the game."""
35-
self.game_config: dict = config["game"]
3635
self.config: dict = config
37-
self.game_id: str = tournament_id
36+
self._metadata: dict = {
37+
"name": self.name,
38+
"config": self.config["game"],
39+
"game_id": tournament_id,
40+
"created_timestamp": int(time.time()),
41+
}
3842
self.log_env: Path = (DIR_WORK / DIR_LOGS / self.game_id).resolve()
3943
self.log_local: Path = local_output_dir
4044
self.logger = get_logger(
4145
self.name, log_path=self.log_local / "game.log", emoji="🏓"
4246
)
4347
self.environment: DockerEnvironment = self.get_environment()
4448
"""The running docker environment for executing the game"""
45-
self._metadata: dict = {
46-
"name": self.name,
47-
"config": self.config,
48-
"game_id": self.game_id,
49-
}
49+
50+
@property
51+
def game_config(self) -> dict:
52+
return self.config["game"]
53+
54+
@property
55+
def game_id(self) -> str:
56+
return self._metadata["game_id"]
5057

5158
@property
5259
def image_name(self) -> str:

codeclash/tournaments/abstract.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def __init__(self, config: dict, *, name: str, **kwargs):
1919
self._metadata: dict = {
2020
"name": self.name,
2121
"tournament_id": self.tournament_id,
22+
"config": self.config,
23+
"created_timestamp": int(time.time()),
2224
}
2325
self.logger = get_logger(
2426
self.name, log_path=self.local_output_dir / "tournament.log", emoji="🏆"

0 commit comments

Comments
 (0)