Skip to content

Commit 4b9c055

Browse files
committed
Add toggle to show only the latest run per system
1 parent 3c0c995 commit 4b9c055

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

apps/analysis.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import html
1313
import json
1414
import os
15+
import re
1516
from pathlib import Path
1617

1718
import pandas as pd
@@ -101,6 +102,28 @@ def get_run_directories(output_dir: Path) -> list[Path]:
101102
return sorted(run_dirs, key=lambda d: d.name, reverse=True)
102103

103104

105+
def _system_name_from_run(run_dir: Path) -> str:
106+
"""Extract the system name from a run folder name (<timestamp>_<system_name>)."""
107+
m = re.match(r"^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}\.\d+_(.+)$", run_dir.name)
108+
return m.group(1) if m else run_dir.name
109+
110+
111+
def filter_latest_runs(run_dirs: list[Path]) -> list[Path]:
112+
"""Keep only the most recent run per system name.
113+
114+
Assumes run_dirs is already sorted newest-first (as returned by
115+
get_run_directories), so the first occurrence of each system name wins.
116+
"""
117+
seen: set[str] = set()
118+
result = []
119+
for d in run_dirs:
120+
system = _system_name_from_run(d)
121+
if system not in seen:
122+
seen.add(system)
123+
result.append(d)
124+
return result
125+
126+
104127
def get_record_directories(run_dir: Path) -> list[Path]:
105128
"""Get all record directories in a run, sorted by record ID."""
106129
records_dir = run_dir / "records"
@@ -1762,6 +1785,10 @@ def main():
17621785

17631786
run_dirs = [rd for od in output_dirs for rd in get_run_directories(od)]
17641787

1788+
latest_only = st.sidebar.toggle("Latest run per system only", value=True)
1789+
if latest_only:
1790+
run_dirs = filter_latest_runs(run_dirs)
1791+
17651792
if not run_dirs:
17661793
st.error(f"No run directories found in: {', '.join(str(d) for d in output_dirs)}")
17671794
return

0 commit comments

Comments
 (0)