Speed up rectification scoring without changing results.

Cache work that depends only on the candidate minute, drop unread response fields, and reject windows above 241 candidates before any chart is built. Eleven canonical scenario hashes match 77057a819. Sealed and reported-offset replays match the 2026-10-08 records (changed_trial_count 8 and 581) and are stored as scoring_perf_2026_10_13.

Co-Authored-By: Grok (agent loop)
This commit is contained in:
jesse-ux
2026-10-14 02:06:14 +08:00
co-authored by Grok (agent loop)
parent 74384be024
commit 8e0503f9c0
27 changed files with 45977 additions and 92 deletions
@@ -130,6 +130,8 @@ def merge_transition_proximity(
for context in static_contexts
if isinstance(context, dict) and (time := _context_time(context))
}
# BUG-1324: one unfiltered dasha walk per candidate, then filter by event year.
# Released when this function returns. Not a module-level cache.
vim_cache: dict[tuple[Any, ...], list[date]] = {}
pd_cache: dict[tuple[Any, ...], list[date]] = {}
narayana_cache: dict[tuple[Any, ...], list[date] | None] = {}
@@ -156,14 +158,15 @@ def merge_transition_proximity(
# Legacy time-only contexts still use the request's date.
candidate_at = context.get("candidate_at")
candidate_date = candidate_at.date().isoformat() if isinstance(candidate_at, datetime) else birth_date
vim_key = (candidate_date, round(float(moon), 6), lo, hi)
moon_key = round(float(moon), 6)
vim_key = (candidate_date, moon_key)
if vim_key not in vim_cache:
vim_cache[vim_key] = _vim_start_dates(candidate_date, float(moon), lo, hi)
vim_cache[vim_key] = _vim_start_dates(candidate_date, float(moon), 1, 9999)
pd_cache[vim_key] = _vim_start_dates(
candidate_date,
float(moon),
lo,
hi,
1,
9999,
include_pratyantar=True,
)
planets = context.get("planet_longitudes") or {}
@@ -171,25 +174,26 @@ def merge_transition_proximity(
narayana_key = (
candidate_date,
int(asc) if isinstance(asc, int) else None,
lo,
hi,
round(float(moon), 6),
moon_key,
)
if narayana_key not in narayana_cache:
narayana_cache[narayana_key] = (
_narayana_start_dates(int(asc), planets, candidate_date, lo, hi)
_narayana_start_dates(int(asc), planets, candidate_date, 1, 9999)
if isinstance(asc, int) and isinstance(planets, dict)
else None
)
ad_starts = vim_cache[vim_key]
ad_starts = [item for item in vim_cache[vim_key] if lo <= item.year <= hi]
ad_set = set(ad_starts)
pd_only = [item for item in pd_cache[vim_key] if item not in ad_set]
pd_only = [item for item in pd_cache[vim_key] if lo <= item.year <= hi and item not in ad_set]
narayana_starts = narayana_cache[narayana_key]
if narayana_starts is not None:
narayana_starts = [item for item in narayana_starts if lo <= item.year <= hi]
scored = score_transition_proximity(
event_date=event_date,
precision=precision,
vim_starts=ad_starts,
vim_pd_starts=pd_only,
narayana_starts=narayana_cache[narayana_key] or [],
narayana_starts=narayana_starts or [],
)
if scored["points"] <= 0 and not scored["rule_ids"]:
continue