123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- import Common
- from DataCenter import DataCenter
- from LocalModel import SiZhu, BaZi, GaoNeng
- def fill_sizhu(bazi: BaZi, dc: DataCenter):
- for gan in bazi.sizhu_tiangans():
- __fill_sizhu_of_tiangan(gan)
- for zhi in bazi.sizhu_dizhis():
- __fill_sizhu_of_dizhi(zhi)
- for tg in bazi.sizhu_tiangans():
- if Common.has_genqi(tg.wuXing, zhi.wuXing):
- dc.genqi[tg.weiZhi][0] += 1
- else:
- dc.genqi[tg.weiZhi][1] += 1
- __fill_sizhu_of_zhangsheng(bazi.nianZhi, bazi.nianGan.text, bazi.riGan.text)
- __fill_sizhu_of_zhangsheng(bazi.yueZhi, bazi.yueGan.text, bazi.riGan.text)
- __fill_sizhu_of_zhangsheng(bazi.riZhi, bazi.riGan.text, bazi.riGan.text)
- __fill_sizhu_of_zhangsheng(bazi.shiZhi, bazi.shiGan.text, bazi.riGan.text)
- for zhi in bazi.sizhu_dizhis():
- __fill_cang_gan(zhi, bazi.riGan)
- for sz in bazi.sizhu_all():
- __fill_shishen(bazi.riGan, sz)
- dc.shishenMap[sz.weiZhi] = sz.shiShen
- dc.shiShenTexts.append(sz.shiShen)
- __calc_shishen_guanxi(bazi)
- __calc_shishen_of_tiangan(bazi, dc)
- __calc_shishen_of_dizhi(bazi, dc)
- def check_muku(bazi: BaZi, dc: DataCenter):
- for zhi in bazi.sizhu_dizhis():
- __check_muku(zhi, bazi, dc)
- def update_powers(bazi: BaZi, dc: DataCenter):
- for sz in bazi.sizhu_all():
- sz.power = dc.get_shishen_power(sz.shiShen)
- per = dc.get_canggan_power_percentage(sz.weiZhi)
- sz.update_canggan_powers(per)
- sz.selfPower = sz.get_canggan_power_by_wuxing(sz.wuXing)
- def next_tiangan(tiangan: str):
- return __get_next(Common.tiangan_ary, tiangan)
- def next_dizhi(dizhi: str):
- return __get_next(Common.dizhi_ary, dizhi)
- def get_dizhi_by_hour(hour: int):
- index = 0
- if hour == 23 or hour == 0:
- index = 0
- elif hour == 1 or hour == 2:
- index = 1
- elif hour == 3 or hour == 4:
- index = 2
- elif hour == 5 or hour == 6:
- index = 3
- elif hour == 7 or hour == 8:
- index = 4
- elif hour == 9 or hour == 10:
- index = 5
- elif hour == 11 or hour == 12:
- index = 6
- elif hour == 13 or hour == 14:
- index = 7
- elif hour == 15 or hour == 16:
- index = 8
- elif hour == 17 or hour == 18:
- index = 9
- elif hour == 19 or hour == 20:
- index = 10
- elif hour == 21 or hour == 22:
- index = 11
- return Common.dizhi_ary[index]
- def get_tiangan_start_of_hour(day_tiangan: str):
- start_tiangan = ""
- if day_tiangan == "甲" or day_tiangan == "己":
- start_tiangan = "甲"
- elif day_tiangan == "乙" or day_tiangan == "庚":
- start_tiangan = "丙"
- elif day_tiangan == "丙" or day_tiangan == "辛":
- start_tiangan = "戊"
- elif day_tiangan == "丁" or day_tiangan == "壬":
- start_tiangan = "庚"
- elif day_tiangan == "戊" or day_tiangan == "癸":
- start_tiangan = "壬"
- return start_tiangan
- def get_tiangan_by_hour(start_tiangan: str, hour: int):
- dist = 0
- if hour == 23 or hour == 0:
- dist = 0
- elif hour == 1 or hour == 2:
- dist = 1
- elif hour == 3 or hour == 4:
- dist = 2
- elif hour == 5 or hour == 6:
- dist = 3
- elif hour == 7 or hour == 8:
- dist = 4
- elif hour == 9 or hour == 10:
- dist = 5
- elif hour == 11 or hour == 12:
- dist = 6
- elif hour == 13 or hour == 14:
- dist = 7
- elif hour == 15 or hour == 16:
- dist = 8
- elif hour == 17 or hour == 18:
- dist = 9
- elif hour == 19 or hour == 20:
- dist = 10
- elif hour == 21 or hour == 22:
- dist = 11
- tiangan = start_tiangan
- while dist > 0:
- tiangan = next_tiangan(tiangan)
- dist -= 1
- return tiangan
- def __fill_sizhu_of_tiangan(sizhu: SiZhu):
- sizhu.wuXing = Common.get_wuxing(sizhu.text)
- sizhu.yinYang = Common.get_yinyang(sizhu.text)
- def __fill_sizhu_of_dizhi(sizhu: SiZhu):
- sizhu.wuXing = Common.get_wuxing(sizhu.text)
- sizhu.yinYang = Common.get_yinyang(sizhu.text)
- def __fill_sizhu_of_zhangsheng(sizhu: SiZhu, tiangan: str, riyuan: str):
- sizhu.tongzhuZhangSheng = Common.get_zhangsheng(tiangan, sizhu.text)
- sizhu.riyuanZhangSheng = Common.get_zhangsheng(riyuan, sizhu.text)
- def __fill_cang_gan(sizhu: SiZhu, rigan: SiZhu):
- cgs = Common.get_canggans(sizhu.text)
- sizhu.cangGan1 = cgs[0]
- sizhu.cangGan2 = cgs[1]
- sizhu.cangGan3 = cgs[2]
- sizhu.gan1WuXing = Common.get_wuxing(sizhu.cangGan1)
- sizhu.gan2WuXing = Common.get_wuxing(sizhu.cangGan2)
- sizhu.gan3WuXing = Common.get_wuxing(sizhu.cangGan3)
- sizhu.gan1ShiShen = Common.get_shishen(sizhu.cangGan1, rigan.text)
- sizhu.gan2ShiShen = Common.get_shishen(sizhu.cangGan2, rigan.text)
- sizhu.gan3ShiShen = Common.get_shishen(sizhu.cangGan3, rigan.text)
- def __check_muku(dizhi: SiZhu, bazi: BaZi, dc: DataCenter, extraGaoNengs: [GaoNeng] = None):
- muku = dizhi.muku
- if muku is None:
- return
- obj = Common.get_muku_info(dizhi.text)
- muku.state = ""
- muku.lock = obj["lock"]
- muku.chong = obj["chong"]
- muku.gonghe = obj["gonghe"]
- muku.zixing = obj["zixing"]
- muku.sanhui = obj["sanhui"]
- muku.anhe = obj["anhe"]
- muku.isLock = False
- muku.hasChong = False
- muku.hasGonghe = False
- muku.hasZiXing = False
- muku.hasSanHui = False
- muku.hasAnHe = False
- muku.isOpen = False
- localLock = dc.has_gaoneng(muku.lock)
- extraLock = __has_gaoneng_in_extra_list(extraGaoNengs, muku.lock)
- localChong = dc.has_gaoneng(muku.chong)
- extraChong = __has_gaoneng_in_extra_list(extraGaoNengs, muku.chong)
- localGongHe = dc.has_gaoneng(muku.gonghe)
- extraGongHe = __has_gaoneng_in_extra_list(extraGaoNengs, muku.gonghe)
- localAnHe = dc.has_gaoneng(muku.anhe)
- extraAnHe = __has_gaoneng_in_extra_list(extraGaoNengs, muku.anhe)
- localZiXing = dc.has_gaoneng(muku.zixing)
- extraZiXing = __has_gaoneng_in_extra_list(extraGaoNengs, muku.zixing)
- localSanHui = dc.has_gaoneng(muku.sanhui)
- extraSanHui = __has_gaoneng_in_extra_list(extraGaoNengs, muku.sanhui)
- if localLock or extraLock:
- muku.isLock = True
- muku.state = muku.lock + "锁库"
- # 拱合开库
- if localGongHe or extraGongHe:
- muku.hasGonghe = True
- muku.isOpen = True
- muku.state += "," + muku.gonghe + "开库"
- # 自刑开库
- elif localZiXing or extraZiXing:
- muku.hasZiXing = True
- muku.isOpen = True
- muku.state += "," + muku.zixing + "开库"
- # 三会开库
- elif localSanHui or extraSanHui:
- muku.hasSanHui = True
- muku.isOpen = True
- muku.state += "," + muku.sanhui + "开库"
- # 暗合开库
- elif localAnHe or extraAnHe:
- if localChong or extraChong:
- muku.hasAnhe = True
- muku.isOpen = True
- muku.state += "," + muku.anhe + "," + muku.chong + "开库"
- else:
- if localChong or extraChong:
- muku.hasChong = True
- muku.isOpen = True
- muku.state = "未锁库," + muku.chong + "开库"
- def __has_gaoneng_in_extra_list(gns: [GaoNeng], text: str):
- result = False
- if gns is None or text is None:
- return result
- for gn in gns:
- if gn.text == text:
- result = True
- break
- return result
- def __fill_shishen(rigan: SiZhu, other: SiZhu):
- other.shiShen = Common.get_shishen(other.text, rigan.text)
- def __calc_shishen_guanxi(bazi: BaZi):
- obj = Common.get_wuxing_shishen_guanxi(bazi.riGan.wuXing)
- for wuxing in Common.wuxing_ary:
- bazi.guanxiInfo.shishen[wuxing] = obj[wuxing]
- def __calc_shishen_of_tiangan(bazi: BaZi, dc: DataCenter):
- for tg in Common.tiangan_ary:
- ss = Common.get_shishen(tg, bazi.riGan.text)
- bazi.guanxiInfo.tiangan[tg] = ss
- dc.shishenOfTianGan[ss] = tg
- def __calc_shishen_of_dizhi(bazi: BaZi, dc: DataCenter):
- for dz in Common.dizhi_ary:
- ss = Common.get_shishen(dz, bazi.riGan.text)
- bazi.guanxiInfo.dizhi[dz] = ss
- dc.shishenOfDiZhi[ss].append(dz)
- def __get_next(ary: [], dt: str):
- index = ary.index(dt)
- i = index + 1
- if i > len(ary) - 1:
- i = 0
- return ary[i]
|