Spaces:
Running
Running
th commited on
Commit ·
63b5f03
1
Parent(s): b0bd2b7
fix(scoring): check 流月 vs all 4 pillars, not just 流年
Browse filesBREAKING: Monthly fortune scores now correctly reflect relationships
Changes:
- Add ZHI_HAI (六害) relationship table
- Add SAN_HE_GROUPS for three harmony detection
- New _analyze_liuyue_vs_mingju() checks 流月 vs 年月日时 four pillars
- Weighted scoring: 日柱(-20/+15) > 月柱(-15/+12) > 年柱(-12/+10) > 时柱(-10/+8)
- Return detailed pillar_relationships for frontend display
Before: 9月 has 4 negative relations but scored 64 (wrong)
After: Score properly reflects 冲刑害合 with all pillars
🦊 Generated with Sisi
- time_fortune_analyzer.py +162 -13
time_fortune_analyzer.py
CHANGED
|
@@ -47,6 +47,32 @@ class TimeFortuneAnalyzer:
|
|
| 47 |
'巳': '申', '申': '巳', '午': '未', '未': '午'
|
| 48 |
}
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
# 三合局
|
| 51 |
SAN_HE = {
|
| 52 |
'申子辰': 'water', # 水局
|
|
@@ -157,18 +183,10 @@ class TimeFortuneAnalyzer:
|
|
| 157 |
score -= 15
|
| 158 |
reasons.append(f"⚠️ 月份五行为{month_element},助长忌神{jishen}")
|
| 159 |
|
| 160 |
-
# 3. 检查冲合关系
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
if self.ZHI_CHONG.get(month_zhi) == year_zhi:
|
| 165 |
-
score -= 10
|
| 166 |
-
reasons.append(f"⚠️ 月支{month_zhi}与年支{year_zhi}相冲")
|
| 167 |
-
|
| 168 |
-
# 与年支合
|
| 169 |
-
if self.LIU_HE.get(month_zhi) == year_zhi:
|
| 170 |
-
score += 10
|
| 171 |
-
reasons.append(f"✅ 月支{month_zhi}与年支{year_zhi}六合")
|
| 172 |
|
| 173 |
# 4. 五行平衡评估
|
| 174 |
five_elements_score = self._evaluate_five_elements_balance(month_gan, month_zhi)
|
|
@@ -243,7 +261,9 @@ class TimeFortuneAnalyzer:
|
|
| 243 |
'avoid_activities': self._get_avoid_activities(score),
|
| 244 |
# 🔮 专业断语增强
|
| 245 |
'triggered_assertions': liunian_result['triggered_assertions'],
|
| 246 |
-
'matters': liunian_result['matters']
|
|
|
|
|
|
|
| 247 |
}
|
| 248 |
|
| 249 |
def analyze_daily_fortune(self, target_date: date, activities: List[str] = None) -> Dict[str, Any]:
|
|
@@ -454,6 +474,135 @@ class TimeFortuneAnalyzer:
|
|
| 454 |
|
| 455 |
# ==================== 辅助方法 ====================
|
| 456 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 457 |
def _apply_liunian_assertions(
|
| 458 |
self,
|
| 459 |
year_gan: str,
|
|
|
|
| 47 |
'巳': '申', '申': '巳', '午': '未', '未': '午'
|
| 48 |
}
|
| 49 |
|
| 50 |
+
# 六害(穿害)
|
| 51 |
+
ZHI_HAI = {
|
| 52 |
+
'子': '未', '未': '子', # 子未害
|
| 53 |
+
'丑': '午', '午': '丑', # 丑午害
|
| 54 |
+
'寅': '巳', '巳': '寅', # 寅巳害
|
| 55 |
+
'卯': '辰', '辰': '卯', # 卯辰害
|
| 56 |
+
'申': '亥', '亥': '申', # 申亥害
|
| 57 |
+
'酉': '戌', '戌': '酉', # 酉戌害
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
# 三合局地支组合
|
| 61 |
+
SAN_HE_GROUPS = {
|
| 62 |
+
'申': ('子', '辰', 'water'), # 申子辰 水局
|
| 63 |
+
'子': ('申', '辰', 'water'),
|
| 64 |
+
'辰': ('申', '子', 'water'),
|
| 65 |
+
'亥': ('卯', '未', 'wood'), # 亥卯未 木局
|
| 66 |
+
'卯': ('亥', '未', 'wood'),
|
| 67 |
+
'未': ('亥', '卯', 'wood'),
|
| 68 |
+
'寅': ('午', '戌', 'fire'), # 寅午戌 火局
|
| 69 |
+
'午': ('寅', '戌', 'fire'),
|
| 70 |
+
'戌': ('寅', '午', 'fire'),
|
| 71 |
+
'巳': ('酉', '丑', 'metal'), # 巳酉丑 金局
|
| 72 |
+
'酉': ('巳', '丑', 'metal'),
|
| 73 |
+
'丑': ('巳', '酉', 'metal'),
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
# 三合局
|
| 77 |
SAN_HE = {
|
| 78 |
'申子辰': 'water', # 水局
|
|
|
|
| 183 |
score -= 15
|
| 184 |
reasons.append(f"⚠️ 月份五行为{month_element},助长忌神{jishen}")
|
| 185 |
|
| 186 |
+
# 3. 检查流月与命局四柱的冲合刑害关系 🔥 核心修复
|
| 187 |
+
pillar_relationships = self._analyze_liuyue_vs_mingju(month_zhi)
|
| 188 |
+
score += pillar_relationships['score_adjustment']
|
| 189 |
+
reasons.extend(pillar_relationships['reasons'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
|
| 191 |
# 4. 五行平衡评估
|
| 192 |
five_elements_score = self._evaluate_five_elements_balance(month_gan, month_zhi)
|
|
|
|
| 261 |
'avoid_activities': self._get_avoid_activities(score),
|
| 262 |
# 🔮 专业断语增强
|
| 263 |
'triggered_assertions': liunian_result['triggered_assertions'],
|
| 264 |
+
'matters': liunian_result['matters'],
|
| 265 |
+
# 🔥 流月与命局四柱关系详情(新增)
|
| 266 |
+
'pillar_relationships': pillar_relationships['relationships']
|
| 267 |
}
|
| 268 |
|
| 269 |
def analyze_daily_fortune(self, target_date: date, activities: List[str] = None) -> Dict[str, Any]:
|
|
|
|
| 474 |
|
| 475 |
# ==================== 辅助方法 ====================
|
| 476 |
|
| 477 |
+
def _analyze_liuyue_vs_mingju(self, month_zhi: str) -> Dict[str, Any]:
|
| 478 |
+
"""
|
| 479 |
+
🔥 核心方法:分析流月地支与命局四柱的冲合刑害关系
|
| 480 |
+
|
| 481 |
+
权重设计(日柱最重要,代表自己):
|
| 482 |
+
- 与日柱:冲-20, 刑-15, 害-10, 合+15, 三合+12
|
| 483 |
+
- 与月柱:冲-15, 刑-12, 害-8, 合+12, 三合+10
|
| 484 |
+
- 与年柱:冲-12, 刑-10, 害-6, 合+10, 三合+8
|
| 485 |
+
- 与时柱:冲-10, 刑-8, 害-5, 合+8, 三合+6
|
| 486 |
+
|
| 487 |
+
Args:
|
| 488 |
+
month_zhi: 流月地支
|
| 489 |
+
|
| 490 |
+
Returns:
|
| 491 |
+
{
|
| 492 |
+
'score_adjustment': int,
|
| 493 |
+
'reasons': List[str],
|
| 494 |
+
'relationships': List[dict] # 详细关系列表
|
| 495 |
+
}
|
| 496 |
+
"""
|
| 497 |
+
score_adjustment = 0
|
| 498 |
+
reasons = []
|
| 499 |
+
relationships = []
|
| 500 |
+
|
| 501 |
+
# 权重配置(日柱 > 月柱 > 年柱 > 时柱)
|
| 502 |
+
pillar_weights = {
|
| 503 |
+
'day': {'chong': -20, 'xing': -15, 'hai': -10, 'he': 15, 'sanhe': 12, 'name': '日柱', 'name_en': 'Day Pillar'},
|
| 504 |
+
'month': {'chong': -15, 'xing': -12, 'hai': -8, 'he': 12, 'sanhe': 10, 'name': '月柱', 'name_en': 'Month Pillar'},
|
| 505 |
+
'year': {'chong': -12, 'xing': -10, 'hai': -6, 'he': 10, 'sanhe': 8, 'name': '年柱', 'name_en': 'Year Pillar'},
|
| 506 |
+
'hour': {'chong': -10, 'xing': -8, 'hai': -5, 'he': 8, 'sanhe': 6, 'name': '时柱', 'name_en': 'Hour Pillar'},
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
# 遍历命局四柱
|
| 510 |
+
for pillar_key, weights in pillar_weights.items():
|
| 511 |
+
pillar_zhi = self.bazi['bazi_chart'][pillar_key]['zhi']
|
| 512 |
+
pillar_name = weights['name']
|
| 513 |
+
|
| 514 |
+
# 1. 检测六冲
|
| 515 |
+
if self.ZHI_CHONG.get(month_zhi) == pillar_zhi:
|
| 516 |
+
adj = weights['chong']
|
| 517 |
+
score_adjustment += adj
|
| 518 |
+
reasons.append(f"⚠️ 流月{month_zhi}冲{pillar_name}{pillar_zhi}({adj}分)")
|
| 519 |
+
relationships.append({
|
| 520 |
+
'type': '冲', 'type_en': 'Clash',
|
| 521 |
+
'pillar': pillar_key, 'pillar_zhi': pillar_zhi,
|
| 522 |
+
'level': 'negative', 'score': adj
|
| 523 |
+
})
|
| 524 |
+
|
| 525 |
+
# 2. 检测六��
|
| 526 |
+
if self.LIU_HE.get(month_zhi) == pillar_zhi:
|
| 527 |
+
adj = weights['he']
|
| 528 |
+
score_adjustment += adj
|
| 529 |
+
reasons.append(f"✅ 流月{month_zhi}合{pillar_name}{pillar_zhi}(+{adj}分)")
|
| 530 |
+
relationships.append({
|
| 531 |
+
'type': '合', 'type_en': 'Harmony',
|
| 532 |
+
'pillar': pillar_key, 'pillar_zhi': pillar_zhi,
|
| 533 |
+
'level': 'positive', 'score': adj
|
| 534 |
+
})
|
| 535 |
+
|
| 536 |
+
# 3. 检测六害
|
| 537 |
+
if self.ZHI_HAI.get(month_zhi) == pillar_zhi:
|
| 538 |
+
adj = weights['hai']
|
| 539 |
+
score_adjustment += adj
|
| 540 |
+
reasons.append(f"⚠️ 流月{month_zhi}害{pillar_name}{pillar_zhi}({adj}分)")
|
| 541 |
+
relationships.append({
|
| 542 |
+
'type': '害', 'type_en': 'Harm',
|
| 543 |
+
'pillar': pillar_key, 'pillar_zhi': pillar_zhi,
|
| 544 |
+
'level': 'negative', 'score': adj
|
| 545 |
+
})
|
| 546 |
+
|
| 547 |
+
# 4. 检测三合(流月与该柱是否构成三合局的一部分)
|
| 548 |
+
sanhe_result = self._check_sanhe_with_pillar(month_zhi, pillar_zhi)
|
| 549 |
+
if sanhe_result['is_sanhe']:
|
| 550 |
+
adj = weights['sanhe']
|
| 551 |
+
score_adjustment += adj
|
| 552 |
+
reasons.append(f"✅ 流月{month_zhi}与{pillar_name}{pillar_zhi}三合{sanhe_result['element']}局(+{adj}分)")
|
| 553 |
+
relationships.append({
|
| 554 |
+
'type': '三合', 'type_en': 'Triple Harmony',
|
| 555 |
+
'pillar': pillar_key, 'pillar_zhi': pillar_zhi,
|
| 556 |
+
'level': 'positive', 'score': adj,
|
| 557 |
+
'element': sanhe_result['element']
|
| 558 |
+
})
|
| 559 |
+
|
| 560 |
+
# 5. 检测三刑(需要三个地支一起检测)
|
| 561 |
+
all_zhis = [
|
| 562 |
+
self.bazi['bazi_chart']['year']['zhi'],
|
| 563 |
+
self.bazi['bazi_chart']['month']['zhi'],
|
| 564 |
+
self.bazi['bazi_chart']['day']['zhi'],
|
| 565 |
+
self.bazi['bazi_chart']['hour']['zhi'],
|
| 566 |
+
month_zhi # 加入流月
|
| 567 |
+
]
|
| 568 |
+
xing_result = self._check_san_xing(all_zhis)
|
| 569 |
+
if xing_result['has_xing']:
|
| 570 |
+
# 三刑惩罚根据刑的严重程度
|
| 571 |
+
xing_penalty = -12 if xing_result['count'] >= 3 else -8
|
| 572 |
+
score_adjustment += xing_penalty
|
| 573 |
+
reasons.append(f"⚠️ 流月{month_zhi}参与{xing_result['xing_type']}({xing_penalty}分)")
|
| 574 |
+
relationships.append({
|
| 575 |
+
'type': '刑', 'type_en': 'Punishment',
|
| 576 |
+
'pillar': 'multiple', 'pillar_zhi': month_zhi,
|
| 577 |
+
'level': 'negative', 'score': xing_penalty,
|
| 578 |
+
'xing_type': xing_result['xing_type']
|
| 579 |
+
})
|
| 580 |
+
|
| 581 |
+
return {
|
| 582 |
+
'score_adjustment': score_adjustment,
|
| 583 |
+
'reasons': reasons,
|
| 584 |
+
'relationships': relationships
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
def _check_sanhe_with_pillar(self, zhi1: str, zhi2: str) -> Dict[str, Any]:
|
| 588 |
+
"""
|
| 589 |
+
检测两个地支是否构成三合局的一部分
|
| 590 |
+
|
| 591 |
+
三合局:申子辰(水)、亥卯未(木)、寅午戌(火)、巳酉丑(金)
|
| 592 |
+
"""
|
| 593 |
+
sanhe_sets = [
|
| 594 |
+
({'申', '子', '辰'}, '水'),
|
| 595 |
+
({'亥', '卯', '未'}, '木'),
|
| 596 |
+
({'寅', '午', '戌'}, '火'),
|
| 597 |
+
({'巳', '酉', '丑'}, '金'),
|
| 598 |
+
]
|
| 599 |
+
|
| 600 |
+
for sanhe_set, element in sanhe_sets:
|
| 601 |
+
if zhi1 in sanhe_set and zhi2 in sanhe_set and zhi1 != zhi2:
|
| 602 |
+
return {'is_sanhe': True, 'element': element}
|
| 603 |
+
|
| 604 |
+
return {'is_sanhe': False, 'element': ''}
|
| 605 |
+
|
| 606 |
def _apply_liunian_assertions(
|
| 607 |
self,
|
| 608 |
year_gan: str,
|