Files
Jyotisha/scripts/research_timing/rashi_pd.py
T
ClaudeandClaude Opus 5.5 9351b0b633
Independent Staging Quality Gate / validate-frontend (push) Successful in 5m20s
Independent Staging Quality Gate / validate-python (push) Successful in 6m3s
Independent Staging Quality Gate / publish (push) Successful in 3m28s
feat(report): Lagna Kendradi, Niryaana Shoola sub-periods and non-applicable conditional dashas, as in the upstream export
Product decision 2026-11-06: follow the upstream export for these tables.

- Lagna Kendradi: upstream profile kendradi_narayana_duration_candidate_v1
  (Lagna sign, then kendra / panaphara / apoklima order, Narayana sign years,
  the same years Drig uses). Major periods only; labelled as not checked
  against a book example.
- Niryaana Shoola: sub-periods forward from the MD sign, twelve equal parts;
  the research chapter adds the third level. Labelled: PVR gives no separate
  rule, comparison only.
- Conditional dashas whose classical gate fails (Satabdika, Shodashottari,
  Dwadashottari, Dwisaptatisama, Panchottari, Chaturshitisama) get a separate
  reference copy with the existing standard-table profile. The reading's own
  modules stay not_applicable, so consultation, convergence and
  rectification are unchanged; the report states the unmet condition.

Tests that locked the old omissions are updated with 原值/新值/原因.
Pre-work ledger: notes from this session (restore, CRLF files, baseline failures).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
2026-11-06 17:39:39 +08:00

80 lines
2.6 KiB
Python

"""Third-level rows for four rashi dashas, on a copy only.
The producer stays free of this key. Printed pages name the sub-period
and not the third level. The split used here is the direct equal-time
rule in the upstream calendar helper: the first child keeps the
sub-period sign, the rest run forward, and the last child ends on the
sub-period end. An empty sub-period list, including a Drig strength tie,
gets no third level.
"""
from __future__ import annotations
from copy import deepcopy
from datetime import datetime
try:
from rashi_dashas_native import SIGNS
except ImportError: # pragma: no cover - package import
from scripts.rashi_dashas_native import SIGNS
FAMILIES = ("sthira", "drig", "shoola", "navamsha", "niryaana_shoola")
def attach_rashi_pratyantar(calculated: dict) -> dict:
"""Return a deep copy with third-level rows. The input is not changed."""
copied = deepcopy(calculated)
for name in FAMILIES:
section = copied.get(name)
if not isinstance(section, dict):
continue
for major in section.get("periods") or []:
if not isinstance(major, dict):
continue
children = major.get("antardasha")
if not isinstance(children, list) or not children:
continue
for child in children:
if not isinstance(child, dict):
continue
third = _equal_forward(child)
if third:
child["pratyantar"] = third
return copied
def _equal_forward(child: dict) -> list[dict]:
sign = child.get("sign_index")
if not isinstance(sign, int):
label = child.get("sign")
if label not in SIGNS:
return []
sign = SIGNS.index(label)
try:
start = datetime.fromisoformat(str(child["start"]))
end = datetime.fromisoformat(str(child["end"]))
except (KeyError, TypeError, ValueError):
return []
total = (end - start).total_seconds()
if total <= 0:
return []
rows = []
for offset in range(12):
moment = end if offset == 11 else start + _seconds(total * (offset + 1) / 12.0)
opened = start if offset == 0 else start + _seconds(total * offset / 12.0)
index = (int(sign) + offset) % 12
rows.append({
"sign": SIGNS[index],
"sign_index": index,
"start": opened.date().isoformat(),
"end": moment.date().isoformat(),
"level": "PD",
})
rows[-1]["end"] = end.date().isoformat()
return rows
def _seconds(value: float):
from datetime import timedelta
return timedelta(seconds=value)