Files
Jyotisha/scripts/report_render/birth_precision_window.py
T

27 lines
1.2 KiB
Python

"""Birth-time tolerance used by the personal report's evidence grading."""
from math import isfinite
CONFIRMED_TOLERANCE_MINUTES = 1.0
DEFAULT_TOLERANCE_MINUTES = 30.0
WINDOW_POLICY = "birth_record_window_v1"
_DECLARED_SOURCES = {"user_stated", "shichen", "period"}
_MAX_SIDE_MINUTES = 720
def _valid_side(value: object) -> bool:
return type(value) in (float, int) and 0 <= value <= _MAX_SIDE_MINUTES and isfinite(value)
def report_birth_window(value: object, *, minute_confirmed: bool) -> dict:
if minute_confirmed:
tolerance = CONFIRMED_TOLERANCE_MINUTES
return {"before_minutes": tolerance, "after_minutes": tolerance, "source": "confirmed_minute"}
if isinstance(value, dict):
before, after, source = value.get("before_minutes"), value.get("after_minutes"), value.get("source")
if isinstance(source, str) and source in _DECLARED_SOURCES and _valid_side(before) and _valid_side(after) and (before or after):
return {"before_minutes": before, "after_minutes": after, "source": source}
tolerance = DEFAULT_TOLERANCE_MINUTES
return {"before_minutes": tolerance, "after_minutes": tolerance, "source": "default_unknown_30"}