#!/usr/bin/env python3 """Drik Bala weighting readings of BPHS 27.19 (upstream yinduzhanxing a4b4b267). Her a4b4b267 adds ``weighting_profile`` to ``calc_drik_bala_precise`` and a ``compare_drik_profiles`` diagnostic. ``scripts/shadbala.py`` is in the rectification frozen identity (ERR-110), so the readings live here and call the frozen geometry and classification unchanged. Defaults stay as recorded: geometry = BPHS 26.9-12 piecewise (BUG-1586), weighting = the quarter for every aspect (DRIK_MERCURY_JUPITER_CONVENTION, BUG-1623, astrologer has not ruled). The other two readings are explicit, diagnostic-only variants; they never enter totals or rankings. """ from __future__ import annotations import math import os import sys from decimal import ROUND_HALF_UP, Decimal from typing import Dict # scripts/ on sys.path for the sibling shadbala module (as scripts/arudha_reference). _scripts_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) if _scripts_dir not in sys.path: sys.path.insert(0, _scripts_dir) import shadbala as _sb # noqa: E402 (read-only use; shadbala.py stays the default path) DRIK_WEIGHTING_PROFILES = ("quarter_v1", "mercury_jupiter_full_replacement_v1", "santhanam27_literal_addition_v1") DRIK_GEOMETRY_PROFILES = ("bphs", "raman_gbb") def drik_aspect_contribution(strength: float, aspector: str, benefic: bool, *, weighting_profile: str = "quarter_v1") -> float: """One aspect's signed share. Literal Santhanam 27.19 adds a positive full Mercury / Jupiter aspect after the signed quarter, so a malefic Mercury gives +0.75 of the aspect, not -1.25 (the sign stays disputed).""" if weighting_profile not in DRIK_WEIGHTING_PROFILES: raise ValueError(f"unknown Drik weighting profile: {weighting_profile}") if not math.isfinite(float(strength)) or strength < 0: raise ValueError("aspect strength must be finite and nonnegative") signed = strength if benefic else -strength if aspector in {"Mercury", "Jupiter"}: if weighting_profile == "mercury_jupiter_full_replacement_v1": return signed if weighting_profile == "santhanam27_literal_addition_v1": return signed / 4 + strength return signed / 4 def calc_drik_bala_profiled(pname: str, all_planets: Dict, variant: str = "bphs", *, weighting_profile: str = "quarter_v1") -> float: """Drik under an explicit weighting; ``quarter_v1`` is the frozen default.""" if weighting_profile not in DRIK_WEIGHTING_PROFILES: raise ValueError(f"unknown Drik weighting profile: {weighting_profile}") if weighting_profile == "quarter_v1": return _sb.calc_drik_bala_precise(pname, all_planets, variant) if pname not in all_planets: return 0.0 benefics, malefics = _sb.classify_drik_planets(all_planets, variant) target_lon = _sb._planet_longitude(pname, all_planets) total = Decimal(0) for other_name in sorted(benefics | malefics): # fixed order (BUG-1576) if other_name == pname: continue strength = _sb._sphuta_drishti_virupas( target_lon - _sb._planet_longitude(other_name, all_planets), other_name, variant) total += Decimal(str(drik_aspect_contribution( strength, other_name, other_name in benefics, weighting_profile=weighting_profile))) return float(total.quantize(Decimal("0.01"), rounding=ROUND_HALF_UP)) def compare_drik_profiles(all_planets: Dict) -> Dict: """Replay the disputed readings without changing production totals.""" names = [n for n in ('Sun', 'Moon', 'Mars', 'Mercury', 'Jupiter', 'Venus', 'Saturn') if n in all_planets] baseline = {n: _sb.calc_drik_bala_precise(n, all_planets) for n in names} variants = [] for geometry in DRIK_GEOMETRY_PROFILES: for weighting in DRIK_WEIGHTING_PROFILES: values = {n: calc_drik_bala_profiled(n, all_planets, geometry, weighting_profile=weighting) for n in names} variants.append({'aspect_profile': geometry, 'weighting_profile': weighting, 'virupas': values, 'delta_from_default': {n: round(values[n] - baseline[n], 2) for n in names}}) return {'admission_state': 'diagnostic_only', 'natural_classification': 'existing_classify_drik_planets_unchanged', 'default': {'aspect_profile': 'bphs', 'weighting_profile': 'quarter_v1'}, 'variants': variants}