Files
Jyotisha/tests/test_shadbala_precise_context.py
T
ClaudeandClaude Opus 5.5 78f98eba93 fix(engine): apply the #166 astrologer rulings to Shadbala, Arudha and D30 (BUG-1581..1589, BUG-1575)
Astrologer ruling 2026-11-04 on #166; product decision the same day (Moon
option C, rulings implemented as given). The default is a named BPHS version;
the pre-#166 precise Sthana / Drik is kept byte-for-byte as variant
"raman_gbb" (Raman, Graha and Bhava Balas Ex. 13 / 55 still pass on it).

- Q3 (BUG-1581): the Moon's own Paksha is P on both sides (Sanskrit 27.11 lists
  indu), Chesta = Paksha, total 2P. Drik still classifies a waning Moon as a
  malefic (Q26), classify_drik_planets unchanged for the Moon.
- Q2 (BUG-1582): the Sun's Ayana is not doubled; Chesta = base Ayana; A + A.
  On the VP Jain fixture Kala + Chesta = 46.73 + 35.07 = published 81.80 + 0.
- Q18 (BUG-1583, BUG-1575): Moolatrikona Moon Taurus from 3 deg, Mercury Virgo
  from 15 deg, in shadbala.py and jyotish_engine.MOOLATRIKONA.
- Q16 / Q20 (BUG-1584): Saptavargaja 45/30/20/15/10/4/2, compound relation from D1.
- Q25 (BUG-1585): Mercury is a natural malefic with any natural malefic in its
  sign (nodes not counted, recorded as an implementation choice).
- Q24 (BUG-1586): BPHS 26.9-12 piecewise special aspects replace the general
  segment for Saturn, Mars and Jupiter; a single aspect stays within 0-60.
- Q21 (BUG-1587): Kendradi Bala by whole sign from the Lagna sign.
- Q27 (BUG-1588): jaimini.calc_arudha_pada_for_house takes the 10th from the
  first-count pada (pada in the 7th -> 4th from the house), as special_lagnas did.
- Q30 (BUG-1589): D30 degree inside the sign is proportional within the
  unequal span in varga.py; divisional_charts_extended uses exact 30/7.
- method_variants names every convention. Q22 edges and the Q24 60 cap are
  locked in tests/test_astrologer_rulings_166.py (42 tests).

Raman / PyJHora comparison tests now run on "raman_gbb"; the VP Jain report
labels the new convention rows; chart-insight-golden.json's planets-only
Shadbala section regenerated from /api/shadbala. Rectification identity,
golden and re-freeze follow in separate commits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-04 21:08:32 +08:00

106 lines
6.0 KiB
Python
Raw 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,
}
# 原值: {"Sun": 24.81, "Moon": 95.48, "Mars": 77.41, "Mercury": 12.64, "Jupiter": 80.60, "Venus": 69.95, "Saturn": 19.62}
# (PyJHora 4.8.7 默认 _dig_bala,弧不折回,与本仓旧写法同错,所以一直「一致」)
# 新值: 月亮 24.52、火星 42.59、木星 39.40、金星 50.05,其余不变
# (= PyJHora 自己的 _dig_bala_another:60 × (1 − 到最强点距离 / 180),7 星逐一相等)
# 原因: BUG-1270,BPHS 27.7 与 Raman GBB §44–45 例 14–15 要求弧大于 180° 时用 360° 去减
PYJHORA_DIG = {"Sun": 24.81, "Moon": 24.52, "Mars": 42.59, "Mercury": 12.64, "Jupiter": 39.40, "Venus": 50.05, "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(), "raman_gbb")
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():
# 原值: 默认口径;新值: variant="raman_gbb";原因: #166(BUG-1584~1586)默认改为 BPHS,Raman 例题与 PyJHora(Raman 系)按具名对照口径核对
assert abs(calc_drik_bala_precise(planet, planets, variant="raman_gbb") - 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], variant="raman_gbb")["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 0(Ayana ×2 = 36.0,与 PyJHora 同)
# 新值: 太阳 delta −18.0(Ayana 18.0,不乘 2;PyJHora 仍乘 2)
# 原因: BUG-1582,#166 第 2 条 SUN_AYANA_CONVENTION(A + A)。此盘月亮为盈月,口径 C 不改其值
delta = 41.51 if planet == "Moon" else -60.0 if planet == "Venus" else -18.0 if planet == "Sun" 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]