66from pathlib import Path
77from typing import Any
88
9+ from aet .tracking import reports
910from aet .tracking .types import TrackingConfig , TRACKING_MODES
1011from aet .tracking .local_backend import LocalBackend
1112from aet .tracking .mlflow_backend import MLflowBackend
@@ -1007,48 +1008,18 @@ def log_human_override(
10071008 # Utility writers
10081009
10091010 def write_run_record (self , extra : dict | None = None ) -> Path :
1010- """Write run_record.json to the run_path root. Returns the path."""
1011- from datetime import datetime , timezone
1012- run_path = self ._config .run_path
1013- run_path .mkdir (parents = True , exist_ok = True )
1014- record : dict = {
1015- "schema_version" : "1.1" ,
1016- "run_id" : self ._config .run_id ,
1017- "project" : self ._config .project ,
1018- "suite" : self ._config .suite ,
1019- "target" : self ._config .target ,
1020- "method" : self ._config .method ,
1021- "seed" : self ._config .seed ,
1022- "tracking_mode" : self ._config .mode ,
1023- "created_at" : datetime .now (tz = timezone .utc ).isoformat (),
1024- }
1025- if extra :
1026- record .update (extra )
1027- import json
1028- path = run_path / "run_record.json"
1029- path .write_text (json .dumps (record , indent = 2 , default = str ))
1030- return path
1011+ """Write `run_record.json` at the run root (see :mod:`aet.tracking.reports`)."""
1012+ c = self ._config
1013+ return reports .write_run_record (
1014+ c .run_path , run_id = c .run_id , project = c .project , suite = c .suite , target = c .target ,
1015+ method = c .method , seed = c .seed , mode = c .mode , extra = extra )
10311016
10321017 def write_summary_metrics (self , extra : dict | None = None ) -> Path :
1033- """Write metrics/summary_metrics.json. Returns the path."""
1034- from datetime import datetime , timezone
1035- import json
1036- metrics_dir = self ._config .run_path / "metrics"
1037- metrics_dir .mkdir (parents = True , exist_ok = True )
1038- summary : dict = {
1039- "run_id" : self ._config .run_id ,
1040- "project" : self ._config .project ,
1041- "suite" : self ._config .suite ,
1042- "method" : self ._config .method ,
1043- "seed" : self ._config .seed ,
1044- "target" : self ._config .target ,
1045- "recorded_at" : datetime .now (tz = timezone .utc ).isoformat (),
1046- }
1047- if extra :
1048- summary .update (extra )
1049- path = metrics_dir / "summary_metrics.json"
1050- path .write_text (json .dumps (summary , indent = 2 , default = str ))
1051- return path
1018+ """Write `metrics/summary_metrics.json` (see :mod:`aet.tracking.reports`)."""
1019+ c = self ._config
1020+ return reports .write_summary_metrics (
1021+ c .run_path , run_id = c .run_id , project = c .project , suite = c .suite , method = c .method ,
1022+ seed = c .seed , target = c .target , extra = extra )
10521023
10531024 def write_eval_report (
10541025 self ,
@@ -1058,25 +1029,10 @@ def write_eval_report(
10581029 coverage : list [dict ] | None = None ,
10591030 extra : dict | None = None ,
10601031 ) -> Path :
1061- """Write eval_report.json: per-test, per-contract, per-assertion, coverage."""
1062- from datetime import datetime , timezone
1063- run_path = self ._config .run_path
1064- run_path .mkdir (parents = True , exist_ok = True )
1065- import json
1066- report : dict = {
1067- "schema_version" : "1.0" ,
1068- "run_id" : self ._config .run_id ,
1069- "generated_at" : datetime .now (tz = timezone .utc ).isoformat (),
1070- "tests" : tests ,
1071- "contracts" : contracts or [],
1072- "assertions" : assertions or [],
1073- "coverage" : coverage or [],
1074- }
1075- if extra :
1076- report .update (extra )
1077- path = run_path / "eval_report.json"
1078- path .write_text (json .dumps (report , indent = 2 , default = str ))
1079- return path
1032+ """Write `eval_report.json` (see :mod:`aet.tracking.reports`)."""
1033+ return reports .write_eval_report (
1034+ self ._config .run_path , run_id = self ._config .run_id , tests = tests , contracts = contracts ,
1035+ assertions = assertions , coverage = coverage , extra = extra )
10801036
10811037 def write_metrics_structured (
10821038 self ,
@@ -1085,24 +1041,10 @@ def write_metrics_structured(
10851041 process : dict ,
10861042 extra : dict | None = None ,
10871043 ) -> Path :
1088- """Write metrics.json with cost/quality/process structure per spec."""
1089- from datetime import datetime , timezone
1090- run_path = self ._config .run_path
1091- run_path .mkdir (parents = True , exist_ok = True )
1092- import json
1093- metrics : dict = {
1094- "schema_version" : "1.0" ,
1095- "run_id" : self ._config .run_id ,
1096- "generated_at" : datetime .now (tz = timezone .utc ).isoformat (),
1097- "cost" : cost ,
1098- "quality" : quality ,
1099- "process" : process ,
1100- }
1101- if extra :
1102- metrics .update (extra )
1103- path = run_path / "metrics.json"
1104- path .write_text (json .dumps (metrics , indent = 2 , default = str ))
1105- return path
1044+ """Write structured `metrics.json` (see :mod:`aet.tracking.reports`)."""
1045+ return reports .write_metrics_structured (
1046+ self ._config .run_path , run_id = self ._config .run_id , cost = cost , quality = quality ,
1047+ process = process , extra = extra )
11061048
11071049 # ------------------------------------------------------------------
11081050 def finish (self , status : str , message : str | None = None ) -> None :
0 commit comments