- Functional default = PVR Table 30 (functional_profile=pvr_table_30); the former product table is bphs_exception_profile, scored only when named (rectification names it, scores unchanged). profile_divergence shows both roles side by side; movable-lagna Moon by the table's paksha note; dual-lordship note; prior rulings BUG-1570/1590/#166 Q4 checked against Table 30. - Shadbala: six open items labelled parameter_sensitive; every option combination computed; only planets whose pass/fail flips get minimum_check=parameter_sensitive. - Vimshottari AD/PD rows carry parent_period_start / visible_period_start; the consult card cuts the balance MD from its full parent and clips at birth. - KP DBA: full first parent, clipped at birth (no balance rescale). - Mudda: balance fields + balance_method (angle default, time comparison apart), nominal_year_days, her crossing wording; Harsha combined blocked reason lists items. - D30 _meta describes the unequal parts (as her r40). - Golden recaptured with TTL=0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
266 lines
14 KiB
Python
266 lines
14 KiB
Python
#!/usr/bin/env python3
|
||
"""Shadbala minimum check under the open parameter questions (占星师 2026-11-08 第五轮裁定 4).
|
||
|
||
The astrologer listed six Shadbala items that are not yet decided and ruled
|
||
that until they are, a planet's "meets / misses the BPHS minimum" must not
|
||
drive a good/bad conclusion when the open choices can flip it. This module
|
||
runs the alternatives for real and marks only the planets whose pass/fail
|
||
actually flips:
|
||
|
||
1. ``saptavargaja_moolatrikona``: the 45-virupa Moolatrikona slot. Default: D1
|
||
inside the degree band only. Alternatives: D1 whole sign; the band in D1
|
||
plus the whole Moolatrikona sign in the other six vargas; the whole sign in
|
||
all seven vargas. Open question: the seven-varga composition and the
|
||
Moolatrikona degree range.
|
||
2. ``ayana_sun``: default A in Kala and Chesta = A (2A). Alternatives: the
|
||
translator's doubled Sun in Kala (3A), doubled and copied to Chesta (4A).
|
||
Open question: is the Sun's Ayana Bala counted twice.
|
||
3. ``chesta_moon``: default Chesta = Paksha (2P in total). Alternative: no
|
||
Chesta for the Moon (P). Raman doubles Paksha and leaves Chesta out, which
|
||
is the same 2P as the default. Open question: is the Moon's Chesta her Paksha.
|
||
4. ``drik_angle``: default continuous longitudes. Alternative: whole-sign
|
||
(integer) aspect angles, i.e. the quarter / half / three-quarter / full
|
||
aspects. Open question: continuous degrees or integer aspects.
|
||
5. ``drik_special_aspects``: default the BPHS 26.9-12 special formulas replace
|
||
the general segment. Alternative: general value plus Raman's fixed bonus.
|
||
Open question: replace or add.
|
||
6. ``drik_mercury_jupiter``: default every aspect at a quarter. Alternatives:
|
||
Mercury / Jupiter at full value (1x), quarter plus full (1.25x for a
|
||
benefic caster). Open question: 1, 1.25 or 1/4.
|
||
|
||
Every combination of the options is evaluated (the Sun and Moon items only
|
||
touch those planets). ``shadbala.py`` is in the frozen rectification identity,
|
||
so nothing there changes: the default totals stay, this module adds
|
||
``parameter_sensitivity`` to each planet row and ``minimum_check_status``.
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from decimal import Decimal, ROUND_HALF_UP
|
||
from itertools import product
|
||
from typing import Any, Dict
|
||
|
||
try:
|
||
import shadbala as sb
|
||
except ImportError: # pragma: no cover - package import
|
||
from scripts import shadbala as sb
|
||
|
||
RULING = "占星师 2026-11-08 第五轮裁定 4"
|
||
SEVEN = ("Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn")
|
||
STATUS_SENSITIVE = "parameter_sensitive"
|
||
STATUS_STABLE = "stable_across_open_parameters"
|
||
STATUS_UNVERIFIED = "sensitivity_not_verified"
|
||
|
||
AXES = {
|
||
"saptavargaja_moolatrikona": {
|
||
"default": "d1_degree_band_only",
|
||
"options": ("d1_degree_band_only", "d1_whole_sign", "d1_band_other_vargas_sign", "all_vargas_whole_sign"),
|
||
"open_question": "Saptavargaja:七分盘组成与 Moolatrikona 度数范围(只 D1 度数段 / 整个星座 / 其余六分盘是否也计 45)",
|
||
"planets": SEVEN,
|
||
},
|
||
"ayana_sun": {
|
||
"default": "base_ayana_chesta_equals_ayana",
|
||
"options": ("base_ayana_chesta_equals_ayana", "sun_doubled_in_kala", "sun_doubled_in_kala_and_chesta"),
|
||
"open_question": "Ayana Bala:太阳是否重复计入(A+A / 2A+A / 2A+2A)",
|
||
"planets": ("Sun",),
|
||
},
|
||
"chesta_moon": {
|
||
"default": "moon_chesta_equals_paksha",
|
||
"options": ("moon_chesta_equals_paksha", "moon_chesta_not_counted"),
|
||
"open_question": "Chesta Bala:月亮是否等于 Paksha Bala(P+P / 只计一次 P)",
|
||
"planets": ("Moon",),
|
||
},
|
||
"drik_angle": {
|
||
"default": "continuous_degrees",
|
||
"options": ("continuous_degrees", "whole_sign_integer_aspects"),
|
||
"open_question": "Drik Bala:连续度数还是整数相位(整宫 1/4、1/2、3/4、全相)",
|
||
"planets": SEVEN,
|
||
},
|
||
"drik_special_aspects": {
|
||
"default": "replace_general_segment",
|
||
"options": ("replace_general_segment", "add_to_general_value"),
|
||
"open_question": "特殊相照:替换普通相照还是另加",
|
||
"planets": SEVEN,
|
||
},
|
||
"drik_mercury_jupiter": {
|
||
"default": "quarter",
|
||
"options": ("quarter", "full_replaces_quarter", "quarter_plus_full"),
|
||
"open_question": "水星、木星相照:1/4、1 倍还是 1.25 倍(1/4 + 全值)",
|
||
"planets": SEVEN,
|
||
},
|
||
}
|
||
AXIS_ORDER = tuple(AXES)
|
||
CHAT_RULE = ("minimum_check = parameter_sensitive:达标与否随未定 Shadbala 参数翻转,"
|
||
"聊天与报告不得据此下好坏结论,只写「是否达标取决于未定参数」并列出未定项")
|
||
|
||
|
||
def _lon(name: str, planets: Dict) -> float:
|
||
return sb._planet_longitude(name, planets)
|
||
|
||
|
||
def _sapta(pname: str, planets: Dict, option: str, vargas: Dict[int, Dict[str, int]]) -> float:
|
||
longitude = _lon(pname, planets)
|
||
degree = longitude % 30.0
|
||
mt_sign, mt_start, mt_end = sb._MOOLATRIKONA[pname]
|
||
total = 0.0
|
||
for division, positions in vargas.items():
|
||
sign_idx = positions[pname]
|
||
owner = sb.SIGN_LORDS[sb.SIGNS[sign_idx]]
|
||
in_band = division == 1 and sign_idx == mt_sign and mt_start <= degree < mt_end
|
||
if option == "d1_degree_band_only":
|
||
mt = in_band
|
||
elif option == "d1_whole_sign":
|
||
mt = division == 1 and sign_idx == mt_sign
|
||
elif option == "d1_band_other_vargas_sign":
|
||
mt = in_band or (division != 1 and sign_idx == mt_sign)
|
||
else: # all_vargas_whole_sign
|
||
mt = sign_idx == mt_sign
|
||
if mt:
|
||
total += 45.0
|
||
elif owner == pname:
|
||
total += 30.0
|
||
else:
|
||
total += sb._compound_relation_score(pname, owner, vargas[1])
|
||
return round(total, 2)
|
||
|
||
|
||
def _drik(pname: str, planets: Dict, angle_mode: str, special: str, merc_jup: str) -> float:
|
||
benefics, malefics = sb.classify_drik_planets(planets)
|
||
target = _lon(pname, planets)
|
||
total = Decimal(0)
|
||
for other in sorted(benefics | malefics):
|
||
if other == pname:
|
||
continue
|
||
if angle_mode == "whole_sign_integer_aspects":
|
||
angle = ((int(target // 30) - int(_lon(other, planets) // 30)) % 12) * 30.0
|
||
else:
|
||
angle = target - _lon(other, planets)
|
||
if special == "add_to_general_value":
|
||
strength = sb._raman_sphuta_drishti_virupas(angle, other)
|
||
else:
|
||
strength = sb._sphuta_drishti_virupas(angle, other, "bphs")
|
||
hundredths = Decimal(round(strength * 100))
|
||
sign = 1 if other in benefics else -1
|
||
quarter = hundredths * sign / 4
|
||
if other in ("Mercury", "Jupiter") and merc_jup == "full_replaces_quarter":
|
||
total += hundredths * sign
|
||
elif other in ("Mercury", "Jupiter") and merc_jup == "quarter_plus_full":
|
||
total += quarter + hundredths
|
||
else:
|
||
total += quarter
|
||
return float((total / 100).quantize(Decimal("0.01"), rounding=ROUND_HALF_UP))
|
||
|
||
|
||
def planet_sensitivity(pname: str, row: Dict[str, Any], planets: Dict) -> Dict[str, Any]:
|
||
"""Pass/fail of one planet over every combination of the open options."""
|
||
minimum = row.get("min_required")
|
||
base_virupas = row.get("total_virupas")
|
||
if not isinstance(minimum, (int, float)) or not isinstance(base_virupas, (int, float)):
|
||
return {"status": STATUS_UNVERIFIED, "reason": "row_without_total_or_minimum"}
|
||
sthana = row.get("sthana_bala") if isinstance(row.get("sthana_bala"), dict) else {}
|
||
kala = row.get("kala_bala") if isinstance(row.get("kala_bala"), dict) else {}
|
||
vargas = sb._saptavarga_signs(planets)
|
||
# The default must be reproduced before any alternative is trusted.
|
||
default_sapta = _sapta(pname, planets, "d1_degree_band_only", vargas)
|
||
default_drik = _drik(pname, planets, "continuous_degrees", "replace_general_segment", "quarter")
|
||
if abs(default_sapta - float(sthana.get("sapta_score", default_sapta))) > 0.011 or \
|
||
abs(default_drik - float(row.get("drik_bala", default_drik))) > 0.011:
|
||
return {"status": STATUS_UNVERIFIED, "reason": "default_components_not_reproduced",
|
||
"reproduced": {"sapta_score": default_sapta, "drik_bala": default_drik}}
|
||
|
||
sapta_delta = {option: round(_sapta(pname, planets, option, vargas) - default_sapta, 2)
|
||
for option in AXES["saptavargaja_moolatrikona"]["options"]}
|
||
ayana = float(kala.get("base_ayana", kala.get("ayana", 0.0)) or 0.0)
|
||
ayana_delta = {"base_ayana_chesta_equals_ayana": 0.0, "sun_doubled_in_kala": ayana,
|
||
"sun_doubled_in_kala_and_chesta": 2 * ayana} if pname == "Sun" else {"base_ayana_chesta_equals_ayana": 0.0}
|
||
paksha = float(row.get("chesta_bala", 0.0) or 0.0)
|
||
chesta_delta = {"moon_chesta_equals_paksha": 0.0, "moon_chesta_not_counted": -paksha} if pname == "Moon" \
|
||
else {"moon_chesta_equals_paksha": 0.0}
|
||
drik_delta = {
|
||
combo: round(_drik(pname, planets, *combo) - default_drik, 2)
|
||
for combo in product(AXES["drik_angle"]["options"], AXES["drik_special_aspects"]["options"],
|
||
AXES["drik_mercury_jupiter"]["options"])
|
||
}
|
||
|
||
default_meets = base_virupas / sb.VIRUPAS_PER_RUPA >= minimum
|
||
totals = []
|
||
flip_sets: set[frozenset[str]] = set()
|
||
for (sapta, s_d), (ayana_opt, a_d), (chesta_opt, c_d), (drik_combo, d_d) in product(
|
||
sapta_delta.items(), ayana_delta.items(), chesta_delta.items(), drik_delta.items()):
|
||
virupas = base_virupas + s_d + a_d + c_d + d_d
|
||
rupas = virupas / sb.VIRUPAS_PER_RUPA
|
||
totals.append(rupas)
|
||
if (rupas >= minimum) != default_meets:
|
||
chosen = {"saptavargaja_moolatrikona": sapta, "ayana_sun": ayana_opt, "chesta_moon": chesta_opt,
|
||
"drik_angle": drik_combo[0], "drik_special_aspects": drik_combo[1],
|
||
"drik_mercury_jupiter": drik_combo[2]}
|
||
flip_sets.add(frozenset(axis for axis, value in chosen.items() if value != AXES[axis]["default"]))
|
||
# Minimal flipping sets: moving these axes off their defaults flips the verdict and no subset
|
||
# does (the full product contains every subset, so this is exact).
|
||
minimal = sorted((sorted(item, key=AXIS_ORDER.index) for item in flip_sets
|
||
if not any(other < item for other in flip_sets)), key=lambda row: (len(row), row))
|
||
flipping_axes = {axis for row in minimal for axis in row}
|
||
flips = bool(flip_sets)
|
||
# Single-axis flips: each axis moved alone, the rest at their defaults.
|
||
single = []
|
||
for axis, deltas in (("saptavargaja_moolatrikona", sapta_delta), ("ayana_sun", ayana_delta),
|
||
("chesta_moon", chesta_delta)):
|
||
if any(((base_virupas + d) / sb.VIRUPAS_PER_RUPA >= minimum) != default_meets for d in deltas.values()):
|
||
single.append(axis)
|
||
for index, axis in enumerate(("drik_angle", "drik_special_aspects", "drik_mercury_jupiter")):
|
||
for combo, d in drik_delta.items():
|
||
others_default = all(combo[i] == AXES[name]["default"] for i, name in
|
||
enumerate(("drik_angle", "drik_special_aspects", "drik_mercury_jupiter")) if i != index)
|
||
if others_default and ((base_virupas + d) / sb.VIRUPAS_PER_RUPA >= minimum) != default_meets:
|
||
single.append(axis)
|
||
break
|
||
return {
|
||
"status": STATUS_SENSITIVE if flips else STATUS_STABLE,
|
||
"default_meets_minimum": default_meets,
|
||
"min_required": minimum,
|
||
"default_rupas": round(base_virupas / sb.VIRUPAS_PER_RUPA, 4),
|
||
"rupas_range": [round(min(totals), 4), round(max(totals), 4)],
|
||
"combinations_evaluated": len(totals),
|
||
"flips_with_axes": [axis for axis in AXIS_ORDER if axis in flipping_axes],
|
||
"minimal_flip_sets": minimal,
|
||
"flips_with_single_axis": [axis for axis in AXIS_ORDER if axis in single],
|
||
"open_questions": [AXES[axis]["open_question"] for axis in AXIS_ORDER if axis in flipping_axes],
|
||
"component_deltas_virupas": {
|
||
"saptavargaja_moolatrikona": sapta_delta,
|
||
**({"ayana_sun": ayana_delta} if pname == "Sun" else {}),
|
||
**({"chesta_moon": chesta_delta} if pname == "Moon" else {}),
|
||
"drik": {"|".join(combo): delta for combo, delta in drik_delta.items()},
|
||
},
|
||
}
|
||
|
||
|
||
def attach_parameter_sensitivity(result: Any, *, planets: Any) -> Any:
|
||
"""Add the flip check to a ``shadbala.calc_shadbala`` result in place; default values unchanged."""
|
||
if not isinstance(result, dict) or not isinstance(result.get("planets"), dict) or not isinstance(planets, dict):
|
||
return result
|
||
sensitive = []
|
||
for pname, row in result["planets"].items():
|
||
if pname not in SEVEN or not isinstance(row, dict):
|
||
continue
|
||
try:
|
||
report = planet_sensitivity(pname, row, planets)
|
||
except Exception as exc: # the default result must survive a failed check
|
||
report = {"status": STATUS_UNVERIFIED, "reason": exc.__class__.__name__}
|
||
row["parameter_sensitivity"] = report
|
||
row["minimum_check_status"] = report["status"]
|
||
if report["status"] == STATUS_SENSITIVE:
|
||
sensitive.append(pname)
|
||
result["minimum_check_sensitivity"] = {
|
||
"ruling": RULING,
|
||
"method": "every combination of the open options below; Sun / Moon items only for those planets",
|
||
"axes": {axis: {"status": STATUS_SENSITIVE, "default": spec["default"], "options": list(spec["options"]),
|
||
"open_question": spec["open_question"]} for axis, spec in AXES.items()},
|
||
"planets_parameter_sensitive": sensitive,
|
||
"chat_rule": CHAT_RULE,
|
||
"defaults_unchanged": True,
|
||
}
|
||
variants = result.get("method_variants")
|
||
if isinstance(variants, dict):
|
||
variants["parameter_sensitive_items"] = {axis: AXES[axis]["open_question"] for axis in AXIS_ORDER}
|
||
return result
|