Skip to content

Commit 9698b2e

Browse files
committed
Enh(viewer): Allow to view different directories
1 parent 577955e commit 9698b2e

3 files changed

Lines changed: 36 additions & 7 deletions

File tree

codeclash/viewer/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
A Flask-based web application to visualize AI agent game trajectories
55
"""
66

7-
from .app import app
7+
from .app import app, set_log_base_directory
88

9-
__all__ = ["app"]
9+
__all__ = ["app", "set_log_base_directory"]

codeclash/viewer/app.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212

1313
from flask import Flask, jsonify, render_template, request
1414

15+
# Global variable to store the directory to search for logs
16+
LOG_BASE_DIR = Path.cwd() / "logs"
17+
18+
19+
def set_log_base_directory(directory: str | Path):
20+
"""Set the logs directory directly"""
21+
global LOG_BASE_DIR
22+
LOG_BASE_DIR = Path(directory).resolve()
23+
1524

1625
@dataclass
1726
class GameMetadata:
@@ -139,9 +148,8 @@ def nl2br(value):
139148
@app.route("/")
140149
def index():
141150
"""Main viewer page"""
142-
# Get available log directories (relative to project root)
143-
project_root = Path(__file__).parent.parent.parent
144-
logs_dir = project_root / "logs"
151+
# Get available log directories
152+
logs_dir = LOG_BASE_DIR
145153
log_folders = []
146154
if logs_dir.exists():
147155
log_folders = [d.name for d in logs_dir.iterdir() if d.is_dir()]
@@ -183,8 +191,7 @@ def trajectory_detail(player_id: int, round_num: int):
183191
if not selected_folder:
184192
return jsonify({"error": "No folder specified"})
185193

186-
project_root = Path(__file__).parent.parent.parent
187-
logs_dir = project_root / "logs"
194+
logs_dir = LOG_BASE_DIR
188195
parser = LogParser(logs_dir / selected_folder)
189196
trajectory = parser.parse_trajectory(player_id, round_num)
190197

run_viewer.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@
33
Launch script for the CodeClash Trajectory Viewer
44
"""
55

6+
import argparse
7+
from pathlib import Path
8+
69
if __name__ == "__main__":
10+
parser = argparse.ArgumentParser(description="CodeClash Trajectory Viewer")
11+
parser.add_argument(
12+
"-d",
13+
"--directory",
14+
type=str,
15+
default=None,
16+
help="Logs directory to search for game trajectories (defaults to ./logs)",
17+
)
18+
19+
args = parser.parse_args()
20+
721
from codeclash.viewer import app
22+
from codeclash.viewer.app import set_log_base_directory
23+
24+
# Set the logs directory if provided
25+
if args.directory:
26+
set_log_base_directory(args.directory)
27+
print(f"📁 Using logs directory: {Path(args.directory).resolve()}")
28+
else:
29+
print(f"📁 Using logs directory: {Path.cwd() / 'logs'}")
830

931
print("🎮 Starting CodeClash Trajectory Viewer...")
1032
print("📊 Navigate to http://localhost:5001 to view game trajectories")

0 commit comments

Comments
 (0)