Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions devops/scripts/benchmarks/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ def load(self, n: int):
benchmark_files = list(results_dir.glob("*.json"))

# Extract timestamp and sort files by it
def extract_timestamp(file_path: Path) -> str:
def extract_timestamp(file_path: Path) -> datetime:
try:
# Assumes results are stored as <name>_YYYYMMDD_HHMMSS.json
ts = file_path.stem[-len("YYYYMMDD_HHMMSS") :]
return ts if Validate.timestamp(ts) else ""
except IndexError:
return ""
if Validate.timestamp(ts):
return datetime.strptime(ts, "%Y%m%d_%H%M%S")
return datetime.fromtimestamp(0) # Default to epoch if invalid
except (IndexError, ValueError):
return datetime.fromtimestamp(0) # Default to epoch if exception

benchmark_files.sort(key=extract_timestamp, reverse=True)

Expand Down
Loading