12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- import Common
- from DataCenter import DataCenter
- from LocalModel import BaZi, WangShuaiPower
- def calc_powers(bazi: BaZi, dc: DataCenter):
- # 计算旺相休囚死
- wxList = Common.get_wangshuai(bazi.yueZhi.wuXing)
- tags = ["旺", "相", "休", "囚", "死"]
- scores = [100, 80, 60, 40, 20]
- temp = []
- for index, wx in enumerate(wxList):
- wsp = WangShuaiPower(wx, tags[index])
- __fill_wangshuaiPower(wsp, bazi, scores[index], dc)
- dc.powerStep[wsp.wuxing] = scores[index]
- dc.wuxingWangShuai[wsp.wuxing] = tags[index]
- temp.append(wsp)
- calc_percentages(temp, False, bazi, dc)
- def calc_percentages(lst: [WangShuaiPower], calcZengQiang: bool, bazi: BaZi, dc: DataCenter):
- if calcZengQiang:
- for wsp in lst:
- if wsp.shishen1ZengQiang > 0 or wsp.shishen2ZengQiang > 0:
- wsp.shishen1ValueAfterZengQiang = wsp.shishenValue1 + wsp.shishen1ZengQiang
- wsp.shishen2ValueAfterZengQiang = wsp.shishenValue2 + wsp.shishen2ZengQiang
- wsp.valueAfterZengQiang = wsp.value + wsp.shishen1ZengQiang + wsp.shishen2ZengQiang
- dc.increase_shishen_power(wsp.shishen1, wsp.shishen1ZengQiang)
- dc.increase_shishen_power(wsp.shishen2, wsp.shishen2ZengQiang)
- ssCount = wsp.shishen1ValueAfterZengQiang + wsp.shishen2ValueAfterZengQiang
- if ssCount == 0:
- wsp.shishenPercentage1 = 0
- wsp.shishenPercentage2 = 0
- else:
- wsp.shishenPercentage1 = round(wsp.shishen1ValueAfterZengQiang / ssCount * 100, 0)
- wsp.shishenPercentage2 = round(wsp.shishen2ValueAfterZengQiang / ssCount * 100, 0)
- ct = 0
- for wsp in lst:
- ct += wsp.valueAfterZengQiang
- for wsp in lst:
- wsp.calcPercentage(ct)
- # 计算同党异党比例
- tongdang = 0
- yidang = 0
- for wsp in lst:
- if wsp.shishen1 in Common.tongdang_ary:
- tongdang += wsp.value
- elif wsp.shishen1 in Common.yidang_ary:
- yidang += wsp.value
- v1 = round(tongdang / (tongdang + yidang) * 100, 0)
- v2 = round(yidang / (tongdang + yidang) * 100, 0)
- bazi.powerInfo.wangShuaiPowers = lst
- bazi.powerInfo.tongdang = v1
- bazi.powerInfo.yidang = v2
- def __fill_wangshuaiPower(wsPower: WangShuaiPower, bazi: BaZi, score: int, dc: DataCenter):
- wsPower.amount = round(dc.count_wuxing(wsPower.wuxing, True), 2)
- wsPower.value = round(wsPower.amount * score, 2)
- shishenAry = bazi.guanxiInfo.shishen[wsPower.wuxing]
- wsPower.shishen1 = shishenAry[0]
- wsPower.shishen2 = shishenAry[1]
- wsPower.shishenAmount1 = round(dc.count_shishen(wsPower.shishen1, True), 2)
- wsPower.shishenValue1 = round(wsPower.shishenAmount1 * score, 2)
- wsPower.shishenAmount2 = round(dc.count_shishen(wsPower.shishen2, True), 2)
- wsPower.shishenValue2 = round(wsPower.shishenAmount2 * score, 2)
- wsPower.shishen1ValueAfterZengQiang = wsPower.shishenValue1 + wsPower.shishen1ZengQiang
- wsPower.shishen2ValueAfterZengQiang = wsPower.shishenValue2 + wsPower.shishen2ZengQiang
- wsPower.valueAfterZengQiang = wsPower.value + wsPower.shishen1ZengQiang + wsPower.shishen2ZengQiang
- dc.increase_shishen_power(wsPower.shishen1, wsPower.shishen1ValueAfterZengQiang)
- dc.increase_shishen_power(wsPower.shishen2, wsPower.shishen2ValueAfterZengQiang)
- ssCount = wsPower.shishen1ValueAfterZengQiang + wsPower.shishen2ValueAfterZengQiang
- if ssCount == 0:
- wsPower.shishenPercentage1 = 0
- wsPower.shishenPercentage2 = 0
- else:
- wsPower.shishenPercentage1 = round(wsPower.shishen1ValueAfterZengQiang / ssCount * 100, 0)
- wsPower.shishenPercentage2 = round(wsPower.shishen2ValueAfterZengQiang / ssCount * 100, 0)
|