Spaces:
Running
Running
File size: 4,861 Bytes
1f45f10 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | #!/usr/bin/env python3
"""
测试1981年10月4日戌时女命盘
Test 1981-10-04 19:00-21:00 female chart
"""
import requests
import json
# API请求
url = "https://sisithefox-astrology-ziwei-api.hf.space/analyze-ziwei-knowledge-enhanced"
payload = {
"birth_date": "1981-10-04",
"birth_time": "20:00", # 戌时中间时间
"gender": "女",
"is_leap_month": False,
"fix_leap": True
}
print("=" * 80)
print("🔮 紫微斗数命盘解读 - 1981-10-04 戌时 女")
print("=" * 80)
try:
response = requests.post(url, json=payload, timeout=30)
if response.status_code != 200:
print(f"❌ API调用失败: {response.status_code}")
print(response.text)
exit(1)
data = response.json()
if data.get('status') != 'success':
print(f"❌ 错误: {data.get('error')}")
exit(1)
result = data['data']
knowledge = result.get('knowledge_interpretation', {})
# 命宫信息
print("\n【命宫信息】")
ming_gong = None
for palace in result.get('palaces', []):
if palace['name'] == '命宫':
ming_gong = palace
break
if ming_gong:
print(f"位置: {ming_gong['position']}")
print(f"强度评分: {ming_gong.get('strength_score', 'N/A')}/100")
print("\n主星:")
for star in ming_gong.get('major_stars', []):
brightness = star.get('brightness', 'N/A')
print(f" • {star['name']} ({brightness})")
print("\n副星:")
minor_stars = ming_gong.get('minor_stars', [])
if minor_stars:
for star in minor_stars:
print(f" • {star['name']}")
else:
print(" 无")
# 星曜组合匹配结果
star_combos = knowledge.get('star_combinations', {})
total_matched = star_combos.get('total_matched', 0)
total_checked = star_combos.get('total_rules_checked', 0)
print("\n" + "=" * 80)
print("【星曜组合匹配结果】")
print("=" * 80)
print(f"匹配规则数: {total_matched}")
print(f"检查规则总数: {total_checked}")
print(f"匹配率: {total_matched / total_checked * 100:.1f}%")
matched_rules = star_combos.get('matched_rules', [])
if matched_rules:
print(f"\n【匹配的组合详情】({len(matched_rules)}个):\n")
for i, rule in enumerate(matched_rules, 1):
print(f"{i}. {rule['rule_name']} (ID: {rule['rule_id']})")
print(f" 宫位: {rule['palace']}")
print(f" 分类: {rule['category']}")
print(f" 评分: {rule['score']}/100")
print(f" 置信度: {rule['confidence']:.1%}")
print(f" 效果等级: {rule['effect_level']}")
interp = rule.get('interpretations', {})
print(f" 核心含义: {interp.get('core_meaning', 'N/A')}")
# 显示匹配的星曜
matched_stars = rule.get('matched_stars', [])
if matched_stars:
print(f" 匹配星曜: {', '.join(matched_stars)}")
print()
# 组合总结
summary = star_combos.get('summary', {})
if summary:
print("=" * 80)
print("【组合总结】")
print("=" * 80)
print(f"最高分: {summary.get('highest_score', 0)}/100")
print(f"平均分: {summary.get('average_score', 0):.1f}/100")
print(f"整体质量: {summary.get('overall_quality', 'N/A')}")
categories = summary.get('categories', {})
if categories:
print(f"\n分类统计:")
for cat, count in sorted(categories.items(), key=lambda x: x[1], reverse=True):
print(f" • {cat}: {count}条")
# Top 3规则
top_3 = summary.get('top_3_rules', [])
if top_3:
print(f"\nTop 3规则:")
for i, rule in enumerate(top_3, 1):
print(f" {i}. {rule['name']} ({rule['score']}分, {rule['category']})")
else:
print("\n⚠️ 未匹配到任何星曜组合")
print(" 这可能表示此命盘的星曜配置不在当前100条规则中")
print("\n" + "=" * 80)
print("✅ 测试完成!")
print("=" * 80)
# 保存详细结果
output_file = "/Volumes/sparksverse/huggingface-spaces/astrology-ziwei-api/test_api_1981_result.json"
with open(output_file, 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=2)
print(f"\n📝 详细结果已保存到: test_api_1981_result.json")
except requests.exceptions.Timeout:
print("❌ API调用超时")
except requests.exceptions.RequestException as e:
print(f"❌ 网络错误: {e}")
except Exception as e:
print(f"❌ 错误: {e}")
import traceback
traceback.print_exc()
|