PowerLogic.py 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import Common
  2. from DataCenter import DataCenter
  3. from LocalModel import BaZi, WangShuaiPower
  4. def calc_powers(bazi: BaZi, dc: DataCenter):
  5. # 计算旺相休囚死
  6. wxList = Common.get_wangshuai(bazi.yueZhi.wuXing)
  7. tags = ["旺", "相", "休", "囚", "死"]
  8. scores = [100, 80, 60, 40, 20]
  9. temp = []
  10. for index, wx in enumerate(wxList):
  11. wsp = WangShuaiPower(wx, tags[index])
  12. __fill_wangshuaiPower(wsp, bazi, scores[index], dc)
  13. dc.powerStep[wsp.wuxing] = scores[index]
  14. dc.wuxingWangShuai[wsp.wuxing] = tags[index]
  15. temp.append(wsp)
  16. calc_percentages(temp, False, bazi, dc)
  17. def calc_percentages(lst: [WangShuaiPower], calcZengQiang: bool, bazi: BaZi, dc: DataCenter):
  18. if calcZengQiang:
  19. for wsp in lst:
  20. if wsp.shishen1ZengQiang > 0 or wsp.shishen2ZengQiang > 0:
  21. wsp.shishen1ValueAfterZengQiang = wsp.shishenValue1 + wsp.shishen1ZengQiang
  22. wsp.shishen2ValueAfterZengQiang = wsp.shishenValue2 + wsp.shishen2ZengQiang
  23. wsp.valueAfterZengQiang = wsp.value + wsp.shishen1ZengQiang + wsp.shishen2ZengQiang
  24. dc.increase_shishen_power(wsp.shishen1, wsp.shishen1ZengQiang)
  25. dc.increase_shishen_power(wsp.shishen2, wsp.shishen2ZengQiang)
  26. ssCount = wsp.shishen1ValueAfterZengQiang + wsp.shishen2ValueAfterZengQiang
  27. if ssCount == 0:
  28. wsp.shishenPercentage1 = 0
  29. wsp.shishenPercentage2 = 0
  30. else:
  31. wsp.shishenPercentage1 = round(wsp.shishen1ValueAfterZengQiang / ssCount * 100, 0)
  32. wsp.shishenPercentage2 = round(wsp.shishen2ValueAfterZengQiang / ssCount * 100, 0)
  33. ct = 0
  34. for wsp in lst:
  35. ct += wsp.valueAfterZengQiang
  36. for wsp in lst:
  37. wsp.calcPercentage(ct)
  38. # 计算同党异党比例
  39. tongdang = 0
  40. yidang = 0
  41. for wsp in lst:
  42. if wsp.shishen1 in Common.tongdang_ary:
  43. tongdang += wsp.value
  44. elif wsp.shishen1 in Common.yidang_ary:
  45. yidang += wsp.value
  46. v1 = round(tongdang / (tongdang + yidang) * 100, 0)
  47. v2 = round(yidang / (tongdang + yidang) * 100, 0)
  48. bazi.powerInfo.wangShuaiPowers = lst
  49. bazi.powerInfo.tongdang = v1
  50. bazi.powerInfo.yidang = v2
  51. def __fill_wangshuaiPower(wsPower: WangShuaiPower, bazi: BaZi, score: int, dc: DataCenter):
  52. wsPower.amount = round(dc.count_wuxing(wsPower.wuxing, True), 2)
  53. wsPower.value = round(wsPower.amount * score, 2)
  54. shishenAry = bazi.guanxiInfo.shishen[wsPower.wuxing]
  55. wsPower.shishen1 = shishenAry[0]
  56. wsPower.shishen2 = shishenAry[1]
  57. wsPower.shishenAmount1 = round(dc.count_shishen(wsPower.shishen1, True), 2)
  58. wsPower.shishenValue1 = round(wsPower.shishenAmount1 * score, 2)
  59. wsPower.shishenAmount2 = round(dc.count_shishen(wsPower.shishen2, True), 2)
  60. wsPower.shishenValue2 = round(wsPower.shishenAmount2 * score, 2)
  61. wsPower.shishen1ValueAfterZengQiang = wsPower.shishenValue1 + wsPower.shishen1ZengQiang
  62. wsPower.shishen2ValueAfterZengQiang = wsPower.shishenValue2 + wsPower.shishen2ZengQiang
  63. wsPower.valueAfterZengQiang = wsPower.value + wsPower.shishen1ZengQiang + wsPower.shishen2ZengQiang
  64. dc.increase_shishen_power(wsPower.shishen1, wsPower.shishen1ValueAfterZengQiang)
  65. dc.increase_shishen_power(wsPower.shishen2, wsPower.shishen2ValueAfterZengQiang)
  66. ssCount = wsPower.shishen1ValueAfterZengQiang + wsPower.shishen2ValueAfterZengQiang
  67. if ssCount == 0:
  68. wsPower.shishenPercentage1 = 0
  69. wsPower.shishenPercentage2 = 0
  70. else:
  71. wsPower.shishenPercentage1 = round(wsPower.shishen1ValueAfterZengQiang / ssCount * 100, 0)
  72. wsPower.shishenPercentage2 = round(wsPower.shishen2ValueAfterZengQiang / ssCount * 100, 0)