Files
Jyotisha/scripts/report_render/conditional_dasha_pvr_2014.py
T

120 lines
5.8 KiB
Python

"""PVR 2014 readings of two conditional-dasha conditions, as a separate named profile (BUG-2122).
Astrologer reply 2026-11-20, answer 11: P.V.R. Narasimha Rao, "Unified
Nakshatra Dasa Approach: In Annual & Natal Charts" (2014-01-07, v4), PDF
pp. 2-4, reads two conditions differently from the ones this product uses:
* Panchottari: the Lagna in Cancer dwadasamsa (D12) only; the article's
footnote rejects the extra "Cancer in rasi" requirement.
* Dwisaptati Sama: the Lagna lord in the 7th house, or the 7th lord in the
Lagna (the product tests the Lagna lord in the 1st or 7th).
These rows are an additional named profile. They never replace the
product's rows, never change which dasha is the main timeline and never
create a period table. Houses are counted by sign from the Lagna sign; the
seven-planet sign lords are the ones the product's own gates use. Inputs
come only from the packet's D1 longitudes (the report's own settings); when
one is missing the row is "not determined" (None), never "does not apply".
BUG-2159 (astrologer ruling 2026-11-22, item 8): this is a check of the
basic applicability conditions the article lists, not a reproduction of the
method. The article's own examples (PDF p. 18 Example 12, p. 22 Example 15)
place houses by degree, which is not done here; the controlling-planet
strength comparison and the final choice among conditional dashas are not
done either, so a met condition is never "the dasha the method selects".
"""
from __future__ import annotations
from typing import Any, Dict, List, Optional
try:
from panchottari_dasha import dwadasamsa_sign_index
except ImportError: # pragma: no cover - package import
from scripts.panchottari_dasha import dwadasamsa_sign_index
try:
from scripts.report_render.conditional_dasha_applicability import _SIGN_LORDS, _longitudes
except ImportError: # pragma: no cover
from report_render.conditional_dasha_applicability import _SIGN_LORDS, _longitudes
PROFILE = "pvr_unified_nakshatra_dasa_2014"
# BUG-2129 (负责人 2026-11-21): no author, article title, pages or source lines for the reader.
# BUG-2159 (占星师 2026-11-22 第 8.2 项): the row names what is done — the basic conditions the
# method lists, by sign — and what is not; "PVR 2014" is the method's name (data chapter only).
PROFILE_NAMES = (
"Basic applicability checks listed in PVR 2014 (by sign for now; degree-based houses and controlling-planet selection not done)",
"PVR 2014所列基础适用条件检查(当前按星座;未完成度数宫位及控制星择优)",
)
CANCER = 3
# Family keys (as in conditional_dasha_applicability.FAMILY_ORDER) that have a PVR 2014 variant.
VARIANT_FAMILIES = ("dwisaptatisama", "panchottari")
def _sign(longitude: float) -> int:
return int(longitude // 30) % 12
def _house(asc_sign: int, sign: int) -> int:
"""Whole-sign house: the Lagna sign is the 1st."""
return (sign - asc_sign) % 12 + 1
def _panchottari(lons: Dict[str, float], fallback_d12: Any = None) -> Dict[str, Any]:
asc = lons.get("Ascendant")
inputs: Dict[str, Any] = {}
if asc is not None:
inputs = {"ascendant_rasi_sign_index": _sign(asc), "ascendant_d12_sign_index": dwadasamsa_sign_index(asc)}
elif isinstance(fallback_d12, int) and not isinstance(fallback_d12, bool):
# The engine's own D12 Lagna, when the packet carries no Lagna longitude.
inputs = {"ascendant_d12_sign_index": int(fallback_d12) % 12}
d12 = inputs.get("ascendant_d12_sign_index")
return {"condition": None if d12 is None else d12 == CANCER, "inputs": inputs}
def _dwisaptati(lons: Dict[str, float]) -> Dict[str, Any]:
asc = lons.get("Ascendant")
if asc is None:
return {"condition": None, "inputs": {}}
asc_sign = _sign(asc)
lagna_lord, seventh_lord = _SIGN_LORDS[asc_sign], _SIGN_LORDS[(asc_sign + 6) % 12]
inputs: Dict[str, Any] = {"ascendant_sign_index": asc_sign, "lagna_lord": lagna_lord, "seventh_lord": seventh_lord}
if lagna_lord in lons:
inputs["lagna_lord_sign_index"] = _sign(lons[lagna_lord])
inputs["lagna_lord_house"] = _house(asc_sign, inputs["lagna_lord_sign_index"])
if seventh_lord in lons:
inputs["seventh_lord_sign_index"] = _sign(lons[seventh_lord])
inputs["seventh_lord_house"] = _house(asc_sign, inputs["seventh_lord_sign_index"])
first = inputs.get("lagna_lord_house") == 7 if "lagna_lord_house" in inputs else None
second = inputs.get("seventh_lord_house") == 1 if "seventh_lord_house" in inputs else None
if first is True or second is True:
condition: Optional[bool] = True
elif first is False and second is False:
condition = False
else:
condition = None # one branch unknown and the other not met: stays unknown.
return {"condition": condition, "inputs": inputs}
def pvr_variant_rows(chart: Any, default_rows: Any = None) -> List[Dict[str, Any]]:
"""One row per family with a PVR 2014 variant.
``chart``: ``core_chart``; ``default_rows``: ``applicability_rows(...)``
(used only for the product row's table state and, for Panchottari, the
engine's D12 Lagna when no longitude is carried).
Row: ``key``, ``profile``, ``condition`` (True / False / None), ``inputs``,
``table`` (the product row's table state, unchanged; no table is built here).
"""
lons = _longitudes(chart if isinstance(chart, dict) else {})
by_key = {row.get("key"): row for row in default_rows or [] if isinstance(row, dict)}
rows = []
for key in VARIANT_FAMILIES:
base = by_key.get(key) or {}
if key == "panchottari":
found = _panchottari(lons, (base.get("inputs") or {}).get("ascendant_d12_sign_index"))
else:
found = _dwisaptati(lons)
rows.append({"key": key, "profile": PROFILE, **found, "table": base.get("table")})
return rows