Files
Jyotisha/tests/test_shadbala_precise_context.py
ClaudeandClaude Opus 5.5 18b01c23e5
Independent Staging Quality Gate / publish (push) Canceled after 0s
Independent Staging Quality Gate / validate-python (push) Canceled after 1m32s
Independent Staging Quality Gate / validate-frontend (push) Canceled after 1m33s
fix(shadbala): count the Moon's Paksha 2x, not 4x; adopt BPHS-Santhanam 27.10-11 + 27.18 (BUG-1557)
The precise path doubled the Moon's Paksha in Kala (Raman, Graha and Bhava
Balas §55(c)) and then took that doubled value again as her Chesta (BPHS
27.18), so her Paksha entered the total four times; Chesta could reach 120,
clamping Kashta to 0 and pushing Ishta past 60. Every surveyed source
counts 2P.

Product decision 2026-11-04: BPHS (Santhanam) 27.10-11 + 27.18, as in
saravali.github.io, Maitreya8 (default) and jyotishyamitra. The Moon's
Paksha is the folded base, not doubled; waxing Moon benefic, waning Moon
malefic (BPHS 3.11, already what classify_drik_planets does, unchanged);
Chesta = Paksha. method_variants.moon_paksha names the convention. Other
planets, Drik and the legacy calc_kala_bala path are unchanged.

shadbala.py is in the rectification frozen identity, so per ERR-110 new
records were frozen and replayed as moon_paksha_2026_11_04. Compared field
by field with data_audit_2026_11_04: sealed holdout 20/20 and reported
offset 900/900 identical, metrics and summary unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyeZrYn6ryNcSe5Y2Y
2026-11-04 15:46:16 +08:00

97 lines
5.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from scripts.shadbala import (
build_shadbala_context,
calc_dig_bala_precise,
calc_drik_bala_precise,
calc_kala_bala_precise,
calc_chesta_bala_precise,
calc_sthana_bala_precise,
classify_drik_planets,
)
PLANET_LONGITUDES = {
"Sun": 312.51819523181405,
"Moon": 344.51168181221095,
"Mars": 5.862334338243072,
"Mercury": 291.12589362817465,
"Jupiter": 87.27055150216494,
"Venus": 267.94211928370015,
"Saturn": 207.92738390514674,
}
PYJHORA_DIG = {"Sun": 24.81, "Moon": 95.48, "Mars": 77.41, "Mercury": 12.64, "Jupiter": 80.60, "Venus": 69.95, "Saturn": 19.62}
PYJHORA_DRIK = {"Sun": 1.74, "Moon": 20.06, "Mars": 13.49, "Mercury": -10.63, "Jupiter": 6.89, "Venus": -2.75, "Saturn": 9.49}
PYJHORA_STHANA = {"Sun": 217.09, "Moon": 246.34, "Mars": 198.63, "Mercury": 167.96, "Jupiter": 201.80, "Venus": 154.06, "Saturn": 218.61}
PYJHORA_KALA = {"Sun": 140.99, "Moon": 149.58, "Mars": 127.93, "Mercury": 121.78, "Jupiter": 199.31, "Venus": 113.44, "Saturn": 136.77}
def _planets() -> dict:
return {
planet: {
"degree": longitude,
"sign": ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo", "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"][int(longitude // 30)],
}
for planet, longitude in PLANET_LONGITUDES.items()
}
def test_precise_dig_bala_matches_pyjhora_same_chart() -> None:
context = build_shadbala_context(2435163.6354166665, 37.7749, -122.4194, "lahiri", -8.0)
for planet, longitude in PLANET_LONGITUDES.items():
assert calc_dig_bala_precise(planet, longitude, context["house_midpoints"]) == PYJHORA_DIG[planet]
def test_drik_classification_matches_pyjhora_same_chart() -> None:
benefics, malefics = classify_drik_planets(_planets())
assert benefics == {"Moon", "Mercury", "Jupiter", "Venus"}
assert malefics == {"Sun", "Mars", "Saturn"}
def test_precise_drik_bala_matches_pyjhora_same_chart() -> None:
planets = _planets()
for planet, expected in PYJHORA_DRIK.items():
assert abs(calc_drik_bala_precise(planet, planets) - expected) <= 0.02
def test_precise_sthana_bala_matches_pyjhora_same_chart() -> None:
planets = _planets()
houses = {"Sun": 7, "Moon": 8, "Mars": 9, "Mercury": 6, "Jupiter": 11, "Venus": 5, "Saturn": 3}
for planet, expected in PYJHORA_STHANA.items():
assert calc_sthana_bala_precise(planet, planets, houses[planet])["total"] == expected
def test_precise_kala_preserves_archived_comparison_with_corrected_hora() -> None:
# 原值: 每颗星 Kala 总分 == 存档 PyJHora 值(test_precise_kala_bala_matches_pyjhora_same_chart)
# 新值: 月亮 +52.18、金星 −60.0,其余仍等于存档值(同上游 yinduzhanxing 0afa2780 的改法)
# 原因: TASK-upstream-sync4-20261002 T3:时主按民用星期查 _HORA_ORDER(周四此时为月亮时),
# Ayana 南北按取模后的回归黄经判断;存档 PyJHora 值只作对照,不作本地公式的标准答案
planets = _planets()
context = build_shadbala_context(2435163.6354166665, 37.7749, -122.4194, "lahiri", -8.0)
assert abs(context["sunrise_hour"] - 6.886306) < 0.00001
assert abs(context["sunset_hour"] - 17.890427) < 0.00001
for planet, expected in PYJHORA_KALA.items():
# BUG-1275: Ayana reads tropical = sidereal + ayanamsa. The fixed sidereal
# longitudes of _planets() were captured in the old mean-ayanamsa frame; with the
# true ayanamsa the Moon's Ayana moves 26.09 -> 26.08 (Kala -0.01).
# 原值: 月亮 delta 52.17(月亮 Paksha ×2 = 21.33)
# 新值: 月亮 delta 41.51(Paksha 10.66,不乘 2;PyJHora 仍乘 2,差 10.66)
# 原因: BUG-1557 采用 BPHS-Santhanam 27.10–11 + 27.18(月亮 Paksha 不乘 2,Chesta = Paksha)
delta = 41.51 if planet == "Moon" else -60.0 if planet == "Venus" else 0.0
assert abs(calc_kala_bala_precise(planet, planets, context)["total"] - expected - delta) < 0.001
def test_precise_chesta_uses_classical_bounded_variant() -> None:
planets = _planets()
context = build_shadbala_context(2435163.6354166665, 37.7749, -122.4194, "lahiri", -8.0)
kala = {planet: calc_kala_bala_precise(planet, planets, context) for planet in planets}
result = {planet: calc_chesta_bala_precise(planet, planets, kala[planet], context) for planet in planets}
assert result["Sun"] == kala["Sun"]["ayana"]
assert result["Moon"] == kala["Moon"]["paksha"]
# BUG-1557: the Moon's Paksha is P (waxing, 32 degrees / 3), not 2P, so Chesta is P too.
assert result["Moon"] == 10.66
for planet in ("Mars", "Mercury", "Jupiter", "Venus", "Saturn"):
assert 0.0 <= result[planet] <= 60.0
vedastro = {"Mars": 21.7377, "Mercury": 47.5107, "Jupiter": 46.0549, "Venus": 30.8469, "Saturn": 39.4390}
tolerances = {"Mars": 1.0, "Mercury": 2.0, "Jupiter": 1.0, "Venus": 2.0, "Saturn": 3.5}
for planet, expected in vedastro.items():
assert abs(result[planet] - expected) <= tolerances[planet]