fix: preserve theme lords in API case matching

This commit is contained in:
732642856
2026-07-18 03:11:50 +08:00
parent d24397a229
commit c9ce5cbc14
2 changed files with 28 additions and 3 deletions
+10 -3
View File
@@ -16,11 +16,11 @@ if str(SCRIPT_DIR) not in sys.path:
try:
from scripts.domain_calculation_service import compute_chart
from scripts.timing_precision_contract import build_timing_precision_contract
from scripts.varga import calc_varga
from scripts.varga import SIGN_LORDS, calc_varga
except ModuleNotFoundError: # pragma: no cover - direct script execution
from domain_calculation_service import compute_chart
from timing_precision_contract import build_timing_precision_contract
from varga import calc_varga
from varga import SIGN_LORDS, calc_varga
ROOT = Path(__file__).resolve().parents[1]
@@ -54,8 +54,15 @@ def _sign(chart: dict[str, Any], planet: str) -> str | None:
def _domain_lord_sign(chart: dict[str, Any], domain: str) -> str | None:
house = DOMAIN_HOUSES.get(domain)
houses = chart.get("houses") if isinstance(chart, dict) else None
house_value = houses.get(house) if house and isinstance(houses, dict) else None
house_index = int(house.split("_", 1)[1]) if house else None
house_value = None
if isinstance(houses, dict) and house:
house_value = houses.get(house)
if house_value is None and house_index is not None:
house_value = houses.get(house_index) or houses.get(str(house_index))
lord = house_value.get("lord") if isinstance(house_value, dict) else None
if not isinstance(lord, str) and isinstance(house_value, dict):
lord = SIGN_LORDS.get(house_value.get("sign") or house_value.get("cusp_sign"))
return _sign(chart, lord) if isinstance(lord, str) else None
@@ -166,6 +166,24 @@ def test_marriage_similarity_adds_d9_only_when_both_charts_have_longitudes() ->
assert "D9" not in similarity["uncompared_layers"]
def test_api_house_shape_keeps_theme_lord_in_similarity() -> None:
chart = _varga_chart()
chart["houses"] = {10: {"sign": "Taurus", "sign_idx": 1}}
cases = [{
"case_id": "api_house_shape", "subject": {"name": "Public Example"}, "chart": chart,
"source": {"url": "https://example.com/birth", "source_grade": "primary"},
"event_outcomes": [{
"domain": "career", "event_type": "career_breakthrough", "event_date": "2007-01-09",
"outcome": "Public career event", "source": {"url": "https://example.com/event", "source_grade": "primary"},
}],
"replay": {"outcome_replay_status": "replayed", "do_not_use_for_prediction": False},
}]
selected = select_similar_public_cases(chart, ["career"], cases=cases)
assert "domain_lord_sign" in selected["cases"][0]["similarity"]["matching_factors"]
def test_default_manifest_exposes_kahlo_health_as_context_only() -> None:
from scripts.domain_calculation_service import compute_chart