Skip to content

Commit 68a4c45

Browse files
committed
Fix viewer for not having rounds/ available anymore
1 parent fbdff8f commit 68a4c45

3 files changed

Lines changed: 63 additions & 46 deletions

File tree

.cursor/rules/viewer.mdc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ Here's how the metadata.json file looks like:
105105
{
106106
"name": "PvpTournament",
107107
"tournament_id": "PvpTournament.BattleSnake.250915203207",
108+
"round_stats": {
109+
"0": {
110+
"round_num": 0,
111+
"winner": "p2",
112+
"scores": {
113+
"p2": 10,
114+
"p1": 9,
115+
"Tie": 1
116+
},
117+
"player_stats": {
118+
"p2": {
119+
"name": "p2",
120+
"invalid_reason": null,
121+
"score": 10,
122+
"valid_submit": true
123+
},
124+
"p1": {
125+
"name": "p1",
126+
"invalid_reason": null,
127+
"score": 9,
128+
"valid_submit": true
129+
}
130+
}
131+
},
108132
"config": {
109133
"tournament": {
110134
"rounds": 10

codeclash/viewer/app.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -331,34 +331,46 @@ def parse_game_metadata(self) -> GameMetadata:
331331
main_log = main_log_file.read_text() if main_log_file.exists() else "No tournament log found"
332332
main_log_path = str(main_log_file) if main_log_file.exists() else ""
333333

334-
# Parse round directories and their sim logs
334+
# Parse round data - prioritize round_stats from metadata.json
335335
rounds = []
336-
rounds_dir = self.log_dir / "rounds"
337-
if rounds_dir.exists():
338-
# Get all round directories (sorted numerically)
339-
round_dirs = sorted([d for d in rounds_dir.iterdir() if d.is_dir()], key=lambda x: int(x.name))
340-
341-
for round_dir in round_dirs:
342-
round_num = int(round_dir.name)
343-
344-
# Collect all sim logs for this round
345-
sim_logs = []
346-
sim_files = sorted(round_dir.glob("sim_*.log"), key=lambda x: int(x.stem.split("_")[1]))
347-
348-
for sim_file in sim_files:
349-
sim_content = sim_file.read_text()
350-
sim_logs.append({"filename": sim_file.name, "content": sim_content, "full_path": str(sim_file)})
351-
352-
# Check for round results
353-
results_file = round_dir / "results.json"
354-
round_results = None
355-
if results_file.exists():
356-
round_results = json.loads(results_file.read_text())
357-
# Get agent info for this round (we'll need to get it from metadata)
358-
agent_info = get_agent_info_from_metadata(results) if results else []
359-
round_results = process_round_results(round_results, agent_info)
360-
361-
rounds.append({"round_num": round_num, "sim_logs": sim_logs, "results": round_results})
336+
337+
# First, try to get round data from metadata.json round_stats
338+
if "round_stats" in results:
339+
# Get agent info for processing round results
340+
agent_info = get_agent_info_from_metadata(results) if results else []
341+
342+
# Process each round from round_stats
343+
for round_key, round_data in results["round_stats"].items():
344+
round_num = int(round_key)
345+
346+
# Process the round results from metadata
347+
round_results = process_round_results(round_data, agent_info)
348+
349+
rounds.append({"round_num": round_num, "sim_logs": [], "results": round_results})
350+
351+
else:
352+
# Fallback: Parse round directories and their sim logs (for older games)
353+
rounds_dir = self.log_dir / "rounds"
354+
if rounds_dir.exists():
355+
# Get all round directories (sorted numerically)
356+
round_dirs = sorted([d for d in rounds_dir.iterdir() if d.is_dir()], key=lambda x: int(x.name))
357+
358+
for round_dir in round_dirs:
359+
round_num = int(round_dir.name)
360+
361+
# Check for round results
362+
results_file = round_dir / "results.json"
363+
round_results = None
364+
if results_file.exists():
365+
round_results = json.loads(results_file.read_text())
366+
# Get agent info for this round (we'll need to get it from metadata)
367+
agent_info = get_agent_info_from_metadata(results) if results else []
368+
round_results = process_round_results(round_results, agent_info)
369+
370+
rounds.append({"round_num": round_num, "sim_logs": [], "results": round_results})
371+
372+
# Sort rounds by round number to ensure consistent ordering
373+
rounds.sort(key=lambda x: x["round_num"])
362374

363375
# Extract agent information
364376
agent_info = get_agent_info_from_metadata(results) if results else []

codeclash/viewer/templates/includes/rounds.html

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,6 @@ <h2>🎯 Detailed Rounds</h2>
1515
{% endfor %}
1616
{% endif %}
1717

18-
<!-- Round Simulation Logs -->
19-
<details class="foldout round-foldout">
20-
<summary>🎮 Round {{ round_num }} Simulation Logs ({{ round_data.sim_logs|length }} sims)</summary>
21-
<div class="log-content">
22-
{% for sim_log in round_data.sim_logs %}
23-
<details class="foldout sim-foldout">
24-
<summary>
25-
{{ sim_log.filename }}
26-
<button class="copy-path-btn-small" data-path="{{ sim_log.full_path }}" title="Copy file path">
27-
📋 Copy path
28-
</button>
29-
</summary>
30-
<div class="log-content">
31-
<pre><code>{{ sim_log.content }}</code></pre>
32-
</div>
33-
</details>
34-
{% endfor %}
35-
</div>
36-
</details>
3718

3819
<!-- Round Results (if available) -->
3920
{% if round_data.results %}

0 commit comments

Comments
 (0)