SiZhuLogic.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import Common
  2. from DataCenter import DataCenter
  3. from LocalModel import SiZhu, BaZi, GaoNeng
  4. def fill_sizhu(bazi: BaZi, dc: DataCenter):
  5. for gan in bazi.sizhu_tiangans():
  6. __fill_sizhu_of_tiangan(gan)
  7. for zhi in bazi.sizhu_dizhis():
  8. __fill_sizhu_of_dizhi(zhi)
  9. for tg in bazi.sizhu_tiangans():
  10. if Common.has_genqi(tg.wuXing, zhi.wuXing):
  11. dc.genqi[tg.weiZhi][0] += 1
  12. else:
  13. dc.genqi[tg.weiZhi][1] += 1
  14. __fill_sizhu_of_zhangsheng(bazi.nianZhi, bazi.nianGan.text, bazi.riGan.text)
  15. __fill_sizhu_of_zhangsheng(bazi.yueZhi, bazi.yueGan.text, bazi.riGan.text)
  16. __fill_sizhu_of_zhangsheng(bazi.riZhi, bazi.riGan.text, bazi.riGan.text)
  17. __fill_sizhu_of_zhangsheng(bazi.shiZhi, bazi.shiGan.text, bazi.riGan.text)
  18. for zhi in bazi.sizhu_dizhis():
  19. __fill_cang_gan(zhi, bazi.riGan)
  20. for sz in bazi.sizhu_all():
  21. __fill_shishen(bazi.riGan, sz)
  22. dc.shishenMap[sz.weiZhi] = sz.shiShen
  23. dc.shiShenTexts.append(sz.shiShen)
  24. __calc_shishen_guanxi(bazi)
  25. __calc_shishen_of_tiangan(bazi, dc)
  26. __calc_shishen_of_dizhi(bazi, dc)
  27. def check_muku(bazi: BaZi, dc: DataCenter):
  28. for zhi in bazi.sizhu_dizhis():
  29. __check_muku(zhi, bazi, dc)
  30. def update_powers(bazi: BaZi, dc: DataCenter):
  31. for sz in bazi.sizhu_all():
  32. sz.power = dc.get_shishen_power(sz.shiShen)
  33. per = dc.get_canggan_power_percentage(sz.weiZhi)
  34. sz.update_canggan_powers(per)
  35. sz.selfPower = sz.get_canggan_power_by_wuxing(sz.wuXing)
  36. def next_tiangan(tiangan: str):
  37. return __get_next(Common.tiangan_ary, tiangan)
  38. def next_dizhi(dizhi: str):
  39. return __get_next(Common.dizhi_ary, dizhi)
  40. def get_dizhi_by_hour(hour: int):
  41. index = 0
  42. if hour == 23 or hour == 0:
  43. index = 0
  44. elif hour == 1 or hour == 2:
  45. index = 1
  46. elif hour == 3 or hour == 4:
  47. index = 2
  48. elif hour == 5 or hour == 6:
  49. index = 3
  50. elif hour == 7 or hour == 8:
  51. index = 4
  52. elif hour == 9 or hour == 10:
  53. index = 5
  54. elif hour == 11 or hour == 12:
  55. index = 6
  56. elif hour == 13 or hour == 14:
  57. index = 7
  58. elif hour == 15 or hour == 16:
  59. index = 8
  60. elif hour == 17 or hour == 18:
  61. index = 9
  62. elif hour == 19 or hour == 20:
  63. index = 10
  64. elif hour == 21 or hour == 22:
  65. index = 11
  66. return Common.dizhi_ary[index]
  67. def get_tiangan_start_of_hour(day_tiangan: str):
  68. start_tiangan = ""
  69. if day_tiangan == "甲" or day_tiangan == "己":
  70. start_tiangan = "甲"
  71. elif day_tiangan == "乙" or day_tiangan == "庚":
  72. start_tiangan = "丙"
  73. elif day_tiangan == "丙" or day_tiangan == "辛":
  74. start_tiangan = "戊"
  75. elif day_tiangan == "丁" or day_tiangan == "壬":
  76. start_tiangan = "庚"
  77. elif day_tiangan == "戊" or day_tiangan == "癸":
  78. start_tiangan = "壬"
  79. return start_tiangan
  80. def get_tiangan_by_hour(start_tiangan: str, hour: int):
  81. dist = 0
  82. if hour == 23 or hour == 0:
  83. dist = 0
  84. elif hour == 1 or hour == 2:
  85. dist = 1
  86. elif hour == 3 or hour == 4:
  87. dist = 2
  88. elif hour == 5 or hour == 6:
  89. dist = 3
  90. elif hour == 7 or hour == 8:
  91. dist = 4
  92. elif hour == 9 or hour == 10:
  93. dist = 5
  94. elif hour == 11 or hour == 12:
  95. dist = 6
  96. elif hour == 13 or hour == 14:
  97. dist = 7
  98. elif hour == 15 or hour == 16:
  99. dist = 8
  100. elif hour == 17 or hour == 18:
  101. dist = 9
  102. elif hour == 19 or hour == 20:
  103. dist = 10
  104. elif hour == 21 or hour == 22:
  105. dist = 11
  106. tiangan = start_tiangan
  107. while dist > 0:
  108. tiangan = next_tiangan(tiangan)
  109. dist -= 1
  110. return tiangan
  111. def __fill_sizhu_of_tiangan(sizhu: SiZhu):
  112. sizhu.wuXing = Common.get_wuxing(sizhu.text)
  113. sizhu.yinYang = Common.get_yinyang(sizhu.text)
  114. def __fill_sizhu_of_dizhi(sizhu: SiZhu):
  115. sizhu.wuXing = Common.get_wuxing(sizhu.text)
  116. sizhu.yinYang = Common.get_yinyang(sizhu.text)
  117. def __fill_sizhu_of_zhangsheng(sizhu: SiZhu, tiangan: str, riyuan: str):
  118. sizhu.tongzhuZhangSheng = Common.get_zhangsheng(tiangan, sizhu.text)
  119. sizhu.riyuanZhangSheng = Common.get_zhangsheng(riyuan, sizhu.text)
  120. def __fill_cang_gan(sizhu: SiZhu, rigan: SiZhu):
  121. cgs = Common.get_canggans(sizhu.text)
  122. sizhu.cangGan1 = cgs[0]
  123. sizhu.cangGan2 = cgs[1]
  124. sizhu.cangGan3 = cgs[2]
  125. sizhu.gan1WuXing = Common.get_wuxing(sizhu.cangGan1)
  126. sizhu.gan2WuXing = Common.get_wuxing(sizhu.cangGan2)
  127. sizhu.gan3WuXing = Common.get_wuxing(sizhu.cangGan3)
  128. sizhu.gan1ShiShen = Common.get_shishen(sizhu.cangGan1, rigan.text)
  129. sizhu.gan2ShiShen = Common.get_shishen(sizhu.cangGan2, rigan.text)
  130. sizhu.gan3ShiShen = Common.get_shishen(sizhu.cangGan3, rigan.text)
  131. def __check_muku(dizhi: SiZhu, bazi: BaZi, dc: DataCenter, extraGaoNengs: [GaoNeng] = None):
  132. muku = dizhi.muku
  133. if muku is None:
  134. return
  135. obj = Common.get_muku_info(dizhi.text)
  136. muku.state = ""
  137. muku.lock = obj["lock"]
  138. muku.chong = obj["chong"]
  139. muku.gonghe = obj["gonghe"]
  140. muku.zixing = obj["zixing"]
  141. muku.sanhui = obj["sanhui"]
  142. muku.anhe = obj["anhe"]
  143. muku.isLock = False
  144. muku.hasChong = False
  145. muku.hasGonghe = False
  146. muku.hasZiXing = False
  147. muku.hasSanHui = False
  148. muku.hasAnHe = False
  149. muku.isOpen = False
  150. localLock = dc.has_gaoneng(muku.lock)
  151. extraLock = __has_gaoneng_in_extra_list(extraGaoNengs, muku.lock)
  152. localChong = dc.has_gaoneng(muku.chong)
  153. extraChong = __has_gaoneng_in_extra_list(extraGaoNengs, muku.chong)
  154. localGongHe = dc.has_gaoneng(muku.gonghe)
  155. extraGongHe = __has_gaoneng_in_extra_list(extraGaoNengs, muku.gonghe)
  156. localAnHe = dc.has_gaoneng(muku.anhe)
  157. extraAnHe = __has_gaoneng_in_extra_list(extraGaoNengs, muku.anhe)
  158. localZiXing = dc.has_gaoneng(muku.zixing)
  159. extraZiXing = __has_gaoneng_in_extra_list(extraGaoNengs, muku.zixing)
  160. localSanHui = dc.has_gaoneng(muku.sanhui)
  161. extraSanHui = __has_gaoneng_in_extra_list(extraGaoNengs, muku.sanhui)
  162. if localLock or extraLock:
  163. muku.isLock = True
  164. muku.state = muku.lock + "锁库"
  165. # 拱合开库
  166. if localGongHe or extraGongHe:
  167. muku.hasGonghe = True
  168. muku.isOpen = True
  169. muku.state += "," + muku.gonghe + "开库"
  170. # 自刑开库
  171. elif localZiXing or extraZiXing:
  172. muku.hasZiXing = True
  173. muku.isOpen = True
  174. muku.state += "," + muku.zixing + "开库"
  175. # 三会开库
  176. elif localSanHui or extraSanHui:
  177. muku.hasSanHui = True
  178. muku.isOpen = True
  179. muku.state += "," + muku.sanhui + "开库"
  180. # 暗合开库
  181. elif localAnHe or extraAnHe:
  182. if localChong or extraChong:
  183. muku.hasAnhe = True
  184. muku.isOpen = True
  185. muku.state += "," + muku.anhe + "," + muku.chong + "开库"
  186. else:
  187. if localChong or extraChong:
  188. muku.hasChong = True
  189. muku.isOpen = True
  190. muku.state = "未锁库," + muku.chong + "开库"
  191. def __has_gaoneng_in_extra_list(gns: [GaoNeng], text: str):
  192. result = False
  193. if gns is None or text is None:
  194. return result
  195. for gn in gns:
  196. if gn.text == text:
  197. result = True
  198. break
  199. return result
  200. def __fill_shishen(rigan: SiZhu, other: SiZhu):
  201. other.shiShen = Common.get_shishen(other.text, rigan.text)
  202. def __calc_shishen_guanxi(bazi: BaZi):
  203. obj = Common.get_wuxing_shishen_guanxi(bazi.riGan.wuXing)
  204. for wuxing in Common.wuxing_ary:
  205. bazi.guanxiInfo.shishen[wuxing] = obj[wuxing]
  206. def __calc_shishen_of_tiangan(bazi: BaZi, dc: DataCenter):
  207. for tg in Common.tiangan_ary:
  208. ss = Common.get_shishen(tg, bazi.riGan.text)
  209. bazi.guanxiInfo.tiangan[tg] = ss
  210. dc.shishenOfTianGan[ss] = tg
  211. def __calc_shishen_of_dizhi(bazi: BaZi, dc: DataCenter):
  212. for dz in Common.dizhi_ary:
  213. ss = Common.get_shishen(dz, bazi.riGan.text)
  214. bazi.guanxiInfo.dizhi[dz] = ss
  215. dc.shishenOfDiZhi[ss].append(dz)
  216. def __get_next(ary: [], dt: str):
  217. index = ary.index(dt)
  218. i = index + 1
  219. if i > len(ary) - 1:
  220. i = 0
  221. return ary[i]