Port from yinduzhanxing 5fb8379c (MIT): Naisargika, Kaala, Karaka, Tara, Lagnamsaka, Yogardha, Mandooka, Paryaaya and Padanadhamsa dashas; Sarvatobhadra, Kota and Kalanala chakras; Nakshatra Latta; Pachakadi; Raman Amsayu and Pindayu. Producers and their upstream tests are copied; scripts/upstream_technique_layers.py feeds them our natal and transit positions and attaches chart.consultation_native_layers.upstream_techniques. - dasha_registry: kaala and padanadhamsa keys (35 -> 37); the nine ported dashas are served by compute_dasha or fail closed with upstream's reason. - technique_registry.json: 16 partial entries; README badges follow. - Evidence lookup section `upstream_techniques` in the consultation tool. - Boundaries: Kalanala carries no PyJHora (AGPL) grid coordinates; Padanadhamsa/Lagnamsaka run on our Narayana engine (no Rath Table 12, PVR co-lord variants or second cycle). PyJHora observers and the Amsayu worked-example scaffold live in scripts/research (root .py budget). - PyJHora black-box cross-checks: Naisargika (lords/years) and Kaala (seed segment and fraction within 5e-4) on a public chart. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
121 lines
5.8 KiB
Python
121 lines
5.8 KiB
Python
"""Configurable Karaka Dasha foundation.
|
|
|
|
The degree ranking is deterministic; tradition-specific period lengths and
|
|
birth balance are explicit inputs so a school is never silently assumed.
|
|
"""
|
|
from datetime import date, datetime, timedelta
|
|
from math import isfinite
|
|
from typing import Dict, Mapping, Optional, Sequence, Union
|
|
|
|
YEAR_DAYS = 365.25636
|
|
|
|
|
|
DEFAULT_KARAKA_ORDER = ("AK", "AmK", "BK", "MK", "PiK", "PK", "GK", "DK")
|
|
SEVEN_KARAKA_ORDER = ("AK", "AmK", "BK", "MK", "PK", "GK", "DK")
|
|
|
|
|
|
def rank_chara_karakas(
|
|
degrees: Mapping[str, float], *, include_rahu: bool = False,
|
|
rahu_mode: str = "direct_legacy",
|
|
) -> Sequence[Dict[str, object]]:
|
|
"""Rank classical planets by longitude within sign, highest first.
|
|
|
|
Rahu supports direct_legacy or reverse_30_minus. Exact ties retain their
|
|
candidate roles without assigning an arbitrary alphabetical winner.
|
|
"""
|
|
required = ("Sun", "Moon", "Mars", "Mercury", "Jupiter", "Venus", "Saturn") + (("Rahu",) if include_rahu else ())
|
|
missing = [name for name in required if name not in degrees]
|
|
if missing:
|
|
raise ValueError(f"missing planetary degrees: {', '.join(missing)}")
|
|
names = list(required)
|
|
if rahu_mode not in {"direct_legacy", "reverse_30_minus"}:
|
|
raise ValueError("unsupported rahu_mode")
|
|
rows = []
|
|
for name in names:
|
|
value = float(degrees[name])
|
|
if not isfinite(value):
|
|
raise ValueError(f"non-finite longitude: {name}")
|
|
longitude = value % 360.0
|
|
degree = longitude % 30.0
|
|
score = 30.0 - degree if name == "Rahu" and rahu_mode == "reverse_30_minus" else degree
|
|
rows.append({"planet": name, "degree_in_sign": degree,
|
|
"ranking_degree": score, "longitude": longitude})
|
|
rows.sort(key=lambda row: (-row["ranking_degree"], row["planet"]))
|
|
labels = DEFAULT_KARAKA_ORDER if include_rahu else SEVEN_KARAKA_ORDER
|
|
result = []
|
|
for row in rows:
|
|
indices = [i for i, other in enumerate(rows) if other["ranking_degree"] == row["ranking_degree"]]
|
|
result.append(dict(row, karaka=labels[indices[0]] if len(indices) == 1 else None,
|
|
candidate_karakas=[labels[i] for i in indices]))
|
|
return result
|
|
|
|
|
|
def calculate_karaka_dasha(
|
|
degrees: Mapping[str, float], *, include_rahu: bool = False,
|
|
duration_years_by_karaka: Optional[Mapping[str, float]] = None,
|
|
birth_balance: Optional[Mapping[str, object]] = None,
|
|
basis: str = "D1",
|
|
cycle_anchor: Optional[Union[date, datetime]] = None,
|
|
rahu_mode: str = "direct_legacy",
|
|
) -> Dict[str, object]:
|
|
if basis not in {"D1", "D9"}:
|
|
raise ValueError("basis must be D1 or D9")
|
|
ranking = rank_chara_karakas(degrees, include_rahu=include_rahu, rahu_mode=rahu_mode)
|
|
if any(row["karaka"] is None for row in ranking):
|
|
return {"system": "karaka_dasha", "status": "blocked",
|
|
"blockers": ["karaka_degree_tie_requires_profile"],
|
|
"karaka_ranking": ranking, "basis": basis, "rahu_mode": rahu_mode}
|
|
if not duration_years_by_karaka:
|
|
return {"system": "karaka_dasha", "status": "blocked",
|
|
"blockers": ["duration_profile_required"], "basis": basis,
|
|
"karaka_ranking": ranking}
|
|
balance_fraction = 1.0
|
|
balance_state = {"status": "not_supplied", "mode": "full_period"}
|
|
if birth_balance is not None:
|
|
if set(birth_balance) != {"mode", "remaining_fraction"} or birth_balance["mode"] != "explicit_remaining_fraction":
|
|
return {"system": "karaka_dasha", "status": "blocked",
|
|
"blockers": ["unsupported_birth_balance_profile"],
|
|
"karaka_ranking": ranking, "basis": basis}
|
|
value = birth_balance["remaining_fraction"]
|
|
if isinstance(value, bool):
|
|
raise ValueError("remaining_fraction must be finite and in (0, 1]")
|
|
balance_fraction = float(value)
|
|
if not isfinite(balance_fraction) or not 0 < balance_fraction <= 1:
|
|
raise ValueError("remaining_fraction must be finite and in (0, 1]")
|
|
balance_state = {"status": "applied", "mode": "explicit_remaining_fraction",
|
|
"remaining_fraction": balance_fraction}
|
|
periods = []
|
|
current = None
|
|
if cycle_anchor is not None:
|
|
current = cycle_anchor if isinstance(cycle_anchor, datetime) else datetime.combine(cycle_anchor, datetime.min.time())
|
|
missing = []
|
|
for index, row in enumerate(ranking):
|
|
label = row["karaka"]
|
|
if label not in duration_years_by_karaka:
|
|
missing.append(label)
|
|
continue
|
|
years = float(duration_years_by_karaka[label])
|
|
if not isfinite(years) or years <= 0:
|
|
raise ValueError(f"duration must be finite and positive: {label}")
|
|
full_years = years
|
|
if index == 0:
|
|
years *= balance_fraction
|
|
period = {"karaka": label, "planet": row["planet"], "years": years,
|
|
"full_years": full_years}
|
|
if current is not None:
|
|
end = current + timedelta(days=years * YEAR_DAYS)
|
|
period.update({"start": current.isoformat(), "end": end.isoformat()})
|
|
current = end
|
|
periods.append(period)
|
|
if missing:
|
|
return {"system": "karaka_dasha", "status": "blocked",
|
|
"blockers": ["duration_profile_incomplete"], "missing_karakas": missing,
|
|
"basis": basis, "karaka_ranking": ranking}
|
|
return {"system": "karaka_dasha", "status": "executed",
|
|
"basis": basis, "include_rahu": include_rahu,
|
|
"rahu_mode": rahu_mode,
|
|
"birth_balance": balance_state,
|
|
"coordinate_contract": "caller_supplied_basis_longitudes_no_varga_conversion",
|
|
"karaka_ranking": ranking, "periods": periods,
|
|
"cycle_anchor": cycle_anchor.isoformat() if cycle_anchor is not None else None}
|