1111from options import Compare , options
1212from datetime import datetime , timezone
1313from utils .utils import run
14+ from utils .validate import Validate
1415
1516
1617class BenchmarkHistory :
@@ -30,15 +31,18 @@ def load_result(self, file_path: Path) -> BenchmarkRun:
3031 def load (self , n : int ):
3132 results_dir = Path (self .dir ) / "results"
3233 if not results_dir .exists () or not results_dir .is_dir ():
33- return []
34+ print (f"Warning: { results_dir } is not a valid directory: no historic results loaded." )
35+ return
3436
3537 # Get all JSON files in the results directory
3638 benchmark_files = list (results_dir .glob ("*.json" ))
3739
3840 # Extract timestamp and sort files by it
3941 def extract_timestamp (file_path : Path ) -> str :
4042 try :
41- return file_path .stem .split ("_" )[- 1 ]
43+ # Assumes results are stored as <name>_YYYYMMDD_HHMMSS.json
44+ ts = file_path .stem [- len ("YYYYMMDD_HHMMSS" ):]
45+ return ts if Validate .timestamp (ts ) else ""
4246 except IndexError :
4347 return ""
4448
@@ -98,7 +102,11 @@ def save(self, save_name, results: list[Result], to_file=True):
98102 os .makedirs (results_dir , exist_ok = True )
99103
100104 # Use formatted timestamp for the filename
101- timestamp = datetime .now ().strftime ("%Y%m%d_%H%M%S" )
105+ timestamp = (
106+ datetime .now ().strftime ("%Y%m%d_%H%M%S" )
107+ if options .timestamp_override is None else
108+ options .timestamp_override
109+ )
102110 file_path = Path (os .path .join (results_dir , f"{ save_name } _{ timestamp } .json" ))
103111 with file_path .open ("w" ) as file :
104112 json .dump (serialized , file , indent = 4 )
0 commit comments