1919# Global variable to store the directory to search for logs
2020LOG_BASE_DIR = Path .cwd () / "logs"
2121
22+ # Global flag to indicate if we're running in static mode
23+ STATIC_MODE = False
24+
2225
2326@dataclass
2427class AgentInfo :
@@ -35,6 +38,17 @@ def set_log_base_directory(directory: str | Path):
3538 LOG_BASE_DIR = Path (directory ).resolve ()
3639
3740
41+ def set_static_mode (enabled : bool = True ):
42+ """Enable or disable static mode"""
43+ global STATIC_MODE
44+ STATIC_MODE = enabled
45+
46+
47+ def is_static_mode () -> bool :
48+ """Check if we're running in static mode"""
49+ return STATIC_MODE
50+
51+
3852def is_game_folder (log_dir : Path ) -> bool :
3953 """Check if a directory contains metadata.json and is therefore a game folder"""
4054 metadata_file = log_dir / "metadata.json"
@@ -705,6 +719,48 @@ def index():
705719 metadata = metadata ,
706720 trajectories_by_round = trajectories_by_round ,
707721 analysis_data = analysis_data ,
722+ is_static = STATIC_MODE ,
723+ )
724+
725+
726+ @app .route ("/game/<path:folder_path>" )
727+ def game_view (folder_path ):
728+ """Static-friendly game viewer route using path parameters"""
729+ # Validate the selected folder exists and is a game folder
730+ logs_dir = LOG_BASE_DIR
731+ folder_path_obj = logs_dir / folder_path
732+
733+ if not folder_path_obj .exists () or not is_game_folder (folder_path_obj ):
734+ return redirect (url_for ("game_picker" ))
735+
736+ # Parse the selected game
737+ parser = LogParser (folder_path_obj )
738+ metadata = parser .parse_game_metadata ()
739+ available_trajectories = parser .get_available_trajectories ()
740+
741+ # Group trajectories by round
742+ trajectories_by_round = {}
743+ for player_name , round_num in available_trajectories :
744+ if round_num not in trajectories_by_round :
745+ trajectories_by_round [round_num ] = []
746+ trajectory = parser .parse_trajectory (player_name , round_num )
747+ if trajectory :
748+ trajectories_by_round [round_num ].append (trajectory )
749+
750+ # Get analysis data
751+ analysis_data = parser .analyze_line_counts ()
752+
753+ # Get the full path of the selected folder
754+ selected_folder_path = str (folder_path_obj )
755+
756+ return render_template (
757+ "index.html" ,
758+ selected_folder = folder_path ,
759+ selected_folder_path = selected_folder_path ,
760+ metadata = metadata ,
761+ trajectories_by_round = trajectories_by_round ,
762+ analysis_data = analysis_data ,
763+ is_static = STATIC_MODE ,
708764 )
709765
710766
@@ -714,7 +770,7 @@ def game_picker():
714770 logs_dir = LOG_BASE_DIR
715771 game_folders = find_all_game_folders (logs_dir )
716772
717- return render_template ("picker.html" , game_folders = game_folders , base_dir = str (logs_dir ))
773+ return render_template ("picker.html" , game_folders = game_folders , base_dir = str (logs_dir ), is_static = STATIC_MODE )
718774
719775
720776@app .route ("/delete-experiment" , methods = ["POST" ])
0 commit comments