49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
if str(ROOT) not in sys.path:
|
|
sys.path.insert(0, str(ROOT))
|
|
|
|
from src.services.research_council import CouncilOptimizationReviewService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = int(env.get("RESEARCH_COUNCIL_INSTRUMENT_ID", "1"))
|
|
limit = int(env.get("RESEARCH_COUNCIL_REVIEW_LIMIT", "5"))
|
|
stale_after_hours = float(env.get("RESEARCH_COUNCIL_STALE_AFTER_HOURS", "24"))
|
|
output_json = _get_bool(env, "RESEARCH_COUNCIL_OUTPUT_JSON", False)
|
|
payload = CouncilOptimizationReviewService().build_review(
|
|
instrument_id=instrument_id,
|
|
limit=limit,
|
|
stale_after_hours=stale_after_hours,
|
|
)
|
|
payload["passed"] = bool(payload.get("present")) and payload.get("health_state") != "missing"
|
|
_print_payload(payload, output_json=output_json)
|
|
return 0 if payload["passed"] else 2
|
|
|
|
|
|
def _print_payload(payload: dict, *, output_json: bool) -> None:
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
return
|
|
print(f"Research council optimization review for instrument {payload.get('instrument_id')}")
|
|
print(f"Health: {payload.get('health_state')}")
|
|
print(f"Summary: {payload.get('operator_summary')}")
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool) -> bool:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return str(value).strip().lower() in {"1", "true", "yes", "on"}
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|