aboutsummaryrefslogtreecommitdiff
path: root/benchmark/agbenchmark/reports/processing/get_files.py
diff options
context:
space:
mode:
Diffstat (limited to 'benchmark/agbenchmark/reports/processing/get_files.py')
-rw-r--r--benchmark/agbenchmark/reports/processing/get_files.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/benchmark/agbenchmark/reports/processing/get_files.py b/benchmark/agbenchmark/reports/processing/get_files.py
new file mode 100644
index 000000000..67ea46ce9
--- /dev/null
+++ b/benchmark/agbenchmark/reports/processing/get_files.py
@@ -0,0 +1,34 @@
+import os
+
+
+def get_last_subdirectory(directory_path: str) -> str | None:
+ # Get all subdirectories in the directory
+ subdirs = [
+ os.path.join(directory_path, name)
+ for name in os.listdir(directory_path)
+ if os.path.isdir(os.path.join(directory_path, name))
+ ]
+
+ # Sort the subdirectories by creation time
+ subdirs.sort(key=os.path.getctime)
+
+ # Return the last subdirectory in the list
+ return subdirs[-1] if subdirs else None
+
+
+def get_latest_report_from_agent_directories(
+ directory_path: str,
+) -> list[tuple[os.DirEntry[str], str]]:
+ latest_reports = []
+
+ for subdir in os.scandir(directory_path):
+ if subdir.is_dir():
+ # Get the most recently created subdirectory within this agent's directory
+ latest_subdir = get_last_subdirectory(subdir.path)
+ if latest_subdir is not None:
+ # Look for 'report.json' in the subdirectory
+ report_file = os.path.join(latest_subdir, "report.json")
+ if os.path.isfile(report_file):
+ latest_reports.append((subdir, report_file))
+
+ return latest_reports