Files
Jyotisha/scripts/shadbala_display.py
T
ClaudeandClaude Opus 5.5 9d7a17a1a5 fix: chat card, annual D2 and remedies follow the astrologer's second-batch rulings (BUG-1964)
Shadbala reads 达到 / 未达到最低线 (her item 9; owner agreed) and the card carries
min_required for the 判断依据 line; required_strength_ratio beside ishta_bala_pct;
remedies no longer trigger from Shadbala (unaccepted_threshold). Education uses D24,
not D5 (item 7). Vighati keeps its position only (item 1); the 64th Navamsa from the
Moon and Pranapada take part as auxiliary layers with her fields (items 2, 3). The
annual natal two-Hora D2 gives Hora membership instead of the lagna lord's house,
and its birth-time stability check compares that membership (item 8).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-17 23:40:26 +08:00

127 lines
6.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""How a Shadbala strength is shown (astrologer rulings 2026-10-03 甲13, BUG-1208).
Whether the planet meets the BPHS minimum (BPHS ch. 27 vv. 32-33, the
`shadbala.MIN_REQUIRED` table). `shadbala.py` is in the frozen rectification
identity, so the fields are added here, at display time, from values the engine
already returns; nothing is recomputed.
BUG-1961 (占星师 2026-11-17 问答数据口径 Q2): the site's own band (150/125/100/75/50 %
of that minimum -> 极强…极弱) has no named rule or source, so it is no longer
presented. `minimum_fields` / `row_fields` stopped returning `level` and
`level_source`; the engine still computes `strength_level` (the rectification
feature hash covers the whole row) but no surface shows it. What stays: the
minimum line, met / not met, and the raw total ÷ minimum ratio.
"""
from __future__ import annotations
from typing import Any, Dict, Optional
LEVEL_SOURCE = 'site_band'
SITE_BAND_SUFFIX = '(网站分档)'
SITE_BAND_SUFFIX_EN = ' (site band)'
MEETS_ZH = '达到 BPHS 最低要求'
MISSES_ZH = '未达到 BPHS 最低要求'
MEETS_EN = 'meets the BPHS minimum'
MISSES_EN = 'below the BPHS minimum'
def _number(value: Any) -> Optional[float]:
return float(value) if isinstance(value, (int, float)) and not isinstance(value, bool) else None
def minimum_fields(rupas: Any, min_required: Any, band: Any = None) -> Dict[str, Any]:
"""`min_required`, `meets_minimum`, `minimum_check`.
原值: 另外返回 `level`(如「略弱(网站分档)」)和 `level_source: site_band`
新值: 不再返回这两项;`band` 参数保留只为不改调用方,值不使用
原因: BUG-1961,占星师 2026-11-17 Q2:分档没有具名规则和来源,冻结前不自动显示
"""
total = _number(rupas)
minimum = _number(min_required)
meets = None if total is None or minimum is None else total >= minimum
return {
'min_required': minimum,
'meets_minimum': meets,
'minimum_check': None if meets is None else (MEETS_ZH if meets else MISSES_ZH),
}
PARAMETER_SENSITIVE = 'parameter_sensitive'
def row_fields(row: Dict[str, Any]) -> Dict[str, Any]:
"""Display fields for one `shadbala.calc_shadbala` planet row.
占星师 2026-11-08 第五轮裁定 4: when `shadbala_service.sensitivity` found that the open
parameter choices flip the planet's pass/fail, `minimum_check` is
`parameter_sensitive` (the default verdict stays in `minimum_check_default`)
and the open questions that flip it are listed.
"""
fields = minimum_fields(row.get('total_rupas', row.get('rupas')), row.get('min_required'), row.get('strength_level'))
sensitivity = row.get('parameter_sensitivity') if isinstance(row.get('parameter_sensitivity'), dict) else {}
if row.get('minimum_check_status') == PARAMETER_SENSITIVE and fields.get('minimum_check'):
fields['minimum_check_default'] = fields['minimum_check']
fields['minimum_check'] = PARAMETER_SENSITIVE
fields['minimum_open_questions'] = list(sensitivity.get('open_questions') or [])
elif row.get('minimum_check_status'):
fields['minimum_check_status'] = row['minimum_check_status']
return fields
BAND_EN = {'极强': 'very strong', '强': 'strong', '充足': 'adequate', '略弱': 'slightly weak', '弱': 'weak', '极弱': 'very weak'}
def band_text(band: Any, language: str = 'zh') -> Optional[str]:
if band in (None, ''):
return None
if language == 'en':
return f"{BAND_EN.get(str(band), str(band))}{SITE_BAND_SUFFIX_EN}"
return f'{band}{SITE_BAND_SUFFIX}'
def check_text(meets: Optional[bool], language: str = 'zh') -> str:
if meets is None:
return '-'
if language == 'en':
return MEETS_EN if meets else MISSES_EN
return MEETS_ZH if meets else MISSES_ZH
SENSITIVE_ZH = 'parameter_sensitive(是否达到 BPHS 最低要求取决于未定 Shadbala 参数,不据此下好坏结论)'
SENSITIVE_EN = 'parameter_sensitive (whether the BPHS minimum is met depends on open Shadbala parameters; no good/bad conclusion)'
def row_check_text(row: Dict[str, Any], language: str = 'zh') -> str:
"""`check_text` for a whole row: parameter_sensitive wins over the default verdict (第五轮裁定 4)."""
if isinstance(row, dict) and row.get('minimum_check_status') == PARAMETER_SENSITIVE:
return SENSITIVE_EN if language == 'en' else SENSITIVE_ZH
return check_text(row_fields(row)['meets_minimum'] if isinstance(row, dict) else None, language)
REQUIRED_STRENGTH_SEMANTICS = 'deprecated_alias_of_required_strength_pct_not_ishta_phala'
def attach_required_strength_alias(result: Any) -> Any:
"""Add `required_strength_pct` beside `ishta_bala_pct` on every planet row, in place.
产品 2026-11-07 同步占星师交接分支 99076dad:`ishta_bala_pct` 是总 Rupa ÷ BPHS 最低
要求 × 100(达标比),不是 Ishta Phala。她在 `shadbala.calc_shadbala` 里加了明确名
`required_strength_pct` 和别名说明 `ishta_bala_pct_semantics`;本仓 `shadbala.py`
在冻结身份里(BUG-1699 测试),所以同名字段在这里补,值照抄、不重算。
"""
planets = result.get('planets') if isinstance(result, dict) else None
if not isinstance(planets, dict):
return result
for row in planets.values():
if isinstance(row, dict) and _number(row.get('ishta_bala_pct')) is not None:
row.setdefault('required_strength_pct', row['ishta_bala_pct'])
row.setdefault('ishta_bala_pct_semantics', REQUIRED_STRENGTH_SEMANTICS)
# BUG-1964(占星师 2026-11-17 第二批第 9 项):`ishta_bala_pct` 若只是总分 ÷ 最低线,
# 迁到 `required_strength_ratio` 等不混淆的名字;旧字段保留供兼容读取。
# 值取引擎给的 pct ÷ 100(引擎已把 pct 取到 0.1);最低线比较仍用 total_rupas 与 min_required 原值,
# 不用这个比值;显示取整另由页面做。
row.setdefault('required_strength_ratio', _number(row['ishta_bala_pct']) / 100.0)
return result