@@ -31,7 +31,12 @@ def load_result(self, file_path: Path) -> BenchmarkRun:
31
31
else :
32
32
return None
33
33
34
- def load (self , n : int ):
34
+ def load (self ):
35
+ """
36
+ Load benchmark runs from the results directory.
37
+ This method loads files after the specified archiving criteria,
38
+ sorts them by timestamp, and stores the results in self.runs.
39
+ """
35
40
results_dir = Path (self .dir ) / "results"
36
41
if not results_dir .exists () or not results_dir .is_dir ():
37
42
log .warning (
@@ -42,20 +47,52 @@ def load(self, n: int):
42
47
# Get all JSON files in the results directory
43
48
benchmark_files = list (results_dir .glob ("*.json" ))
44
49
45
- # Extract timestamp and sort files by it
50
+ # Extract timestamp
46
51
def extract_timestamp (file_path : Path ) -> str :
47
52
try :
48
53
# Assumes results are stored as <name>_YYYYMMDD_HHMMSS.json
49
54
ts = file_path .stem [- len ("YYYYMMDD_HHMMSS" ) :]
50
55
return ts if Validate .timestamp (ts ) else ""
51
56
except IndexError :
52
57
return ""
53
-
58
+
59
+ baseline_drop_after = options .archive_baseline_days * 3
60
+ pr_drop_after = options .archive_pr_days * 3
61
+ baseline_cutoff_date = datetime .now (timezone .utc ) - timedelta (days = baseline_drop_after )
62
+ log .debug (f"Baseline cutoff date: { baseline_cutoff_date } " )
63
+ pr_cutoff_date = datetime .now (timezone .utc ) - timedelta (days = pr_drop_after )
64
+ log .debug (f"PR cutoff date: { pr_cutoff_date } " )
65
+
66
+ # Filter out files that exceed archiving criteria three times the specified days
67
+ def is_file_too_old (file_path : Path ) -> bool :
68
+ try :
69
+ if file_path .stem .startswith ("Baseline_" ):
70
+ cutoff_date = baseline_cutoff_date
71
+ else :
72
+ cutoff_date = pr_cutoff_date
73
+
74
+ timestamp_str = extract_timestamp (file_path )
75
+ if not timestamp_str :
76
+ return False
77
+
78
+ file_timestamp = datetime .strptime (timestamp_str , "%Y%m%d_%H%M%S" )
79
+ # Add timezone info for proper comparison
80
+ file_timestamp = file_timestamp .replace (tzinfo = timezone .utc )
81
+ return file_timestamp < cutoff_date
82
+ except Exception as e :
83
+ log .warning (f"Error processing timestamp for { file_path .name } : { e } " )
84
+ return False
85
+
86
+ benchmark_files = [
87
+ file for file in benchmark_files if not is_file_too_old (file )
88
+ ]
89
+
90
+ # Sort files by timestamp
54
91
benchmark_files .sort (key = extract_timestamp , reverse = True )
55
92
56
- # Load the first n benchmark files
93
+ # Load benchmark files
57
94
benchmark_runs = []
58
- for file_path in benchmark_files [: n ] :
95
+ for file_path in benchmark_files :
59
96
benchmark_run = self .load_result (file_path )
60
97
if benchmark_run :
61
98
benchmark_runs .append (benchmark_run )
0 commit comments