File size: 5,346 Bytes
e4efb8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class DivinationAdvisor:
    """

    综合建议系统 (吉凶报告生成)

    汇总八字、奇门、六壬、梅花及皇极经世的数据,生成直观的时空决策报告

    """
    
    def __init__(self, bazi_res, qimen_res, liuren_res, meihua_res, planner_res):
        self.bazi = bazi_res
        self.qimen = qimen_res
        self.liuren = liuren_res
        self.meihua = meihua_res
        self.planner = planner_res

    def get_summary(self):
        """生成总体评价"""
        mh_hex = self.meihua.get('hexagram', '')
        hj_advice = self.planner.get('schedule', [{}])[0].get('advice', '平稳')
        return f"当前时空背景:{mh_hex}卦主事。{hj_advice}。综合八字五行与格局,建议以稳健为主。"

    def get_final_verdict(self):
        """五术合一,综合评分与最终意见"""
        score = 50
        details = []
        
        # 1. 梅花提取
        mh_desc = self.meihua.get('description', '')
        if '大吉' in mh_desc: score += 15; details.append('梅花大吉')
        elif '凶' in mh_desc and '大凶' not in mh_desc: score -= 5; details.append('梅花带凶')
        elif '大凶' in mh_desc: score -= 15; details.append('梅花极危')
        elif '吉' in mh_desc: score += 5; details.append('梅花小吉')
        
        # 2. 皇极
        hj_luck = '平'
        schedule = self.planner.get('schedule', [])
        if schedule:
            hj_luck = schedule[0].get('luck', '中')
        if '大吉' in hj_luck: score += 10; details.append('时辰大吉')
        elif '吉' in hj_luck: score += 5; details.append('时辰吉利')
        elif '大凶' in hj_luck: score -= 10; details.append('时辰大凶')
        elif '凶' in hj_luck: score -= 5; details.append('时辰警示')
        
        # 3. 奇门全局格局
        q_patterns = self.qimen.get('global_patterns', [])
        is_q_good = any('吉' in p for p in q_patterns)
        is_q_bad = any('凶' in p for p in q_patterns)
        if is_q_good and not is_q_bad: score += 10; details.append('奇门现吉格')
        elif is_q_bad and not is_q_good: score -= 10; details.append('奇门见凶相')
        
        # 4. 六壬
        lr_bifa = "".join(self.liuren.get('bifa_verdicts', []))
        if '吉' in lr_bifa and '凶' not in lr_bifa: score += 10; details.append('六壬顺遂')
        elif '凶' in lr_bifa and '吉' not in lr_bifa: score -= 10; details.append('六壬不顺')
        
        score = max(0, min(100, score))
        
        if score >= 85:
            final_advice = "大吉 🎉 时机极佳,天地同心。应当毫不犹豫地大胆推进核心决策,哪怕有一定风险也能绝处逢生。"
        elif score >= 70:
            final_advice = "吉 🌟 整体局势顺畅。可以按照原定计划行事,中间遇到的小困难都会有贵人相助,适宜进取。"
        elif score >= 50:
            final_advice = "中平 ⚖️ 吉凶参半或格局平缓。最好以静制动,维持现状,此时不宜做转行、投资等重大改变。"
        elif score >= 30:
            final_advice = "小凶 ⚠️ 阻碍较多,且有可能存在你看不见的隐患。建议推迟手头的重要决定,多防范小人和意外。"
        else:
            final_advice = "大凶 🛑 时空能量剧烈冲突。天时极差,强行突围必有重大损失,建议彻底放弃冒险,蛰伏退守。"

        if not details:
            details.append("各术数吉凶相消,大势平缓")
            
        return {
            "score": score,
            "conclusion": final_advice,
            "summary_factors": "加权依据:" + "、".join(details) + "。"
        }

    def get_categorical_guidance(self):
        """分门别类的决策建议"""
        dm = self.bazi.get('day_master', '甲')
        bazi_hash = sum(ord(c) for c in (dm + str(self.planner.get('day_hex', ''))))
        
        return {
            "career": {
                "score": 60 + (bazi_hash % 35),
                "advice": f"日主为{dm},利于稳妥规划,奇门显示吉门方位可用。不要急进。"
            },
            "wealth": {
                "score": 50 + ((bazi_hash + 13) % 40),
                "advice": "财星隐现随格局波动,需根据八字五行制衡,不宜盲目投机。"
            },
            "relations": {
                "score": 65 + ((bazi_hash + 7) % 30),
                "advice": "顺应天时则地利人和,利于沟通与协作。"
            },
            "health": {
                "score": 70 + ((bazi_hash + 21) % 25),
                "advice": "注意顺应廿四节气作息,当前时辰需养生固本。"
            }
        }

    def generate_report(self):
        """汇总完整报告"""
        dm = self.bazi.get('day_master', '甲')
        return {
            "final": self.get_final_verdict(),
            "summary": self.get_summary(),
            "guidance": self.get_categorical_guidance(),
            "lucky_factors": [f"五色对应{dm}之喜忌", "结合奇门吉门方位", f"时辰吉数"],
            "warning": "命理提示:运势随岁运流转,以上仅供决策参考,不可强求。"
        }