feat(dasha): 接口 Yogini 副本挂上小运,完整解读不变
大运行深拷贝后再挂 antardasha。虚构盘对照改成去掉小运后与完整解读逐字段相等。 Co-Authored-By: Grok (agent loop) Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Grok (agent loop)
Cursor
parent
6eeb98c774
commit
3490e89403
@@ -12,6 +12,7 @@ This module must not import `jyotish_api_server` or PyJHora.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
@@ -287,8 +288,22 @@ def compute_dasha(
|
||||
body = body or {}
|
||||
alt, conditional, planet_lons = build_reading_birth_info(birth_dt, planets or {}, ascendant, body)
|
||||
if key == "yogini":
|
||||
payload = _load("yogini_dasha").calculate_yogini_dasha({**alt, "moon_longitude": conditional["moon_longitude"]})
|
||||
return {"periods": _major_rows(payload)}
|
||||
module = _load("yogini_dasha")
|
||||
payload = module.calculate_yogini_dasha({**alt, "moon_longitude": conditional["moon_longitude"]})
|
||||
year_days = 365.25
|
||||
if isinstance(payload, dict) and payload.get("dasha_year_days") is not None:
|
||||
year_days = float(payload["dasha_year_days"])
|
||||
periods = []
|
||||
for row in _major_rows(payload):
|
||||
copied = copy.deepcopy(row)
|
||||
if isinstance(copied, dict):
|
||||
copied["antardasha"] = module.yogini_antardashas(
|
||||
copied,
|
||||
birth_dt=birth_dt,
|
||||
year_days=year_days,
|
||||
)
|
||||
periods.append(copied)
|
||||
return {"periods": periods}
|
||||
if key == "ashtottari":
|
||||
payload = _load("ashtottari_dasha").calculate_ashtottari_dasha({
|
||||
**alt,
|
||||
|
||||
@@ -201,6 +201,18 @@ def _period_covering(majors, moment: datetime):
|
||||
return None
|
||||
|
||||
|
||||
def _without_antardasha(rows):
|
||||
cleaned = []
|
||||
for row in rows:
|
||||
if isinstance(row, dict) and "antardasha" in row:
|
||||
item = dict(row)
|
||||
item.pop("antardasha")
|
||||
cleaned.append(item)
|
||||
else:
|
||||
cleaned.append(row)
|
||||
return cleaned
|
||||
|
||||
|
||||
def test_api_major_periods_match_full_reading_modules() -> None:
|
||||
report = _fiction_reading()
|
||||
modules = report["modules"]
|
||||
@@ -210,7 +222,16 @@ def test_api_major_periods_match_full_reading_modules() -> None:
|
||||
result = handler._compute_dasha_system(_chart_body(report, key))
|
||||
assert result["precision"] == "engine_module", key
|
||||
assert result["precision"] not in {"generic", "calculator"}
|
||||
assert result["periods"] == engine_rows, key
|
||||
if key == "yogini":
|
||||
# 原值:result["periods"] == engine_rows
|
||||
# 新值:去掉 antardasha 后相等
|
||||
# 原因:小运只挂在接口返回的副本上,完整解读的 Yogini 行保持原字段
|
||||
assert _without_antardasha(result["periods"]) == engine_rows, key
|
||||
assert result["periods"]
|
||||
assert all(isinstance(row, dict) and row.get("antardasha") for row in result["periods"])
|
||||
assert all(isinstance(row, dict) and "antardasha" not in row for row in engine_rows)
|
||||
else:
|
||||
assert result["periods"] == engine_rows, key
|
||||
|
||||
|
||||
def test_unimplemented_dasha_keys_are_rejected() -> None:
|
||||
|
||||
Reference in New Issue
Block a user