health_assessment_publish.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python
  2. """把 hdkg 批次产物发布到平台共享结果根目录(只读接口读取的位置)。
  3. 批次目录形如 <batch-root>/<field>/<period>/{detail,report,registration.json},
  4. 发布后变为 <out-root>/<field>/<period>/...,与 HDKG_OUT_ROOT 对齐。
  5. 说明:本脚本不做 MinIO 上传、不写平台 MySQL;平台若要登记 analysis_general_file,
  6. 由现有导入任务或后续 MinIO 导入脚本完成。这里先保证“结果可被页面读取”。
  7. """
  8. from __future__ import annotations
  9. import argparse
  10. import json
  11. import shutil
  12. from pathlib import Path
  13. def main() -> int:
  14. ap = argparse.ArgumentParser()
  15. ap.add_argument("--batch-root", required=True)
  16. ap.add_argument("--out-root", required=True)
  17. args = ap.parse_args()
  18. batch = Path(args.batch_root)
  19. reg_path = batch / "registration.json"
  20. if not reg_path.is_file():
  21. raise SystemExit(f"没有 registration.json: {reg_path}")
  22. reg = json.loads(reg_path.read_text(encoding="utf-8"))
  23. if reg.get("status") != "ok":
  24. raise SystemExit(f"批次状态不是 ok: {reg.get('status')} {reg.get('error')}")
  25. field = reg.get("fieldCode")
  26. period = reg.get("period")
  27. if not field or not period:
  28. raise SystemExit("registration.json 缺 fieldCode/period")
  29. if not (batch / "detail" / "health.json").is_file():
  30. raise SystemExit("缺 detail/health.json")
  31. target = Path(args.out_root) / field / period
  32. target.mkdir(parents=True, exist_ok=True)
  33. for name in ("detail", "report", "logs"):
  34. src = batch / name
  35. if src.is_dir():
  36. shutil.copytree(src, target / name, dirs_exist_ok=True)
  37. for name in ("check_result.csv", "healthscores_check.csv", "registration.json"):
  38. src = batch / name
  39. if src.is_file():
  40. shutil.copy2(src, target / name)
  41. print(f"published {field}/{period} -> {target}")
  42. return 0
  43. if __name__ == "__main__":
  44. raise SystemExit(main())