123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302 |
- import Common
- from LocalModel import BaZi, SiZhu
- class DataCenter():
- bazi: BaZi
- tianganTexts: [str]
- dizhiTexts: [str]
- cangGanPowerPercentage: {} # key:5-8, value: [v1,v2,v3]
- cangganWuXing: {} # key: 5-8, value:[火,None,None]
- cangganShiShen: {} # key:5-8,value:[食,None,None]
- wuxingCounter: {} # key:五行, value: int
- wuxingCounterIncludeCangGan: {} # key:五行, value: int
- wuxingWangShuai: {} # key五行,value:旺相休囚死
- shishenCounter: {} # key:十神, value: int
- shishenCounterIncludeCangGan: {} # key:十神, value: int
- gaonengTexts: [str]
- gaonengInWeiZhi: {} # key 位置, value:text
- mukuState: {} # key 5-8 ,value:None | True | False
- shishenPower: {} # key 十神, value:int
- powerStep: {} # key:五行,value:power step,对应旺相休囚死
- genqi: {} # key 位置, value: [真,假]
- lushenAmount: int
- banluAmount: int
- shishenMap: {} # key 位置,value:十神
- shiShenTexts: []
- shishenZengQiang: {} # key 十神,value:int
- xiongjiTexts: []
- shishenOfTianGan: {} # key 十神 value:天干
- shishenOfDiZhi: {} # key 十神 value:地支
- def __init__(self, bazi: BaZi):
- # 这个时候只知道text,muku(不带状态)
- self.bazi = bazi
- self.tianganTexts = []
- self.dizhiTexts = []
- self.mukuState = {5: None, 6: None, 7: None, 8: None}
- self.cangganWuXing = {5: None, 6: None, 7: None, 8: None}
- self.cangganShiShen = {5: None, 6: None, 7: None, 8: None}
- self.cangGanPowerPercentage = {5: [0, 0, 0], 6: [0, 0, 0], 7: [0, 0, 0], 8: [0, 0, 0]}
- self.wuxingCounter = {}
- self.wuxingCounterIncludeCangGan = {}
- self.shishenCounter = {}
- self.shishenCounterIncludeCangGan = {}
- self.shishenPower = {}
- self.gaonengInWeiZhi = {}
- self.powerStep = {}
- self.genqi = {1: [0, 0], 2: [0, 0], 3: [0, 0], 4: [0, 0]}
- self.lushenAmount = 0
- self.banluAmount = 0
- self.shishenMap = {}
- self.shiShenTexts = []
- self.xiongjiTexts = []
- self.shishenOfTianGan = {}
- self.shishenOfDiZhi = {}
- self.wuxingWangShuai = {}
- self.shishenZengQiang = {}
- for dizhi in bazi.sizhu_dizhis():
- if dizhi.isLuShen:
- self.lushenAmount += 1
- if dizhi.isBanLu:
- self.banluAmount += 1
- for i in range(1, 9):
- self.gaonengInWeiZhi[i] = []
- self.shishenMap[i] = ""
- for wx in Common.wuxing_ary:
- self.powerStep[wx] = 0
- self.wuxingWangShuai[wx] = ""
- for ss in Common.shishen_ary:
- self.shishenPower[ss] = 0
- self.shishenOfTianGan[ss] = ""
- self.shishenOfDiZhi[ss] = []
- self.shishenZengQiang[ss] = 0
- for sz in bazi.sizhu_all():
- if sz.isTianGan:
- self.tianganTexts.append(sz.text)
- else:
- self.dizhiTexts.append(sz.text)
- def list_gaoneng(self):
- self.gaonengTexts = []
- tgs = self.bazi.sizhu_tiangans()
- for tg1 in tgs:
- for tg2 in tgs:
- if tg1.weiZhi == tg2.weiZhi:
- continue
- gns = Common.find_gaoneng_by_texts(tg1.text, tg2.text)
- for gn in gns:
- if not self.gaonengTexts.__contains__(gn["name"]):
- self.gaonengTexts.append(gn["name"])
- dzs = self.bazi.sizhu_dizhis()
- for dz1 in dzs:
- for dz2 in dzs:
- for dz3 in dzs:
- if dz1.weiZhi == dz2.weiZhi or dz1.weiZhi == dz3.weiZhi or dz2.weiZhi == dz3.weiZhi:
- continue
- gns = Common.find_gaoneng_by_texts(dz1.text, dz2.text, dz3.text)
- for gn in gns:
- if not self.gaonengTexts.__contains__(gn["name"]):
- self.gaonengTexts.append(gn["name"])
- if dz1.weiZhi == dz2.weiZhi:
- continue
- gns2 = Common.find_gaoneng_by_texts(dz1.text, dz2.text)
- for gn in gns2:
- if not self.gaonengTexts.__contains__(gn["name"]):
- self.gaonengTexts.append(gn["name"])
- def has_gaoneng(self, text: str):
- if text is None:
- return False
- return self.gaonengTexts.__contains__(text)
- def update_muku_state(self):
- for sz in self.bazi.sizhu_dizhis():
- if sz.muku is not None:
- self.mukuState[sz.weiZhi] = False
- info = Common.get_muku_info(sz.text)
- if info is not None:
- # 是否锁库
- if not self.has_gaoneng(info["lock"]):
- # 没锁库,有冲则开库
- if self.has_gaoneng(info["chong"]):
- self.mukuState[sz.weiZhi] = True
- else:
- # 锁库,自刑则开库、三会开库、拱合开库、暗合+冲开库
- if self.has_gaoneng(info["zixing"]):
- self.mukuState[sz.weiZhi] = True
- elif self.has_gaoneng(info["sanhui"]):
- self.mukuState[sz.weiZhi] = True
- elif self.has_gaoneng(info["gonghe"]):
- self.mukuState[sz.weiZhi] = True
- else:
- if self.has_gaoneng(info["anhe"]) and self.has_gaoneng(info["chong"]):
- self.mukuState[sz.weiZhi] = True
- def update_counter(self):
- # 此时四柱填充完成,知道wuxing shishen canggan
- for wx in Common.wuxing_ary:
- self.wuxingCounter[wx] = 0
- self.wuxingCounterIncludeCangGan[wx] = 0
- for ss in Common.shishen_ary:
- self.shishenCounter[ss] = 0
- self.shishenCounterIncludeCangGan[ss] = 0
- for sz in self.bazi.sizhu_all():
- self.wuxingCounter[sz.wuXing] += 1
- self.shishenCounter[sz.shiShen] += 1
- # 这里顺便计算下地支藏干的power分布
- if not sz.isTianGan:
- self.cangganWuXing[sz.weiZhi] = [sz.gan1WuXing, sz.gan2WuXing, sz.gan3WuXing]
- self.cangganShiShen[sz.weiZhi] = [sz.gan1ShiShen, sz.gan2ShiShen, sz.gan3ShiShen]
- per = [0, 0, 0]
- ct = 0
- if sz.cangGan1 is not None:
- ct += 1
- if sz.cangGan2 is not None:
- ct += 1
- if sz.cangGan3 is not None:
- ct += 1
- if ct == 1:
- per = [1, 0, 0]
- elif ct == 2:
- per = [0.7, 0.3, 0]
- elif ct == 3:
- if sz.muku is None:
- per = [0.6, 0.3, 0.1]
- else:
- # 注意,此时墓库的状态还未更新到sz.muku,会导致获得sz.muku.isOpen等属性获取失败
- # 因此这里要使用预存的mukuState进行判定
- state = self.mukuState[sz.weiZhi]
- if state is not None:
- if state is True:
- per = [0.1, 0.6, 0.3]
- else:
- per = [0.6, 0.3, 0.1]
- self.cangGanPowerPercentage[sz.weiZhi] = per
- else:
- self.wuxingCounterIncludeCangGan[sz.wuXing] += 1
- self.shishenCounterIncludeCangGan[sz.shiShen] += 1
- # 根据上面计算的藏干power分布,重新计算地支藏干五行
- for sz in self.bazi.sizhu_dizhis():
- per = self.cangGanPowerPercentage[sz.weiZhi]
- ganWuXing = self.cangganWuXing[sz.weiZhi]
- ganShiShen = self.cangganShiShen[sz.weiZhi]
- for i in range(0, 3):
- if ganWuXing[i] is not None:
- self.wuxingCounterIncludeCangGan[ganWuXing[i]] += round(per[i], 1)
- if ganShiShen[i] is not None:
- self.shishenCounterIncludeCangGan[ganShiShen[i]] += round(per[i], 1)
- def increase_shishen_power(self, shishen: str, power: int):
- self.shishenPower[shishen] += power
- def count_wuxing(self, wuxing: str, includeCangGan: bool):
- try:
- if includeCangGan is True:
- return self.wuxingCounterIncludeCangGan[wuxing]
- else:
- return self.wuxingCounter[wuxing]
- except KeyError:
- return 0
- def count_shishen(self, shishen: str, includeCangGan: bool):
- try:
- if includeCangGan is True:
- return self.shishenCounterIncludeCangGan[shishen]
- else:
- return self.shishenCounter[shishen]
- except KeyError:
- return 0
- def get_shishen_power(self, shishen: str):
- try:
- return self.shishenPower[shishen]
- except KeyError:
- return 0
- def add_gaoneng_in_weizhi(self, weizhi: int, text: str):
- self.gaonengInWeiZhi[weizhi].append(text)
- def has_gaoneng_in_weizhi(self, weizhi: int, text: str):
- if text is None:
- return False
- try:
- lst = self.gaonengInWeiZhi[weizhi]
- return lst.__contains__(text)
- except KeyError:
- return False
- def get_canggan_power_percentage(self, weizhi: int):
- try:
- return self.cangGanPowerPercentage[weizhi]
- except KeyError:
- return [0, 0, 0]
- def get_cangan_power_percentage_by_zhu(self, sz: SiZhu):
- result = [0, 0, 0]
- if sz.isTianGan:
- return result
- ct = 0
- if sz.cangGan1 is not None:
- ct += 1
- if sz.cangGan2 is not None:
- ct += 1
- if sz.cangGan3 is not None:
- ct += 1
- if ct == 1:
- result = [1, 0, 0]
- elif ct == 2:
- result = [0.7, 0.3, 0]
- elif ct == 3:
- if sz.muku is None:
- result = [0.6, 0.3, 0.1]
- else:
- if sz.muku.isOpen is True:
- result = [0.1, 0.6, 0.3]
- else:
- result = [0.6, 0.3, 0.1]
- return result
- def get_power_step(self, wuxing: str):
- try:
- return self.powerStep[wuxing]
- except KeyError:
- return 0
- def has_all_shishen(self, shishens: [str]):
- result = True
- for ss in shishens:
- if not self.shiShenTexts.__contains__(ss):
- result = False
- break
- return result
- def has_shishen(self, shishen: str):
- return self.shiShenTexts.__contains__(shishen)
- # 存在一个就返回True
- def has_shishen_in_dizhi(self, shishens: [str]):
- result = False
- for i in range(5, 9):
- if self.shishenMap[i] in shishens:
- result = True
- break
- return result
- def has_xiongji(self, key: str):
- return self.xiongjiTexts.__contains__(key)
- def get_tiangan_by_shishen(self, shishen: str):
- return self.shishenOfTianGan[shishen]
- def get_dizhi_by_shishen(self, shishen: str):
- return self.shishenOfDiZhi[shishen]
- def get_wangshuai_by_wuxing(self, wuxing: str):
- return self.wuxingWangShuai[wuxing]
|