123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450 |
- import Common
- import PowerLogic
- import SiZhuLogic
- from DataCenter import DataCenter
- from LocalModel import BaZi, GaoNeng, SiZhu
- gaoneng_tips = [
- "合多:喜社交,擅处理人际关系,喜与人为善,不喜争斗;",
- "冲多:擅运动,喜欢对抗,喜欢折腾;",
- "天干合:合中带克,夫妻关系",
- "天干冲:甲庚、乙辛金木冲,意外伤;丙壬、丁癸水火冲,情绪不稳",
- "地支合:申子辰合水,寅午戌合火,亥卯未合木,巳酉丑合金",
- "地支冲:丑未、寅申、卯酉金木冲,意外伤;子午、辰戌、巳亥水火冲,情绪不稳",
- "地支穿:穿又叫害,表达一种不对付的关系,常见于关系被挑拨离间、三角恋等,穿是一种互相伤害的概念。",
- "地支刑:刑表示互相折磨互相伤害、较力、掰手腕。子卯刑表示傲慢无礼,不知感恩;申寅巳刑表示不服管教,恃势之刑;丑未戌刑表示家庭不和睦,亲骨无恩,不利亲情。",
- "自刑:自我折磨,有精神障碍,心门不开",
- "地支暗合:午亥暗合,表示财源来路不明,有婚外情;申卯暗合,表示搞手段,暗箱操作,使阴招;寅丑暗合,表示被偷盗、丢东西、破财。",
- "地支破:争吵,多见于婚姻关系中"
- ]
- def check_gaoneng(bazi: BaZi, dc: DataCenter):
- tgs = bazi.sizhu_tiangans()
- dzs = bazi.sizhu_dizhis()
- for tg in tgs:
- __fix_tiangan_gaoneng(tg, tgs, bazi, dc, True)
- # 检查三合三会三刑
- for dz in dzs:
- __fix_dizhi3_gaoneng(dz, dzs, bazi, dc, True)
- for dz in dzs:
- __fix_dizhi2_gaoneng(dz, dzs, bazi, dc, True)
- def update_gaoneng_power(bazi: BaZi, dc: DataCenter):
- # 计算刑的力量
- for gn in bazi.gaonengInfo.xingList:
- __update_power_of_gaoneng_xing(gn, bazi, dc)
- # 半合带来的能量增强
- for gn in bazi.gaonengInfo.banHeList:
- zhu = gn.zhu1
- if gn.arg1 == gn.fangxiang:
- zhu = gn.zhu2
- wx = Common.get_wuxing(gn.fangxiang)
- sz = bazi.getZhuByWeiZhi(zhu)
- gn.banheZengQiangPower = sz.get_canggan_power_by_wuxing(wx)
- dc.shishenZengQiang[gn.banheZengQiangShiShen] += gn.banheZengQiangPower
- # 拱合带来的能量变化
- for gn in bazi.gaonengInfo.gongHeList:
- gn.gongheZengQiangPower = dc.get_power_step(gn.gongheZengQiangWuXing)
- dc.shishenZengQiang[gn.gongheZengQiangShiShen] += gn.gongheZengQiangPower
- # 三会带来的能量变化(这里其实要看有没有被破坏才决定是否增强)
- for gn in bazi.gaonengInfo.sanHuiList:
- zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
- zhu2 = bazi.getZhuByWeiZhi(gn.zhu2)
- zhu3 = bazi.getZhuByWeiZhi(gn.zhu3)
- p1 = zhu1.get_canggan_power_by_wuxing(gn.hehua)
- p2 = zhu2.get_canggan_power_by_wuxing(gn.hehua)
- p3 = zhu3.get_canggan_power_by_wuxing(gn.hehua)
- power = 0
- if zhu1.text != gn.fangxiang:
- power += p1
- if zhu2.text != gn.fangxiang:
- power += p2
- if zhu3.text != gn.fangxiang:
- power += p3
- gn.sanhuiZengQiangPower = power
- dc.shishenZengQiang[gn.sanhuiZengQiangShiShen] += gn.sanhuiZengQiangPower
- # 自刑带来的能量变化
- for gn in bazi.gaonengInfo.ziXingList:
- if gn.zixingZengQiangWuXing is not None:
- zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
- power = zhu1.get_canggan_power_by_wuxing(gn.zixingZengQiangWuXing)
- gn.zixingZengQiangPower = power
- # 力量变动后,重新计算counter
- for ss in Common.shishen_ary:
- zq = dc.shishenZengQiang[ss]
- if zq > 0:
- found = False
- for wsp in bazi.powerInfo.wangShuaiPowers:
- if wsp.shishen1 == ss:
- wsp.shishen1ZengQiang = zq
- found = True
- elif wsp.shishen2 == ss:
- wsp.shishen2ZengQiang = zq
- found = True
- if found:
- break
- PowerLogic.calc_percentages(bazi.powerInfo.wangShuaiPowers, True, bazi, dc)
- SiZhuLogic.update_powers(bazi, dc)
- def __fix_tiangan_gaoneng(zhu: SiZhu, tiangans: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
- for tg in tiangans:
- if zhu.weiZhi == tg.weiZhi:
- continue
- data = Common.find_gaoneng_by_texts(zhu.text, tg.text)
- for temp in data:
- gn = __build_gaoneng_object_from_data(temp, zhu, tg, None, bazi, dc, save)
- gn1 = gn.copySelf()
- __calc_fangxiang(gn1, zhu.weiZhi)
- zhu.gaonengs.append(gn1)
- if save:
- dc.add_gaoneng_in_weizhi(zhu.weiZhi, gn1.text)
- dc.add_gaoneng_in_weizhi(tg.weiZhi, gn1.text)
- def __fix_dizhi3_gaoneng(zhu: SiZhu, dizhis: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
- gnMap = {}
- for dz2 in dizhis:
- for dz3 in dizhis:
- if zhu.weiZhi == dz2.weiZhi or zhu.weiZhi == dz3.weiZhi or dz2.weiZhi == dz3.weiZhi:
- continue
- data = Common.find_gaoneng_by_texts(zhu.text, dz2.text, dz3.text)
- for temp in data:
- key = __calc_key_of_gaoneng_data(zhu.weiZhi, dz2.weiZhi, dz3.weiZhi, temp["name"])
- if not gnMap.keys().__contains__(key):
- gnMap[key] = __build_gaoneng_object_from_data(temp, zhu, dz2, dz3, bazi, dc, save)
- if save:
- dc.add_gaoneng_in_weizhi(zhu.weiZhi, gnMap[key].text)
- dc.add_gaoneng_in_weizhi(dz2.weiZhi, gnMap[key].text)
- dc.add_gaoneng_in_weizhi(dz3.weiZhi, gnMap[key].text)
- for temp in gnMap.values():
- gn1 = temp.copySelf()
- __calc_fangxiang(gn1, zhu.weiZhi)
- zhu.gaonengs.append(gn1)
- def __fix_dizhi2_gaoneng(zhu: SiZhu, dizhis: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
- for dz in dizhis:
- if zhu.weiZhi == dz.weiZhi:
- continue
- data = Common.find_gaoneng_by_texts(zhu.text, dz.text)
- for temp in data:
- gn = __build_gaoneng_object_from_data(temp, zhu, dz, None, bazi, dc, save)
- gn1 = gn.copySelf()
- __calc_fangxiang(gn1, zhu.weiZhi)
- zhu.gaonengs.append(gn1)
- if save:
- dc.add_gaoneng_in_weizhi(zhu.weiZhi, gn1.text)
- dc.add_gaoneng_in_weizhi(dz.weiZhi, gn1.text)
- def __build_gaoneng_object_from_data(data: {}, zhu1: SiZhu, zhu2: SiZhu, zhu3: SiZhu, bazi: BaZi, dc: DataCenter,
- save: bool):
- gn = GaoNeng()
- gn.arg1 = zhu1.text
- gn.arg2 = zhu2.text
- gn.arg3 = zhu3.text if zhu3 is not None else None
- gn.guanxi = data["guanxi"]
- gn.text = data["name"]
- gn.father = data["father"]
- gn.leibie = data["leibie"]
- gn.wuxing1 = zhu1.wuXing
- gn.wuxing2 = zhu2.wuXing
- gn.wuxing3 = zhu3.wuXing if zhu3 is not None else None
- gn.hehua = data["hehua"]
- gn.shishen1 = zhu1.shiShen
- gn.shishen2 = zhu2.shiShen
- gn.shishen3 = zhu3.shiShen if zhu3 is not None else None
- gn.power1 = dc.get_shishen_power(gn.shishen1)
- gn.power2 = dc.get_shishen_power(gn.shishen2)
- gn.power3 = dc.get_shishen_power(gn.shishen3)
- gn.zhu1 = zhu1.weiZhi
- gn.zhu2 = zhu2.weiZhi
- gn.zhu3 = zhu3.weiZhi if zhu3 is not None else None
- gn.tip = data["tip"]
- gn.fangxiang = data["fangxiang"]
- gn.key = __calc_key_of_gaoneng_data(gn.zhu1, gn.zhu2, gn.zhu3, gn.text)
- if gn.guanxi == "合":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
- bazi.gaonengInfo.heList.append(gn)
- elif gn.guanxi == "冲":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
- bazi.gaonengInfo.chongList.append(gn)
- elif gn.guanxi == "破":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
- bazi.gaonengInfo.poList.append(gn)
- elif gn.guanxi == "穿":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
- bazi.gaonengInfo.chuanList.append(gn)
- elif gn.guanxi == "半合":
- gn.banheZengQiang = gn.fangxiang
- gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
- gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
- bazi.gaonengInfo.banHeList.append(gn)
- elif gn.guanxi == "拱合":
- gn.gongheZengQiang = gn.fangxiang
- gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
- gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
- bazi.gaonengInfo.gongHeList.append(gn)
- elif gn.guanxi == "暗合":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
- bazi.gaonengInfo.anHeList.append(gn)
- elif gn.guanxi == "三会":
- gn.sanhuiZengQiang = gn.fangxiang
- gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
- gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
- bazi.gaonengInfo.sanHuiList.append(gn)
- elif gn.guanxi == "自刑":
- gn.zixingZengQiang = gn.fangxiang
- gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
- gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
- bazi.gaonengInfo.ziXingList.append(gn)
- elif gn.guanxi == "刑":
- if save:
- __fill_data_for_gaoneng_xing(gn, bazi)
- if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
- bazi.gaonengInfo.xingList.append(gn)
- return gn
- def __build_gaoneng_object_from_data_as_text(data: {}, text: str, zhu2: SiZhu, zhu3: SiZhu, bazi: BaZi, dc: DataCenter,
- save: bool):
- gn = GaoNeng()
- gn.arg1 = text
- gn.arg2 = zhu2.text
- gn.arg3 = zhu3.text if zhu3 is not None else None
- gn.guanxi = data["guanxi"]
- gn.text = data["name"]
- gn.father = data["father"]
- gn.leibie = data["leibie"]
- gn.wuxing1 = Common.get_wuxing(text)
- gn.wuxing2 = zhu2.wuXing
- gn.wuxing3 = zhu3.wuXing if zhu3 is not None else None
- gn.hehua = data["hehua"]
- gn.shishen1 = Common.get_shishen(text, bazi.riGan.text)
- gn.shishen2 = zhu2.shiShen
- gn.shishen3 = zhu3.shiShen if zhu3 is not None else None
- gn.power1 = dc.get_shishen_power(gn.shishen1)
- gn.power2 = dc.get_shishen_power(gn.shishen2)
- gn.power3 = dc.get_shishen_power(gn.shishen3)
- gn.zhu1 = -1
- gn.zhu2 = zhu2.weiZhi
- gn.zhu3 = zhu3.weiZhi if zhu3 is not None else None
- gn.tip = data["tip"]
- gn.fangxiang = data["fangxiang"]
- gn.key = __calc_key_of_gaoneng_data(gn.zhu1, gn.zhu2, gn.zhu3, gn.text)
- if gn.guanxi == "合":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
- bazi.gaonengInfo.heList.append(gn)
- elif gn.guanxi == "冲":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
- bazi.gaonengInfo.chongList.append(gn)
- elif gn.guanxi == "破":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
- bazi.gaonengInfo.poList.append(gn)
- elif gn.guanxi == "穿":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
- bazi.gaonengInfo.chuanList.append(gn)
- elif gn.guanxi == "半合":
- gn.banheZengQiang = gn.fangxiang
- gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
- gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
- bazi.gaonengInfo.banHeList.append(gn)
- elif gn.guanxi == "拱合":
- gn.gongheZengQiang = gn.fangxiang
- gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
- gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
- bazi.gaonengInfo.gongHeList.append(gn)
- elif gn.guanxi == "暗合":
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
- bazi.gaonengInfo.anHeList.append(gn)
- elif gn.guanxi == "三会":
- gn.sanhuiZengQiang = gn.fangxiang
- gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
- gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
- bazi.gaonengInfo.sanHuiList.append(gn)
- elif gn.guanxi == "自刑":
- gn.zixingZengQiang = gn.fangxiang
- gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
- gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
- if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
- bazi.gaonengInfo.ziXingList.append(gn)
- elif gn.guanxi == "刑":
- if save:
- __fill_data_for_gaoneng_xing(gn, bazi)
- if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
- bazi.gaonengInfo.xingList.append(gn)
- return gn
- def __calc_key_of_gaoneng_data(zhu1: int, zhu2: int, zhu3: int, text: str):
- lst = [zhu1, zhu2]
- if zhu3 is not None:
- lst.append(zhu3)
- lst.sort()
- key = text
- for v in lst:
- key += str(v)
- return key
- def __has_father(gns: [GaoNeng], gn: GaoNeng):
- result = False
- if gn.father is None:
- return result
- for temp in gns:
- if temp.text == gn.father:
- result = True
- break
- return result
- def __fill_data_for_gaoneng_xing(gn: GaoNeng, bazi: BaZi):
- found = False
- if gn.text == "寅巳刑":
- gn.xingchu1 = "丙"
- gn.xingchu2 = "戊"
- gn.xingchong = "甲庚冲"
- gn.xingchongArg1 = "甲"
- gn.xingchongArg2 = "庚"
- found = True
- elif gn.text == "巳申刑":
- gn.xingchu1 = "庚"
- gn.xingchu2 = "戊"
- gn.xingchong = "丙壬冲"
- gn.xingchongArg1 = "丙"
- gn.xingchongArg2 = "壬"
- found = True
- elif gn.text == "戌未刑":
- gn.xingchu1 = "丁"
- gn.xingchu2 = None
- gn.xingchong = "乙辛冲"
- gn.xingchongArg1 = "乙"
- gn.xingchongArg2 = "辛"
- found = True
- elif gn.text == "丑戌刑":
- gn.xingchu1 = "辛"
- gn.xingchu2 = None
- gn.xingchong = "丁癸冲"
- gn.xingchongArg1 = "丁"
- gn.xingchongArg2 = "癸"
- found = True
- elif gn.text == "子卯刑":
- gn.xingchu1 = None
- gn.xingchu2 = None
- gn.xingchong = None
- gn.xingchongArg1 = None
- gn.xingchongArg2 = None
- found = True
- if found:
- gn.xingchu1WuXing = Common.get_wuxing(gn.xingchu1)
- gn.xingchu2WuXing = Common.get_wuxing(gn.xingchu2)
- gn.xingchu1ShiShen = Common.get_shishen(gn.xingchu1, bazi.riGan.text)
- gn.xingchu2ShiShen = Common.get_shishen(gn.xingchu2, bazi.riGan.text)
- def __update_power_of_gaoneng_xing(gn: GaoNeng, bazi: BaZi, dc: DataCenter):
- zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
- zhu2 = bazi.getZhuByWeiZhi(gn.zhu2)
- gn.xingchu1Power = zhu1.get_canggan_power_by_wuxing(gn.xingchu1WuXing) + zhu2.get_canggan_power_by_wuxing(
- gn.xingchu1WuXing)
- gn.xingchu2Power = zhu1.get_canggan_power_by_wuxing(gn.xingchu2WuXing) + zhu2.get_canggan_power_by_wuxing(
- gn.xingchu2WuXing)
- gn.xingchongArg1ShiShen = Common.get_shishen(gn.xingchongArg1, bazi.riGan.text)
- gn.xingchongArg2ShiShen = Common.get_shishen(gn.xingchongArg2, bazi.riGan.text)
- gn.xingchongArg1Power = dc.get_shishen_power(gn.xingchongArg1ShiShen)
- gn.xingchongArg2Power = dc.get_shishen_power(gn.xingchongArg2ShiShen)
- def __has_key_in_gaoneng_list(gn: GaoNeng, list: [GaoNeng]):
- result = False
- for item in list:
- if item.key == gn.key:
- result = True
- break
- return result
- def __calc_fangxiang(gn: GaoNeng, selfZhu: int):
- if gn.guanxi in ["合", "暗合", "三合", "半合", "三会"]:
- fromZhu = selfZhu
- toZhu = gn.zhu1
- if gn.fangxiang == gn.arg2:
- toZhu = gn.zhu2
- elif gn.fangxiang == gn.arg3:
- toZhu = gn.zhu3
- if fromZhu == toZhu:
- gn.fangxiangTip = ""
- elif fromZhu < toZhu:
- gn.fangxiangTip = "→"
- elif fromZhu > toZhu:
- gn.fangxiangTip = "←"
- elif gn.guanxi in ["冲", "穿"]:
- if selfZhu == gn.zhu1:
- if gn.power1 < gn.power2:
- gn.fangxiangTip = "↓"
- elif gn.power1 > gn.power2:
- gn.fangxiangTip = "↑"
- else:
- gn.fangxiangTip = "="
- else:
- if gn.power1 < gn.power2:
- gn.fangxiangTip = "↑"
- elif gn.power1 > gn.power2:
- gn.fangxiangTip = "↓"
- else:
- gn.fangxiangTip = "="
- elif gn.guanxi == "拱合":
- gn.fangxiangTip = "(" + gn.fangxiang + ")"
- def fix_gaoneng_by_text(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, dc: DataCenter):
- result: [GaoNeng] = []
- tg = Common.is_tiangan(text)
- if tg is True:
- __fix_gaoneng_for_two(text, zhus, bazi, weizhi, result, dc)
- else:
- __fix_gaoneng_for_three(text, zhus, bazi, weizhi, result, dc)
- __fix_gaoneng_for_two(text, zhus, bazi, weizhi, result, dc)
- return result
- def __fix_gaoneng_for_two(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, list: [GaoNeng], dc: DataCenter):
- for sz in zhus:
- data = Common.find_gaoneng_by_texts(text, sz.text)
- for dt in data:
- gn = __build_gaoneng_object_from_data_as_text(dt, text, sz, None, bazi, dc, False)
- if __has_key_in_gaoneng_list(gn, list) is False:
- list.append(gn)
- def __fix_gaoneng_for_three(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, list: [GaoNeng], dc: DataCenter):
- for sz2 in zhus:
- for sz3 in zhus:
- if sz2.weiZhi == sz3.weiZhi:
- continue
- data = Common.find_gaoneng_by_texts(text, sz2.text, sz3.text)
- for dt in data:
- gn = __build_gaoneng_object_from_data_as_text(dt, text, sz2, sz3, bazi, dc, False)
- if __has_key_in_gaoneng_list(gn, list) is False:
- list.append(gn)
|