XingGeLogic.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import Common
  2. from LocalModel import BaZi, XingGeDesc
  3. def fill_xingge(bazi: BaZi):
  4. # > 50% strong
  5. # < 18% low
  6. # 18% - 50% middle
  7. # 五行性格
  8. bazi.xinggeInfo["wuxing"] = []
  9. bazi.xinggeInfo["shishen"] = []
  10. zuozhiFullName = __get_shishen_full_name(bazi.riZhi.shiShen)
  11. zuozhiSimpleName = __get_shishen_simple_name(bazi.riZhi.shiShen)
  12. for wsp in bazi.powerInfo.wangShuaiPowers:
  13. wx = __build_xingge_desc(wsp.wuxing, wsp.percentage)
  14. fullShiShen = __get_shishen_full_name(wsp.shishen1)
  15. name1 = __get_shishen_simple_name(wsp.shishen1)
  16. name2 = __get_shishen_simple_name(wsp.shishen2)
  17. ssMain = __build_xingge_desc(fullShiShen, wsp.percentage)
  18. ss1 = __build_xingge_desc(name1, wsp.shishenPercentage1InTotal)
  19. ss2 = __build_xingge_desc(name2, wsp.shishenPercentage2InTotal)
  20. if fullShiShen == zuozhiFullName:
  21. ssMain.zuozhi = True
  22. if name1 == zuozhiSimpleName:
  23. ss1.zuozhi = True
  24. if name2 == zuozhiSimpleName:
  25. ss2.zuozhi = True
  26. bazi.xinggeInfo["wuxing"].append(wx)
  27. bazi.xinggeInfo["shishen"].append(ssMain)
  28. bazi.xinggeInfo["shishen"].append(ss1)
  29. bazi.xinggeInfo["shishen"].append(ss2)
  30. def __build_xingge_desc(key: str, value: int):
  31. desc = XingGeDesc()
  32. desc.key = key
  33. desc.value = value
  34. xg = Common.get_xingge(desc.key)
  35. desc.low = xg["low"]
  36. desc.middle = xg["middle"]
  37. desc.strong = xg["strong"]
  38. if desc.value >= 50:
  39. desc.state = "过旺"
  40. elif desc.value < 18:
  41. desc.state = "衰"
  42. else:
  43. desc.state = "旺"
  44. return desc
  45. def __get_shishen_simple_name(shishen: str):
  46. if shishen == "官":
  47. return "正官"
  48. if shishen == "杀":
  49. return "七杀"
  50. if shishen == "比":
  51. return "比肩"
  52. if shishen == "劫":
  53. return "劫财"
  54. if shishen == "印":
  55. return "正印"
  56. if shishen == "枭":
  57. return "偏印"
  58. if shishen == "食":
  59. return "食神"
  60. if shishen == "伤":
  61. return "伤官"
  62. if shishen == "财":
  63. return "正财"
  64. if shishen == "才":
  65. return "偏财"
  66. return "未知"
  67. def __get_shishen_full_name(shishen: str):
  68. if shishen in ["官", "杀"]:
  69. return "官杀"
  70. if shishen in ["比", "劫"]:
  71. return "比劫"
  72. if shishen in ["食", "伤"]:
  73. return "食伤"
  74. if shishen in ["印", "枭"]:
  75. return "印绶"
  76. if shishen in ["财", "才"]:
  77. return "财星"
  78. return "未知"