- 2377 appendix yoga table: kind, formation, also-needs, condition and meaning source (book title only) - 2378 Saham trace: A, B, C, A − B + C, arc test, +30°, final value - 2379 daridra_2 「第二宫主落陷…」 no longer classified as Neecha Bhanga - 2380 Neecha variant names on page titles; Raja add-on line - 2381 Pancha Mahapurusha page agrees with its basis; degree, Moolatrikona, same-fact line - 2382 no book/page "Source:" lines in the body Yoga Expression chapter - 2383 yoga pages state participants' combustion, Shadbala, functional role - 2384 unresolved-rule records stay backstage (packet only) - 2385 Neecha verified state matches the row's own fallen planet - 2386 no hedge line for uncomputed Neecha notes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXp3RzgZVEpT1PXxkwHj
137 lines
5.4 KiB
Python
137 lines
5.4 KiB
Python
"""Formula traces for Sahams that were already calculated.
|
|
|
|
The trace copies the stored longitude. It does not replace it.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
|
|
# (result key, day (p1, p2), night (p1, p2) or None when day and night match)
|
|
# _saham(p1, p2) = Asc + p2 - p1.
|
|
_LOCAL = (
|
|
("karya_saham", ("Moon", "Mars"), ("Mars", "Moon")),
|
|
# BUG-2156: was ("Mars", "Venus"), None — Asc + Venus - Mars, not Vivaha. Table 74:
|
|
# day Venus - Saturn + Asc, night Saturn - Venus + Asc. Only used when the formula metadata is missing.
|
|
("vivah_saham", ("Saturn", "Venus"), ("Venus", "Saturn")),
|
|
("rajya_saham", ("Jupiter", "Sun"), None),
|
|
("shatru_saham", ("Saturn", "Mars"), None),
|
|
("labha_saham", ("Moon", "Jupiter"), None),
|
|
("parakrama_saham", ("Sun", "Mars"), None),
|
|
("putra_saham", ("Moon", "Jupiter"), None),
|
|
("jnana_saham", ("Mercury", "Jupiter"), None),
|
|
("raja_saham", ("Moon", "Sun"), None),
|
|
("yasha_saham", ("Sun", "Jupiter"), None),
|
|
("karma_saham", ("Mars", "Saturn"), None),
|
|
("bandhu_saham", ("Mercury", "Mars"), None),
|
|
("matri_saham", ("Venus", "Moon"), None),
|
|
("pitri_saham", ("Saturn", "Sun"), None),
|
|
("janma_saham", ("Sun", "Asc"), None),
|
|
("mrityu_saham", ("Mars", "Saturn"), None),
|
|
("rogha_saham", ("Saturn", "Mercury"), None),
|
|
("aarogya_saham", ("Saturn", "Jupiter"), None),
|
|
("bhraatri_saham", ("Moon", "Mars"), None),
|
|
("ghataka_saham", ("Mars", "Rahu"), None),
|
|
("paradesa_saham", ("Moon", "Saturn"), None),
|
|
("parabharya_saham", ("Mars", "Venus"), None),
|
|
("dhan_saham", ("Venus", "Jupiter"), None),
|
|
("maya_saham", ("Ketu", "Rahu"), None),
|
|
("moksha_saham", ("Jupiter", "Ketu"), None),
|
|
("buddha_saham", ("Jupiter", "Mercury"), None),
|
|
("shastra_saham", ("Ketu", "Mars"), None),
|
|
("kala_saham", ("Sun", "Saturn"), None),
|
|
("shakti_saham", ("Moon", "Venus"), None),
|
|
("bhrigu_saham", ("Jupiter", "Venus"), None),
|
|
("sundara_saham", ("Mercury", "Venus"), None),
|
|
("jnati_saham", ("Saturn", "Mars"), None),
|
|
("artha_saham", ("Venus", "Sun"), None),
|
|
("dharma_saham", ("Saturn", "Jupiter"), None),
|
|
("sangrama_saham", ("Rahu", "Mars"), None),
|
|
)
|
|
|
|
|
|
def _rule_text(meta: dict) -> str:
|
|
# BUG-2065: the three operands mean A - B + C (scripts/tajika.py
|
|
# _formula_saham_trace: third + (first - second)), not a sum.
|
|
operands = [str(part).replace("_", " ") for part in meta.get("formula_operands") or ()]
|
|
if len(operands) == 3:
|
|
text = f"{operands[0]} - {operands[1]} + {operands[2]}"
|
|
else:
|
|
text = str(meta.get("rule_name") or "rule").replace("_", " ")
|
|
if _plus_thirty(meta):
|
|
text += " + 30°"
|
|
return text
|
|
|
|
|
|
def _plus_thirty(meta: dict) -> bool:
|
|
"""True when the stored longitude carries the +30 degree correction."""
|
|
flag = meta.get("zodiacal_order_exception_applied")
|
|
if isinstance(flag, bool):
|
|
return flag
|
|
base, final = meta.get("base_longitude"), meta.get("longitude")
|
|
if all(isinstance(value, (int, float)) and not isinstance(value, bool) for value in (base, final)):
|
|
return abs((float(final) - float(base)) % 360 - 30.0) < 1e-6
|
|
return False
|
|
|
|
|
|
def _steps(meta: dict | None) -> dict:
|
|
"""BUG-2378 (占星师 2026-11-25 M13): the operands, the value before the +30° test, the test and its result."""
|
|
if not isinstance(meta, dict):
|
|
return {}
|
|
values = meta.get("operand_longitudes")
|
|
if not isinstance(values, dict):
|
|
return {}
|
|
steps = {
|
|
"operands": list(meta.get("formula_operands") or ()),
|
|
"operand_longitudes": {key: round(float(value), 4) for key, value in values.items()
|
|
if isinstance(value, (int, float)) and not isinstance(value, bool)},
|
|
"plus_thirty": _plus_thirty(meta),
|
|
}
|
|
if isinstance(meta.get("base_longitude"), (int, float)):
|
|
steps["base_longitude"] = round(float(meta["base_longitude"]), 4)
|
|
if isinstance(meta.get("arc_passes_c"), bool):
|
|
steps["arc_passes_c"] = meta["arc_passes_c"]
|
|
return steps
|
|
|
|
|
|
def attach_formula_traces(
|
|
results: dict[str, Any],
|
|
*,
|
|
is_day: bool,
|
|
formula_meta: dict[str, dict] | None = None,
|
|
) -> list[dict]:
|
|
"""Add ``formula_traces`` without changing any existing Saham longitude."""
|
|
formula_meta = formula_meta or {}
|
|
traces = []
|
|
punya = formula_meta.get("punya_saham")
|
|
if punya and isinstance(results.get("punya_saham"), dict):
|
|
traces.append({
|
|
"name": results["punya_saham"].get("name") or "Punya Saham",
|
|
"key": "punya_saham",
|
|
"rule": _rule_text(punya),
|
|
"phase": "day" if is_day else "night",
|
|
"longitude": results["punya_saham"].get("longitude"),
|
|
**_steps(punya),
|
|
})
|
|
for key, day_pair, night_pair in _LOCAL:
|
|
item = results.get(key)
|
|
if not isinstance(item, dict) or not isinstance(item.get("longitude"), (int, float)):
|
|
continue
|
|
meta = formula_meta.get(key)
|
|
if meta:
|
|
rule = _rule_text(meta)
|
|
else:
|
|
pair = day_pair if is_day or night_pair is None else night_pair
|
|
rule = f"Asc + {pair[1]} - {pair[0]}"
|
|
traces.append({
|
|
"name": item.get("name") or key,
|
|
"key": key,
|
|
"rule": rule,
|
|
"phase": "day" if is_day else "night",
|
|
"longitude": item.get("longitude"),
|
|
**_steps(meta),
|
|
})
|
|
results["formula_traces"] = traces
|
|
return traces
|