#!/usr/bin/env python3 """Harbor wrapper for the timeline metric_v2 scorer.""" import argparse import json from pathlib import Path import sys HERE = Path(__file__).resolve().parent def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--prediction', type=Path, default=Path('/app/timeline.json')) parser.add_argument('--output-dir', type=Path, default=Path('/logs/verifier')) args = parser.parse_args() args.output_dir.mkdir(parents=True, exist_ok=True) for name in ['reward.json', 'metrics.json']: (args.output_dir / name).unlink(missing_ok=True) sys.path.insert(0, str(HERE / 'evaluator')) import benchmark import metric_v2 study = json.loads((HERE / 'study.json').read_text()) gold_path = HERE / 'gold.json' if benchmark.digest(gold_path) != study['gold_sha256']: raise ValueError('Gold hash mismatch: ' + study['id']) prediction = json.loads(args.prediction.read_text()) if args.prediction.exists() else {} report = metric_v2.score(prediction, json.loads(gold_path.read_text()), metric_v2.load_reference(study['id'])) report['study_id'] = study['id'] report['missing_prediction'] = not args.prediction.exists() report['prediction_sha256'] = benchmark.digest(args.prediction) if args.prediction.exists() else None components = report['components'] rewards = {'reward': report['score'], 'epochs_accuracy': components['epochs']['score'], **{key + '_f1': components[key]['f1'] for key in ['encounters', 'activities', 'timing']}} (args.output_dir / 'metrics.json').write_text(json.dumps(report, indent=2, allow_nan=False)) (args.output_dir / 'reward.json').write_text(json.dumps(rewards, indent=2, allow_nan=False)) print(json.dumps(rewards)) if __name__ == '__main__': main()