Spaces:
Running
Running
Download test_baba_1952.py from sisithefox/astrology-ziwei-api: direct link, hf CLI and curl.
- Browser
- Download file 8.93 kB
-
https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/test_baba_1952.py
- Command line
-
hf download hf://spaces/sisithefox/astrology-ziwei-api/test_baba_1952.py
-
curl -L -o test_baba_1952.py https://huggingface.co/spaces/sisithefox/astrology-ziwei-api/resolve/main/test_baba_1952.py
8.93 kB
| #!/usr/bin/env python3 | |
| """ | |
| 测试爸爸案例 (1952-05-28 寅时 男) | |
| 验证紫微斗数系统准确性 - 父亲案例 | |
| """ | |
| import subprocess | |
| import json | |
| from datetime import datetime | |
| from daxun_analyzer import DaxunAnalyzer | |
| from sihua_analyzer import SihuaAnalyzer | |
| # 爸爸的出生信息 | |
| # 农历五月初五,天蒙蒙亮(3-5点,寅时或卯时) | |
| # 先用寅时(3:00-5:00中间4:00)测试 | |
| BABA_DATA = { | |
| "birth_date": "1952-05-28", | |
| "birth_time": "04:00", # 寅时 | |
| "gender": "男", | |
| "is_leap_month": False, | |
| "fix_leap": True | |
| } | |
| def analyze_baba_chart(): | |
| """分析爸爸的命盘""" | |
| print("=" * 80) | |
| print("🔮 紫微斗数命盘分析 - 爸爸案例 (1952-05-28 寅时 男)") | |
| print("=" * 80) | |
| print() | |
| # 1. 获取紫微命盘 | |
| print("【步骤1】获取紫微命盘...") | |
| result = subprocess.run( | |
| ['node', 'ziwei_service.js'], | |
| input=json.dumps(BABA_DATA), | |
| capture_output=True, | |
| text=True, | |
| timeout=10 | |
| ) | |
| if result.returncode != 0: | |
| print(f"❌ 排盘失败: {result.stderr}") | |
| return | |
| ziwei_chart = json.loads(result.stdout) | |
| print("✅ 排盘成功!") | |
| print() | |
| # 2. 提取命盘基本信息 | |
| print("【步骤2】命盘基本信息") | |
| print("-" * 80) | |
| chart_info = ziwei_chart.get('chart', {}) | |
| print(f"出生日期: {chart_info.get('solar', '')}") | |
| print(f"农历: {chart_info.get('lunar', '')}") | |
| print(f"性别: {chart_info.get('gender', '')}") | |
| print(f"命宫: {chart_info.get('ming_gong', '')}") | |
| print(f"身宫: {chart_info.get('shen_gong', '')}") | |
| print(f"五行局: {chart_info.get('wu_xing_ju', '')}") | |
| print(f"年干: {chart_info.get('year_heavenly_stem', '')}") | |
| print() | |
| # 3. 查看各宫位星曜 | |
| print("【步骤3】十二宫位星曜配置") | |
| print("-" * 80) | |
| palaces = ziwei_chart.get('palaces', []) | |
| for palace in palaces: | |
| palace_name = palace.get('name', '') | |
| is_ming = '【命宫】' if palace_name == '命宫' else '' | |
| is_shen = '【身宫】' if palace.get('is_shen_gong', False) else '' | |
| # 特别标注关键宫位 | |
| highlight = '' | |
| if palace_name == '夫妻': | |
| highlight = '【婚姻宫】' | |
| elif palace_name == '疾厄': | |
| highlight = '【健康宫】' | |
| elif palace_name == '官禄': | |
| highlight = '【事业宫】' | |
| print(f"\n{palace_name} {is_ming}{is_shen}{highlight}") | |
| # 主星 | |
| major_stars = palace.get('major_stars', []) | |
| if major_stars: | |
| major_names = [] | |
| for star in major_stars: | |
| if isinstance(star, dict): | |
| name = star.get('name', '') | |
| brightness = star.get('brightness', '') | |
| major_names.append(f"{name}({brightness})" if brightness else name) | |
| else: | |
| major_names.append(star) | |
| print(f" 主星: {', '.join(major_names)}") | |
| else: | |
| print(f" 主星: 空宫") | |
| # 副星 | |
| minor_stars = palace.get('minor_stars', []) | |
| if minor_stars: | |
| minor_names = [] | |
| for star in minor_stars: | |
| if isinstance(star, dict): | |
| minor_names.append(star.get('name', '')) | |
| else: | |
| minor_names.append(star) | |
| if minor_names: | |
| print(f" 副星: {', '.join(minor_names[:8])}") # 显示前8个 | |
| print() | |
| print("-" * 80) | |
| print() | |
| # 4. 四化分析 | |
| print("【步骤4】四化飞星分析") | |
| print("-" * 80) | |
| sihua_analyzer = SihuaAnalyzer(ziwei_chart) | |
| sihua_analysis = sihua_analyzer.analyze_all_sihua() | |
| year_sihua = sihua_analysis.get('year_sihua', {}) | |
| if year_sihua: | |
| for sihua_type, data in year_sihua.items(): | |
| star = data.get('star', '') | |
| palace = data.get('palace', '') | |
| impact_score = data.get('impact_score', 0) | |
| interpretation = data.get('interpretation', '') | |
| emoji = '🎁' if sihua_type == '化禄' else '👑' if sihua_type == '化权' else '📚' if sihua_type == '化科' else '⚠️' | |
| print(f"\n{emoji} {sihua_type}: {star} 在 {palace}") | |
| print(f" 影响分数: {impact_score}") | |
| print(f" 解释: {interpretation}") | |
| overall = sihua_analysis.get('overall_judgment', {}) | |
| print(f"\n总体评价: {overall.get('message', '')}") | |
| print(f"总分: {overall.get('total_score', 0)}") | |
| print() | |
| print("-" * 80) | |
| print() | |
| # 5. 大运分析 | |
| print("【步骤5】大运分析(关键人生阶段)") | |
| print("-" * 80) | |
| birth_year = 1952 | |
| daxun_analyzer = DaxunAnalyzer(ziwei_chart) | |
| # 分析关键年份的大运 | |
| key_years = [ | |
| (1970, "家境清寒,兄弟姐妹多"), | |
| (1978, "开始恋爱"), | |
| (1981, "结婚生女"), | |
| (1983, "重病后治愈"), | |
| (1990, "工作期"), | |
| (2000, "工作期"), | |
| (2010, "接近退休"), | |
| (2017, "退休后") | |
| ] | |
| for year, event in key_years: | |
| age = year - birth_year | |
| daxun = daxun_analyzer.analyze_current_daxun(age) | |
| if 'error' not in daxun: | |
| palace = daxun.get('palace_name', '') | |
| daxun_year = daxun.get('daxun_year', 0) | |
| phase = daxun.get('phase_name', '') | |
| is_empty = daxun.get('is_empty_palace', False) | |
| strength = daxun.get('strength_score', 0) | |
| is_transition = daxun.get('is_transition', False) | |
| empty_mark = '🈳' if is_empty else '' | |
| transition_mark = '⚠️' if is_transition else '' | |
| print(f"\n{year}年 ({age}岁) - {event}") | |
| print(f" 大运: {palace} {empty_mark}{transition_mark}") | |
| print(f" 第{daxun_year}年 | {phase} | 强度{strength}/100") | |
| print() | |
| print("-" * 80) | |
| print() | |
| # 6. 关键验证点 | |
| print("【步骤6】关键人生事件验证") | |
| print("-" * 80) | |
| # 获取关键宫位信息 | |
| husband_palace = None | |
| health_palace = None | |
| career_palace = None | |
| for palace in palaces: | |
| if palace.get('name') == '夫妻': | |
| husband_palace = palace | |
| elif palace.get('name') == '疾厄': | |
| health_palace = palace | |
| elif palace.get('name') == '官禄': | |
| career_palace = palace | |
| print("\n✅ 验证点1: 婚姻稳定性(对比妈妈有出轨问题)") | |
| if husband_palace: | |
| major_stars = husband_palace.get('major_stars', []) | |
| minor_stars = husband_palace.get('minor_stars', []) | |
| has_fire_mars = any('火星' in str(s) for s in minor_stars) | |
| print(f" 夫妻宫主星: {[s.get('name', s) if isinstance(s, dict) else s for s in major_stars]}") | |
| print(f" 夫妻宫副星: {[s.get('name', s) if isinstance(s, dict) else s for s in minor_stars][:5]}") | |
| print(f" 是否有火星: {'是 ⚠️' if has_fire_mars else '否 ✅'}") | |
| if has_fire_mars: | |
| print(" → 火星在夫妻宫可能导致婚姻波折、感情不稳定") | |
| else: | |
| print(" → 婚姻宫相对稳定") | |
| print("\n✅ 验证点2: 健康状况(1983年重病,之后小病多)") | |
| if health_palace: | |
| major_stars = health_palace.get('major_stars', []) | |
| is_empty = len(major_stars) == 0 | |
| print(f" 疾厄宫主星: {[s.get('name', s) if isinstance(s, dict) else s for s in major_stars] if major_stars else '空宫'}") | |
| print(f" 是否空宫: {'是 ⚠️' if is_empty else '否'}") | |
| if is_empty: | |
| print(" → 空宫容易受流年化忌冲击,健康不稳定") | |
| print("\n✅ 验证点3: 工作稳定性(仅换过2次,1980年后一直到退休同一单位)") | |
| if career_palace: | |
| major_stars = career_palace.get('major_stars', []) | |
| minor_stars = career_palace.get('minor_stars', []) | |
| # 检查天府、天相等稳定星曜 | |
| has_stable_stars = any( | |
| star_name in str(major_stars) | |
| for star_name in ['天府', '天相', '太阳', '太阴'] | |
| ) | |
| print(f" 官禄宫主星: {[s.get('name', s) if isinstance(s, dict) else s for s in major_stars]}") | |
| print(f" 是否有稳定星曜: {'是 ✅' if has_stable_stars else '否'}") | |
| if has_stable_stars: | |
| print(" → 有利于工作稳定,长期在同一单位发展") | |
| print() | |
| print("-" * 80) | |
| print() | |
| # 7. 保存完整结果 | |
| print("【步骤7】保存完整分析结果...") | |
| with open('baba_chart_full_result.json', 'w', encoding='utf-8') as f: | |
| json.dump(ziwei_chart, f, ensure_ascii=False, indent=2) | |
| print("✅ 完整结果已保存到: baba_chart_full_result.json") | |
| print() | |
| print("=" * 80) | |
| print("✅ 分析完成!") | |
| print("=" * 80) | |
| if __name__ == "__main__": | |
| analyze_baba_chart() | |