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
+46 -7
View File
@@ -127,6 +127,7 @@ def _active_narayana(
birth_at: datetime,
event_at: datetime,
periods: list[dict[str, Any]] | None = None,
antardasha_by_md: dict[int, list[dict[str, Any]]] | None = None,
) -> tuple[int | None, int | None]:
if periods is None:
periods = narayana_dasha.calc_narayana_mahadasha(
@@ -134,10 +135,30 @@ def _active_narayana(
planet_longitudes,
)
age = max((event_at - birth_at).total_seconds() / (365.2425 * 86_400), 0.0)
active = narayana_dasha.get_current_narayana_dasha(periods, age)
major = active.get("md") or {}
minor = active.get("ad") or {}
return major.get("sign_idx"), minor.get("sign_idx")
if antardasha_by_md is None:
active = narayana_dasha.get_current_narayana_dasha(periods, age)
major = active.get("md") or {}
minor = active.get("ad") or {}
return major.get("sign_idx"), minor.get("sign_idx")
# BUG-1324: same MD/AD lookup as narayana_dasha.get_current_narayana_dasha
# lines 769-800 (total_cycle, cycle_start, age_in_cycle, MD loop, AD loop).
# PD (lines 801-812) is unused by scoring and is not computed here.
if not periods:
return None, None
total_cycle = sum(p["years"] for p in periods)
if total_cycle == 0:
return None, None
cycle_start = min(float(p.get("start_age", 0)) for p in periods)
age_in_cycle = ((age - cycle_start) % total_cycle) + cycle_start
for period in periods:
if period["start_age"] <= age_in_cycle < period["end_age"]:
md_sign = period.get("sign_idx")
ads = antardasha_by_md.get(period["sign_idx"]) or []
for ad in ads:
if ad["start_age"] <= age_in_cycle < ad["end_age"]:
return md_sign, ad.get("sign_idx")
return md_sign, None
return None, None
def _varga_chart(charts: dict, prefix: str) -> dict | None:
@@ -198,13 +219,15 @@ def _score_event(
vimshottari: tuple[str, str, str],
narayana: tuple[int | None, int | None],
arudha_padas: dict,
functional: dict | None = None,
) -> CandidateEvidence:
_, target_houses = DOMAIN_CONFIG[event["domain"]]
ascendant_index = int(natal_chart["ascendant"]["lon"] // 30)
target_lords = _house_lords(ascendant_index, target_houses)
functional = functional_benefics.derive_functional_benefic_malefic(
natal_chart["ascendant"].get("sign")
)
if functional is None:
functional = functional_benefics.derive_functional_benefic_malefic(
natal_chart["ascendant"].get("sign")
)
functional_benefics_set = set(functional.get("functional_benefics") or [])
functional_malefics_set = set(functional.get("functional_malefics") or [])
major_lord, minor_lord, pratyantar_lord = vimshottari
@@ -542,6 +565,18 @@ def build_candidate_static_context(
)
except (KeyError, TypeError, ValueError):
narayana_periods = None
functional_profile = functional_benefics.derive_functional_benefic_malefic(
chart["ascendant"].get("sign")
)
narayana_antardasha_by_md = None
if narayana_periods:
narayana_antardasha_by_md = {
period["sign_idx"]: narayana_dasha.calc_narayana_antardasha(
narayana_periods,
period["sign_idx"],
)
for period in narayana_periods
}
birth_info = chart.get("birth_info") if isinstance(chart.get("birth_info"), dict) else {}
kp_snapshot = observe_kp_cusps(
@@ -595,6 +630,8 @@ def build_candidate_static_context(
"shadbala_result": shadbala_result,
"vimshottari_timeline": vimshottari_timeline,
"narayana_periods": narayana_periods,
"functional_profile": functional_profile,
"narayana_antardasha_by_md": narayana_antardasha_by_md,
}
@@ -649,6 +686,7 @@ def _candidate_row(
candidate_at,
event_at,
context.get("narayana_periods"),
context.get("narayana_antardasha_by_md"),
)
except (KeyError, TypeError, ValueError):
missing_layers.append("Narayana_MD_AD")
@@ -664,6 +702,7 @@ def _candidate_row(
vimshottari=vimshottari,
narayana=narayana,
arudha_padas=arudha_padas,
functional=context.get("functional_profile"),
))
transit_rules = _controlled_transit_rules(
request,