@@ -41,6 +41,38 @@ def get_round_count_from_metadata(log_dir: Path) -> int | None:
4141 return None
4242
4343
44+ def get_models_from_metadata (log_dir : Path ) -> list [str ]:
45+ """Extract model names from metadata.json if it exists"""
46+ metadata_file = log_dir / "metadata.json"
47+ if not metadata_file .exists ():
48+ return []
49+
50+ try :
51+ metadata = json .loads (metadata_file .read_text ())
52+ models = []
53+ players_config = metadata .get ("config" , {}).get ("players" , [])
54+
55+ # Handle both list and dict formats
56+ if isinstance (players_config , list ):
57+ # If players is a list, iterate through each player
58+ for player_config in players_config :
59+ if isinstance (player_config , dict ):
60+ model_name = player_config .get ("config" , {}).get ("model" , {}).get ("model_name" )
61+ if model_name and model_name not in models :
62+ models .append (model_name )
63+ elif isinstance (players_config , dict ):
64+ # If players is a dict, iterate through player keys (p1, p2, etc.)
65+ for _player_key , player_config in players_config .items ():
66+ if isinstance (player_config , dict ):
67+ model_name = player_config .get ("config" , {}).get ("model" , {}).get ("model_name" )
68+ if model_name and model_name not in models :
69+ models .append (model_name )
70+
71+ return models
72+ except (json .JSONDecodeError , KeyError , AttributeError ):
73+ return []
74+
75+
4476def find_all_game_folders (base_dir : Path ) -> list [dict [str , Any ]]:
4577 """Recursively find all folders and mark which ones contain metadata.json"""
4678 all_folders = []
@@ -60,12 +92,14 @@ def scan_directory(directory: Path, relative_path: str = ""):
6092 # Check if this directory is a game folder
6193 if is_game_folder (item ):
6294 round_count = get_round_count_from_metadata (item )
95+ models = get_models_from_metadata (item )
6396 game_folders .add (current_relative )
6497 all_folders .append (
6598 {
6699 "name" : current_relative ,
67100 "full_path" : str (item ),
68101 "round_count" : round_count ,
102+ "models" : models ,
69103 "is_game" : True ,
70104 "depth" : depth ,
71105 "parent" : relative_path if relative_path else None ,
@@ -78,6 +112,7 @@ def scan_directory(directory: Path, relative_path: str = ""):
78112 "name" : current_relative ,
79113 "full_path" : str (item ),
80114 "round_count" : None ,
115+ "models" : [],
81116 "is_game" : False ,
82117 "depth" : depth ,
83118 "parent" : relative_path if relative_path else None ,
0 commit comments