JieGouLogic.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import Common
  2. from DataCenter import DataCenter
  3. from LocalModel import BaZi, JieGou
  4. def calc_jiegou(bazi: BaZi, dc: DataCenter):
  5. guanxis = ["合", "暗合", "冲", "穿", "破"]
  6. for ss in Common.shishen_ary:
  7. for guanxi in guanxis:
  8. lst = __get_jiegou_list_in_bazi(ss, guanxi, bazi)
  9. tg = dc.get_tiangan_by_shishen(ss)
  10. dz = dc.get_dizhi_by_shishen(ss)
  11. __build_jiegou_data([tg], ss, guanxi, lst, bazi, dc)
  12. __build_jiegou_data(dz, ss, guanxi, lst, bazi, dc)
  13. def __build_jiegou_data(texts: [str], shishen: str, guanxi: str, lst: [JieGou], bazi: BaZi, dc: DataCenter):
  14. for key in texts:
  15. data = Common.find_gaoneng_by_key_and_guanxi(key, guanxi)
  16. bh = __find_baohu_in_bazi(key, bazi)
  17. bazi.jiegouInfo.baohu[shishen] = bh
  18. for dt in data:
  19. other = Common.get_other_arg_in_gaoneng(key, guanxi, dt["name"])
  20. otherShiShen = Common.get_shishen(other, bazi.riGan.text)
  21. hasGaoneng = dc.has_gaoneng(dt["name"])
  22. level = 1 if hasGaoneng else 0
  23. if key in Common.muku_ary and other in Common.muku_ary:
  24. continue
  25. jg = JieGou(key, other, guanxi, level, shishen, otherShiShen, Common.is_tiangan(key))
  26. if guanxi in ["冲", "穿", "破"]:
  27. jg.baohu = __find_baohu_in_bazi(other, bazi)
  28. if not __has_data_in_list(shishen, otherShiShen, lst):
  29. lst.append(jg)
  30. def __has_data_in_list(shishen1: str, shishen2: str, lst: [JieGou]):
  31. result = False
  32. for dt in lst:
  33. if dt.shishen1 == shishen1 and dt.shishen2 == shishen2:
  34. result = True
  35. break
  36. return result
  37. def __find_baohu_in_bazi(arg: str, bazi: BaZi):
  38. found = False
  39. for dt in bazi.gaonengInfo.heList:
  40. if dt.leibie == "地支合":
  41. if dt.arg1 == arg or dt.arg2 == arg:
  42. found = True
  43. break
  44. return found
  45. def __get_jiegou_list_in_bazi(key: str, guanxi: str, bazi: BaZi):
  46. if key == "官":
  47. if guanxi == "合":
  48. return bazi.jiegouInfo.guanHe
  49. if guanxi == "暗合":
  50. return bazi.jiegouInfo.guanAnHe
  51. if guanxi == "冲":
  52. return bazi.jiegouInfo.guanChong
  53. if guanxi == "穿":
  54. return bazi.jiegouInfo.guanChuan
  55. if guanxi == "破":
  56. return bazi.jiegouInfo.guanPo
  57. elif key == "杀":
  58. if guanxi == "合":
  59. return bazi.jiegouInfo.shaHe
  60. if guanxi == "暗合":
  61. return bazi.jiegouInfo.shaAnHe
  62. if guanxi == "冲":
  63. return bazi.jiegouInfo.shaChong
  64. if guanxi == "穿":
  65. return bazi.jiegouInfo.shaChuan
  66. if guanxi == "破":
  67. return bazi.jiegouInfo.shaPo
  68. elif key == "财":
  69. if guanxi == "合":
  70. return bazi.jiegouInfo.cai1He
  71. if guanxi == "暗合":
  72. return bazi.jiegouInfo.cai1AnHe
  73. if guanxi == "冲":
  74. return bazi.jiegouInfo.cai1Chong
  75. if guanxi == "穿":
  76. return bazi.jiegouInfo.cai1Chuan
  77. if guanxi == "破":
  78. return bazi.jiegouInfo.cai1Po
  79. elif key == "才":
  80. if guanxi == "合":
  81. return bazi.jiegouInfo.cai2He
  82. if guanxi == "暗合":
  83. return bazi.jiegouInfo.cai2AnHe
  84. if guanxi == "冲":
  85. return bazi.jiegouInfo.cai2Chong
  86. if guanxi == "穿":
  87. return bazi.jiegouInfo.cai2Chuan
  88. if guanxi == "破":
  89. return bazi.jiegouInfo.cai2Po
  90. elif key == "印":
  91. if guanxi == "合":
  92. return bazi.jiegouInfo.yinHe
  93. if guanxi == "暗合":
  94. return bazi.jiegouInfo.yinAnHe
  95. if guanxi == "冲":
  96. return bazi.jiegouInfo.yinChong
  97. if guanxi == "穿":
  98. return bazi.jiegouInfo.yinChuan
  99. if guanxi == "破":
  100. return bazi.jiegouInfo.yinPo
  101. elif key == "枭":
  102. if guanxi == "合":
  103. return bazi.jiegouInfo.xiaoHe
  104. if guanxi == "暗合":
  105. return bazi.jiegouInfo.xiaoAnHe
  106. if guanxi == "冲":
  107. return bazi.jiegouInfo.xiaoChong
  108. if guanxi == "穿":
  109. return bazi.jiegouInfo.xiaoChuan
  110. if guanxi == "破":
  111. return bazi.jiegouInfo.xiaoPo
  112. elif key == "食":
  113. if guanxi == "合":
  114. return bazi.jiegouInfo.shiHe
  115. if guanxi == "暗合":
  116. return bazi.jiegouInfo.shiAnHe
  117. if guanxi == "冲":
  118. return bazi.jiegouInfo.shiChong
  119. if guanxi == "穿":
  120. return bazi.jiegouInfo.shiChuan
  121. if guanxi == "破":
  122. return bazi.jiegouInfo.shiPo
  123. elif key == "伤":
  124. if guanxi == "合":
  125. return bazi.jiegouInfo.shangHe
  126. if guanxi == "暗合":
  127. return bazi.jiegouInfo.shangAnHe
  128. if guanxi == "冲":
  129. return bazi.jiegouInfo.shangChong
  130. if guanxi == "穿":
  131. return bazi.jiegouInfo.shangChuan
  132. if guanxi == "破":
  133. return bazi.jiegouInfo.shangPo
  134. elif key == "比":
  135. if guanxi == "合":
  136. return bazi.jiegouInfo.biHe
  137. if guanxi == "暗合":
  138. return bazi.jiegouInfo.biAnHe
  139. if guanxi == "冲":
  140. return bazi.jiegouInfo.biChong
  141. if guanxi == "穿":
  142. return bazi.jiegouInfo.biChuan
  143. if guanxi == "破":
  144. return bazi.jiegouInfo.biPo
  145. elif key == "劫":
  146. if guanxi == "合":
  147. return bazi.jiegouInfo.jieHe
  148. if guanxi == "暗合":
  149. return bazi.jiegouInfo.jieAnHe
  150. if guanxi == "冲":
  151. return bazi.jiegouInfo.jieChong
  152. if guanxi == "穿":
  153. return bazi.jiegouInfo.jieChuan
  154. if guanxi == "破":
  155. return bazi.jiegouInfo.jiePo
  156. return []