feat(rectification): pass ayanamsa per request
This commit is contained in:
@@ -6,6 +6,8 @@ import uuid
|
||||
from datetime import date
|
||||
from typing import Any, Literal, NotRequired, TypedDict, cast
|
||||
|
||||
from scripts.ayanamsa_utils import UnsupportedAyanamsaError, normalize_ayanamsa_name
|
||||
|
||||
DatePrecision = Literal["day", "month", "quarter", "year", "range"]
|
||||
|
||||
EVENT_CONTRACT_VERSION = "rectification-event-contract-v2"
|
||||
@@ -48,7 +50,10 @@ _EVENT_PROVENANCE_FIELDS = frozenset({
|
||||
"date_source", "date_reliability", "date_corroboration", "date_conflict_status",
|
||||
"source_turn_id", "subject",
|
||||
})
|
||||
_REQUEST_FIELDS = frozenset({"birth_date", "start_time", "end_time", "lat", "lon", "tz", "events"}) | _REQUEST_PROVENANCE_FIELDS
|
||||
_REQUEST_FIELDS = frozenset({
|
||||
"birth_date", "start_time", "end_time", "lat", "lon", "tz", "events",
|
||||
"ayanamsa", "node_mode",
|
||||
}) | _REQUEST_PROVENANCE_FIELDS
|
||||
_EVENT_FIELDS = frozenset({"id", "domain", "event_kind", "date_start", "date_end", "precision", "summary"}) | _EVENT_PROVENANCE_FIELDS
|
||||
_CLOCK = re.compile(r"(?:[01]\d|2[0-3]):[0-5]\d\Z")
|
||||
|
||||
@@ -77,6 +82,8 @@ class RectificationRequest(TypedDict):
|
||||
lon: float
|
||||
tz: float
|
||||
events: list[LifeEvent]
|
||||
ayanamsa: NotRequired[str]
|
||||
node_mode: NotRequired[str]
|
||||
birth_time_source: NotRequired[str | None]
|
||||
timezone_id: NotRequired[str | None]
|
||||
timezone_source: NotRequired[str | None]
|
||||
@@ -227,6 +234,16 @@ def normalize_rectification_request(body: Any, *, today: date | None = None) ->
|
||||
"tz": _bounded_number(body, "tz", -14, 14),
|
||||
"events": cleaned_events,
|
||||
}
|
||||
if "ayanamsa" in body:
|
||||
try:
|
||||
cleaned_request["ayanamsa"] = normalize_ayanamsa_name(body.get("ayanamsa"))
|
||||
except UnsupportedAyanamsaError as exc:
|
||||
raise ValueError(str(exc)) from exc
|
||||
if "node_mode" in body:
|
||||
node_mode = body.get("node_mode")
|
||||
if not isinstance(node_mode, str) or node_mode.strip().lower() not in {"mean", "true"}:
|
||||
raise ValueError("node_mode must be mean or true")
|
||||
cleaned_request["node_mode"] = node_mode.strip().lower()
|
||||
_copy_nullable_text(body, cleaned_request, "birth_time_source", "birth_time_source", 120, _BIRTH_TIME_SOURCES)
|
||||
_copy_nullable_text(body, cleaned_request, "timezone_id", "timezone_id", 120)
|
||||
_copy_nullable_text(body, cleaned_request, "timezone_source", "timezone_source", 80)
|
||||
|
||||
Reference in New Issue
Block a user