76 lines
2.8 KiB
Python
76 lines
2.8 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 ResearchCouncilService
|
|
from src.services.trust import ModelTrustService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = int(env.get("RESEARCH_COUNCIL_INSTRUMENT_ID", "1"))
|
|
timeframe = env.get("RESEARCH_COUNCIL_TIMEFRAME", "1m")
|
|
output_json = _get_bool(env, "RESEARCH_COUNCIL_OUTPUT_JSON", False)
|
|
model_codes = _resolve_model_codes(env=env, instrument_id=instrument_id)
|
|
service = ResearchCouncilService()
|
|
rows = []
|
|
for model_code in model_codes:
|
|
preview = service.build_preview(instrument_id=instrument_id, timeframe=timeframe, model_code=model_code)
|
|
decision = dict(preview.get("decision") or {})
|
|
context = dict(preview.get("context") or {})
|
|
rows.append(
|
|
{
|
|
"model_code": model_code,
|
|
"overall_stance": decision.get("overall_stance"),
|
|
"committee_confidence": decision.get("committee_confidence"),
|
|
"follow_up_check_count": len(list(decision.get("follow_up_checks") or [])),
|
|
"disagreement_count": len(list(decision.get("disagreement_points") or [])),
|
|
"lesson_count": len(list(context.get("compact_lessons") or [])),
|
|
}
|
|
)
|
|
payload = {
|
|
"instrument_id": instrument_id,
|
|
"timeframe": timeframe,
|
|
"rows": rows,
|
|
"passed": bool(rows),
|
|
}
|
|
_print_payload(payload, output_json=output_json)
|
|
return 0 if rows else 2
|
|
|
|
|
|
def _resolve_model_codes(*, env, instrument_id: int) -> list[str]:
|
|
explicit = [item.strip() for item in str(env.get("RESEARCH_COUNCIL_ARENA_MODEL_CODES") or "").split(",") if item.strip()]
|
|
if explicit:
|
|
return explicit
|
|
trust_summary = ModelTrustService().build_summary(instrument_id=instrument_id)
|
|
models = [str(item.get("model_code") or "").strip() for item in list(trust_summary.get("models") or []) if str(item.get("model_code") or "").strip()]
|
|
if models:
|
|
return models[:3]
|
|
return ["OSOK_DAILY_RANGE_SWEEP_MSS_FVG_RETRACE"]
|
|
|
|
|
|
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 arena for instrument {payload.get('instrument_id')}")
|
|
print(f"Rows: {len(payload.get('rows') or [])}")
|
|
|
|
|
|
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())
|