fix: route synastry api through full ashtakoot engine

This commit is contained in:
732642856
2026-06-25 23:38:16 +08:00
parent b5fcc30fd8
commit 5e48f18da0
2 changed files with 30 additions and 3 deletions
+14 -2
View File
@@ -1999,11 +1999,23 @@ class JyotishAPIHandler(BaseHTTPRequestHandler):
}
def _compute_synastry(self, body):
from synastry import calc_ashtakoot
return calc_ashtakoot(
from ashtakoot import calculate_ashtakoot
result = calculate_ashtakoot(
self._normalize_degree(body, 'male_moon', 0),
self._normalize_degree(body, 'female_moon', 0),
)
# Backward-compatible aliases for older frontend/report consumers.
result['is_approved'] = result.get('is_match_approved', False)
result['assessment'] = (
'优秀' if result.get('total_score', 0) >= 28 else
'良好' if result.get('total_score', 0) >= 21 else
'一般' if result.get('total_score', 0) >= 18 else
'不推荐'
)
result['male'] = result.get('male_details', {})
result['female'] = result.get('female_details', {})
return result
def _compute_dasha_system(self, body):
dasha_key = body.get('dasha', body.get('name', 'vimshottari'))
+16 -1
View File
@@ -70,10 +70,25 @@ def test_synastry_rejects_non_numeric_moon_degree() -> None:
def test_synastry_normalizes_360_degree_boundary() -> None:
handler = _handler()
result = handler._compute_synastry({'male_moon': 360, 'female_moon': 0})
assert result['male']['nakshatra'] == result['female']['nakshatra']
assert result['male_details']['nakshatra'] == result['female_details']['nakshatra']
assert result['max_score'] == 36.0
def test_synastry_api_uses_full_ashtakoot_engine() -> None:
from ashtakoot import calculate_ashtakoot
handler = _handler()
api_result = handler._compute_synastry({'male_moon': 0, 'female_moon': 60})
engine_result = calculate_ashtakoot(0, 60)
assert api_result['method'] == engine_result['method']
assert api_result['scores'] == engine_result['scores']
assert api_result['total_score'] == engine_result['total_score']
assert api_result['is_match_approved'] == engine_result['is_match_approved']
assert api_result['scores']['Vashya'] == 0.5
assert 'BadConstellations' in api_result['additional_kutas']
def test_prashna_rejects_non_string_question() -> None:
handler = _handler()
with pytest.raises(BadRequest, match='question must be a string'):