57 lines
2.0 KiB
Python
57 lines
2.0 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.readiness import ShadowPaperObservationBackfillService
|
|
|
|
|
|
def main(env=None) -> int:
|
|
env = os.environ if env is None else env
|
|
instrument_id = _get_int(env, "SHADOW_PAPER_BACKFILL_INSTRUMENT_ID", 1)
|
|
timeframe = str(env.get("SHADOW_PAPER_BACKFILL_TIMEFRAME") or "1m")
|
|
window_days = _get_int(env, "SHADOW_PAPER_BACKFILL_WINDOW_DAYS", 14)
|
|
apply = _get_bool(env, "SHADOW_PAPER_BACKFILL_APPLY", False)
|
|
output_json = _get_bool(env, "SHADOW_PAPER_BACKFILL_OUTPUT_JSON", False)
|
|
created_by = str(env.get("SHADOW_PAPER_BACKFILL_CREATED_BY") or "shadow_paper_backfill_audit")
|
|
payload = ShadowPaperObservationBackfillService().build_backfill_audit(
|
|
instrument_id=instrument_id,
|
|
timeframe=timeframe,
|
|
window_days=window_days,
|
|
apply=apply,
|
|
created_by=created_by,
|
|
)
|
|
if output_json:
|
|
print(json.dumps(payload, ensure_ascii=False, sort_keys=True, default=str))
|
|
else:
|
|
print(f"Shadow paper observation backfill: {payload.get('status')}")
|
|
print(f"Eligible dates: {', '.join(payload.get('eligible_backfill_dates') or []) or 'none'}")
|
|
print(f"Created observations: {payload.get('created_observation_count')}")
|
|
print(f"Projected shadow days: {payload.get('projected_observed_shadow_day_count')}")
|
|
print(f"Blocked backfill items: {', '.join(payload.get('blocked_backfill_items') or []) or 'none'}")
|
|
return 0
|
|
|
|
|
|
def _get_int(env, key: str, default: int) -> int:
|
|
value = env.get(key)
|
|
if value is None or value == "":
|
|
return default
|
|
return int(value)
|
|
|
|
|
|
def _get_bool(env, key: str, default: bool = False) -> 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())
|