GaoNengLogic.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. import Common
  2. import PowerLogic
  3. import SiZhuLogic
  4. from DataCenter import DataCenter
  5. from LocalModel import BaZi, GaoNeng, SiZhu
  6. from model import GaonengMid
  7. gaoneng_tips = [
  8. "合多:喜社交,擅处理人际关系,喜与人为善,不喜争斗;",
  9. "冲多:擅运动,喜欢对抗,喜欢折腾;",
  10. "天干合:合中带克,夫妻关系",
  11. "天干冲:甲庚、乙辛金木冲,意外伤;丙壬、丁癸水火冲,情绪不稳",
  12. "地支合:申子辰合水,寅午戌合火,亥卯未合木,巳酉丑合金",
  13. "地支冲:丑未、寅申、卯酉金木冲,意外伤;子午、辰戌、巳亥水火冲,情绪不稳",
  14. "地支穿:穿又叫害,表达一种不对付的关系,常见于关系被挑拨离间、三角恋等,穿是一种互相伤害的概念。",
  15. "地支刑:刑表示互相折磨互相伤害、较力、掰手腕。子卯刑表示傲慢无礼,不知感恩;申寅巳刑表示不服管教,恃势之刑;丑未戌刑表示家庭不和睦,亲骨无恩,不利亲情。",
  16. "自刑:自我折磨,有精神障碍,心门不开",
  17. "地支暗合:午亥暗合,表示财源来路不明,有婚外情;申卯暗合,表示搞手段,暗箱操作,使阴招;寅丑暗合,表示被偷盗、丢东西、破财。",
  18. "地支破:争吵,多见于婚姻关系中"
  19. ]
  20. def check_gaoneng(bazi: BaZi, dc: DataCenter):
  21. tgs = bazi.sizhu_tiangans()
  22. dzs = bazi.sizhu_dizhis()
  23. for tg in tgs:
  24. __fix_tiangan_gaoneng(tg, tgs, bazi, dc, True)
  25. # 检查三合三会三刑
  26. for dz in dzs:
  27. __fix_dizhi3_gaoneng(dz, dzs, bazi, dc, True)
  28. for dz in dzs:
  29. __fix_dizhi2_gaoneng(dz, dzs, bazi, dc, True)
  30. def update_gaoneng_power(bazi: BaZi, dc: DataCenter):
  31. # 计算刑的力量
  32. for gn in bazi.gaonengInfo.xingList:
  33. __update_power_of_gaoneng_xing(gn, bazi, dc)
  34. # 半合带来的能量增强
  35. for gn in bazi.gaonengInfo.banHeList:
  36. zhu = gn.zhu1
  37. if gn.arg1 == gn.fangxiang:
  38. zhu = gn.zhu2
  39. wx = Common.get_wuxing(gn.fangxiang)
  40. sz = bazi.getZhuByWeiZhi(zhu)
  41. gn.banheZengQiangPower = sz.get_canggan_power_by_wuxing(wx)
  42. dc.shishenZengQiang[gn.banheZengQiangShiShen] += gn.banheZengQiangPower
  43. # 拱合带来的能量变化
  44. for gn in bazi.gaonengInfo.gongHeList:
  45. gn.gongheZengQiangPower = dc.get_power_step(gn.gongheZengQiangWuXing)
  46. dc.shishenZengQiang[gn.gongheZengQiangShiShen] += gn.gongheZengQiangPower
  47. # 三会带来的能量变化(这里其实要看有没有被破坏才决定是否增强)
  48. for gn in bazi.gaonengInfo.sanHuiList:
  49. zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
  50. zhu2 = bazi.getZhuByWeiZhi(gn.zhu2)
  51. zhu3 = bazi.getZhuByWeiZhi(gn.zhu3)
  52. p1 = zhu1.get_canggan_power_by_wuxing(gn.hehua)
  53. p2 = zhu2.get_canggan_power_by_wuxing(gn.hehua)
  54. p3 = zhu3.get_canggan_power_by_wuxing(gn.hehua)
  55. power = 0
  56. if zhu1.text != gn.fangxiang:
  57. power += p1
  58. if zhu2.text != gn.fangxiang:
  59. power += p2
  60. if zhu3.text != gn.fangxiang:
  61. power += p3
  62. gn.sanhuiZengQiangPower = power
  63. dc.shishenZengQiang[gn.sanhuiZengQiangShiShen] += gn.sanhuiZengQiangPower
  64. # 自刑带来的能量变化
  65. for gn in bazi.gaonengInfo.ziXingList:
  66. if gn.zixingZengQiangWuXing is not None:
  67. zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
  68. power = zhu1.get_canggan_power_by_wuxing(gn.zixingZengQiangWuXing)
  69. gn.zixingZengQiangPower = power
  70. # 力量变动后,重新计算counter
  71. for ss in Common.shishen_ary:
  72. zq = dc.shishenZengQiang[ss]
  73. if zq > 0:
  74. found = False
  75. for wsp in bazi.powerInfo.wangShuaiPowers:
  76. if wsp.shishen1 == ss:
  77. wsp.shishen1ZengQiang = zq
  78. found = True
  79. elif wsp.shishen2 == ss:
  80. wsp.shishen2ZengQiang = zq
  81. found = True
  82. if found:
  83. break
  84. PowerLogic.calc_percentages(bazi.powerInfo.wangShuaiPowers, True, bazi, dc)
  85. SiZhuLogic.update_powers(bazi, dc)
  86. def __fix_tiangan_gaoneng(zhu: SiZhu, tiangans: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
  87. for tg in tiangans:
  88. if zhu.weiZhi == tg.weiZhi:
  89. continue
  90. data = Common.find_gaoneng_by_texts(zhu.text, tg.text)
  91. for temp in data:
  92. gn = __build_gaoneng_object_from_data(temp, zhu, tg, None, bazi, dc, save)
  93. gn1 = gn.copySelf()
  94. __calc_fangxiang(gn1, zhu.weiZhi)
  95. zhu.gaonengs.append(gn1)
  96. if save:
  97. dc.add_gaoneng_in_weizhi(zhu.weiZhi, gn1.text)
  98. dc.add_gaoneng_in_weizhi(tg.weiZhi, gn1.text)
  99. def __fix_dizhi3_gaoneng(zhu: SiZhu, dizhis: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
  100. gnMap = {}
  101. for dz2 in dizhis:
  102. for dz3 in dizhis:
  103. if zhu.weiZhi == dz2.weiZhi or zhu.weiZhi == dz3.weiZhi or dz2.weiZhi == dz3.weiZhi:
  104. continue
  105. data = Common.find_gaoneng_by_texts(zhu.text, dz2.text, dz3.text)
  106. for temp in data:
  107. key = __calc_key_of_gaoneng_data(zhu.weiZhi, dz2.weiZhi, dz3.weiZhi, temp["name"])
  108. if not gnMap.keys().__contains__(key):
  109. gnMap[key] = __build_gaoneng_object_from_data(temp, zhu, dz2, dz3, bazi, dc, save)
  110. if save:
  111. dc.add_gaoneng_in_weizhi(zhu.weiZhi, gnMap[key].text)
  112. dc.add_gaoneng_in_weizhi(dz2.weiZhi, gnMap[key].text)
  113. dc.add_gaoneng_in_weizhi(dz3.weiZhi, gnMap[key].text)
  114. for temp in gnMap.values():
  115. gn1 = temp.copySelf()
  116. __calc_fangxiang(gn1, zhu.weiZhi)
  117. zhu.gaonengs.append(gn1)
  118. def __fix_dizhi2_gaoneng(zhu: SiZhu, dizhis: [SiZhu], bazi: BaZi, dc: DataCenter, save: bool):
  119. for dz in dizhis:
  120. if zhu.weiZhi == dz.weiZhi:
  121. continue
  122. data = Common.find_gaoneng_by_texts(zhu.text, dz.text)
  123. for temp in data:
  124. gn = __build_gaoneng_object_from_data(temp, zhu, dz, None, bazi, dc, save)
  125. gn1 = gn.copySelf()
  126. __calc_fangxiang(gn1, zhu.weiZhi)
  127. zhu.gaonengs.append(gn1)
  128. if save:
  129. dc.add_gaoneng_in_weizhi(zhu.weiZhi, gn1.text)
  130. dc.add_gaoneng_in_weizhi(dz.weiZhi, gn1.text)
  131. def __build_gaoneng_object_from_data(data: {}, zhu1: SiZhu, zhu2: SiZhu, zhu3: SiZhu, bazi: BaZi, dc: DataCenter,
  132. save: bool):
  133. gn = GaoNeng()
  134. gn.arg1 = zhu1.text
  135. gn.arg2 = zhu2.text
  136. gn.arg3 = zhu3.text if zhu3 is not None else None
  137. gn.guanxi = data["guanxi"]
  138. gn.text = data["name"]
  139. gn.father = data["father"]
  140. gn.leibie = data["leibie"]
  141. gn.wuxing1 = zhu1.wuXing
  142. gn.wuxing2 = zhu2.wuXing
  143. gn.wuxing3 = zhu3.wuXing if zhu3 is not None else None
  144. gn.hehua = data["hehua"]
  145. gn.shishen1 = zhu1.shiShen
  146. gn.shishen2 = zhu2.shiShen
  147. gn.shishen3 = zhu3.shiShen if zhu3 is not None else None
  148. gn.power1 = dc.get_shishen_power(gn.shishen1)
  149. gn.power2 = dc.get_shishen_power(gn.shishen2)
  150. gn.power3 = dc.get_shishen_power(gn.shishen3)
  151. gn.zhu1 = zhu1.weiZhi
  152. gn.zhu2 = zhu2.weiZhi
  153. gn.zhu3 = zhu3.weiZhi if zhu3 is not None else None
  154. gn.tip = data["tip"]
  155. gn.fangxiang = data["fangxiang"]
  156. gn.key = __calc_key_of_gaoneng_data(gn.zhu1, gn.zhu2, gn.zhu3, gn.text)
  157. if gn.guanxi == "合":
  158. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
  159. bazi.gaonengInfo.heList.append(gn)
  160. elif gn.guanxi == "冲":
  161. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
  162. bazi.gaonengInfo.chongList.append(gn)
  163. elif gn.guanxi == "破":
  164. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
  165. bazi.gaonengInfo.poList.append(gn)
  166. elif gn.guanxi == "穿":
  167. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
  168. bazi.gaonengInfo.chuanList.append(gn)
  169. elif gn.guanxi == "半合":
  170. gn.banheZengQiang = gn.fangxiang
  171. gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
  172. gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
  173. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
  174. bazi.gaonengInfo.banHeList.append(gn)
  175. elif gn.guanxi == "拱合":
  176. gn.gongheZengQiang = gn.fangxiang
  177. gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
  178. gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
  179. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
  180. bazi.gaonengInfo.gongHeList.append(gn)
  181. elif gn.guanxi == "暗合":
  182. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
  183. bazi.gaonengInfo.anHeList.append(gn)
  184. elif gn.guanxi == "三会":
  185. gn.sanhuiZengQiang = gn.fangxiang
  186. gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
  187. gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
  188. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
  189. bazi.gaonengInfo.sanHuiList.append(gn)
  190. elif gn.guanxi == "自刑":
  191. gn.zixingZengQiang = gn.fangxiang
  192. gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
  193. gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
  194. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
  195. bazi.gaonengInfo.ziXingList.append(gn)
  196. elif gn.guanxi == "刑":
  197. if save:
  198. __fill_data_for_gaoneng_xing(gn, bazi)
  199. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
  200. bazi.gaonengInfo.xingList.append(gn)
  201. return gn
  202. def __build_gaoneng_object_from_data_as_text(data: {}, text: str, zhu2: SiZhu, zhu3: SiZhu, bazi: BaZi, dc: DataCenter,
  203. save: bool):
  204. gn = GaoNeng()
  205. gn.arg1 = text
  206. gn.arg2 = zhu2.text
  207. gn.arg3 = zhu3.text if zhu3 is not None else None
  208. gn.guanxi = data["guanxi"]
  209. gn.text = data["name"]
  210. gn.father = data["father"]
  211. gn.leibie = data["leibie"]
  212. gn.wuxing1 = Common.get_wuxing(text)
  213. gn.wuxing2 = zhu2.wuXing
  214. gn.wuxing3 = zhu3.wuXing if zhu3 is not None else None
  215. gn.hehua = data["hehua"]
  216. gn.shishen1 = Common.get_shishen(text, bazi.riGan.text)
  217. gn.shishen2 = zhu2.shiShen
  218. gn.shishen3 = zhu3.shiShen if zhu3 is not None else None
  219. gn.power1 = dc.get_shishen_power(gn.shishen1)
  220. gn.power2 = dc.get_shishen_power(gn.shishen2)
  221. gn.power3 = dc.get_shishen_power(gn.shishen3)
  222. gn.zhu1 = -1
  223. gn.zhu2 = zhu2.weiZhi
  224. gn.zhu3 = zhu3.weiZhi if zhu3 is not None else None
  225. gn.tip = data["tip"]
  226. gn.fangxiang = data["fangxiang"]
  227. gn.key = __calc_key_of_gaoneng_data(gn.zhu1, gn.zhu2, gn.zhu3, gn.text)
  228. if gn.guanxi == "合":
  229. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
  230. bazi.gaonengInfo.heList.append(gn)
  231. elif gn.guanxi == "冲":
  232. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
  233. bazi.gaonengInfo.chongList.append(gn)
  234. elif gn.guanxi == "破":
  235. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
  236. bazi.gaonengInfo.poList.append(gn)
  237. elif gn.guanxi == "穿":
  238. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
  239. bazi.gaonengInfo.chuanList.append(gn)
  240. elif gn.guanxi == "半合":
  241. gn.banheZengQiang = gn.fangxiang
  242. gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
  243. gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
  244. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
  245. bazi.gaonengInfo.banHeList.append(gn)
  246. elif gn.guanxi == "拱合":
  247. gn.gongheZengQiang = gn.fangxiang
  248. gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
  249. gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
  250. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
  251. bazi.gaonengInfo.gongHeList.append(gn)
  252. elif gn.guanxi == "暗合":
  253. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
  254. bazi.gaonengInfo.anHeList.append(gn)
  255. elif gn.guanxi == "三会":
  256. gn.sanhuiZengQiang = gn.fangxiang
  257. gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
  258. gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
  259. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
  260. bazi.gaonengInfo.sanHuiList.append(gn)
  261. elif gn.guanxi == "自刑":
  262. gn.zixingZengQiang = gn.fangxiang
  263. gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
  264. gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
  265. if save and not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
  266. bazi.gaonengInfo.ziXingList.append(gn)
  267. elif gn.guanxi == "刑":
  268. if save:
  269. __fill_data_for_gaoneng_xing(gn, bazi)
  270. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
  271. bazi.gaonengInfo.xingList.append(gn)
  272. return gn
  273. def __calc_key_of_gaoneng_data(zhu1: int, zhu2: int, zhu3: int, text: str):
  274. lst = [zhu1, zhu2]
  275. if zhu3 is not None:
  276. lst.append(zhu3)
  277. lst.sort()
  278. key = text
  279. for v in lst:
  280. key += str(v)
  281. return key
  282. def __has_father(gns: [GaoNeng], gn: GaoNeng):
  283. result = False
  284. if gn.father is None:
  285. return result
  286. for temp in gns:
  287. if temp.text == gn.father:
  288. result = True
  289. break
  290. return result
  291. def __build_gaoneng_object_from_db(data: GaonengMid, bazi: BaZi, zhu1: int, zhu2: int, zhu3: int, save: bool):
  292. gn = GaoNeng()
  293. gn.arg1 = data.arg1
  294. gn.arg2 = data.arg2
  295. gn.arg3 = data.arg3
  296. gn.guanxi = data.guanxi
  297. gn.text = data.desc
  298. gn.father = data.father
  299. gn.leibie = data.leibie
  300. gn.wuxing1 = data.wuxing1
  301. gn.wuxing2 = data.wuxing2
  302. gn.wuxing3 = data.wuxing3
  303. gn.hehua = data.hehua
  304. gn.shishen1 = Common.get_shishen(gn.arg1, bazi.riGan.text)
  305. gn.shishen2 = Common.get_shishen(gn.arg2, bazi.riGan.text)
  306. gn.shishen3 = Common.get_shishen(gn.arg3, bazi.riGan.text)
  307. gn.power1 = bazi.getPowerOfShiShen(gn.shishen1)
  308. gn.power2 = bazi.getPowerOfShiShen(gn.shishen2)
  309. gn.power3 = bazi.getPowerOfShiShen(gn.shishen3)
  310. gn.zhu1 = zhu1
  311. gn.zhu2 = zhu2
  312. gn.zhu3 = zhu3
  313. gn.tip = data.tip
  314. gn.fangxiang = data.fangxiang
  315. gn.key = __calc_key_of_gaoneng_data(zhu1, zhu2, zhu3, gn.text)
  316. if gn.guanxi == "合":
  317. if save:
  318. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.heList):
  319. bazi.gaonengInfo.heList.append(gn)
  320. elif gn.guanxi == "冲":
  321. if save:
  322. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chongList):
  323. bazi.gaonengInfo.chongList.append(gn)
  324. elif gn.guanxi == "破":
  325. if save:
  326. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.poList):
  327. bazi.gaonengInfo.poList.append(gn)
  328. elif gn.guanxi == "穿":
  329. if save:
  330. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.chuanList):
  331. bazi.gaonengInfo.chuanList.append(gn)
  332. elif gn.guanxi == "半合":
  333. gn.banheZengQiang = gn.fangxiang
  334. gn.banheZengQiangWuXing = Common.get_wuxing(gn.banheZengQiang)
  335. gn.banheZengQiangShiShen = Common.get_shishen(gn.banheZengQiang, bazi.riGan.text)
  336. if save:
  337. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.banHeList):
  338. bazi.gaonengInfo.banHeList.append(gn)
  339. elif gn.guanxi == "拱合":
  340. gn.gongheZengQiang = gn.fangxiang
  341. gn.gongheZengQiangWuXing = Common.get_wuxing(gn.gongheZengQiang)
  342. gn.gongheZengQiangShiShen = Common.get_shishen(gn.gongheZengQiang, bazi.riGan.text)
  343. if save:
  344. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.gongHeList):
  345. bazi.gaonengInfo.gongHeList.append(gn)
  346. elif gn.guanxi == "暗合":
  347. if save:
  348. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.anHeList):
  349. bazi.gaonengInfo.anHeList.append(gn)
  350. elif gn.guanxi == "三会":
  351. gn.sanhuiZengQiang = gn.fangxiang
  352. gn.sanhuiQiangWuXing = Common.get_wuxing(gn.sanhuiZengQiang)
  353. gn.sanhuiZengQiangShiShen = Common.get_shishen(gn.sanhuiZengQiang, bazi.riGan.text)
  354. if save:
  355. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.sanHuiList):
  356. bazi.gaonengInfo.sanHuiList.append(gn)
  357. elif gn.guanxi == "自刑":
  358. gn.zixingZengQiang = gn.fangxiang
  359. gn.zixingZengQiangWuXing = Common.get_wuxing(gn.zixingZengQiang)
  360. gn.zixingZengQiangShiShen = Common.get_shishen(gn.zixingZengQiang, bazi.riGan.text)
  361. if save:
  362. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.ziXingList):
  363. bazi.gaonengInfo.ziXingList.append(gn)
  364. elif gn.guanxi == "刑":
  365. if save:
  366. __fill_data_for_gaoneng_xing(gn, bazi)
  367. if save:
  368. if not __has_key_in_gaoneng_list(gn, bazi.gaonengInfo.xingList) and gn.arg3 is None:
  369. bazi.gaonengInfo.xingList.append(gn)
  370. return gn
  371. def __fill_data_for_gaoneng_xing(gn: GaoNeng, bazi: BaZi):
  372. found = False
  373. if gn.text == "寅巳刑":
  374. gn.xingchu1 = "丙"
  375. gn.xingchu2 = "戊"
  376. gn.xingchong = "甲庚冲"
  377. gn.xingchongArg1 = "甲"
  378. gn.xingchongArg2 = "庚"
  379. found = True
  380. elif gn.text == "巳申刑":
  381. gn.xingchu1 = "庚"
  382. gn.xingchu2 = "戊"
  383. gn.xingchong = "丙壬冲"
  384. gn.xingchongArg1 = "丙"
  385. gn.xingchongArg2 = "壬"
  386. found = True
  387. elif gn.text == "戌未刑":
  388. gn.xingchu1 = "丁"
  389. gn.xingchu2 = None
  390. gn.xingchong = "乙辛冲"
  391. gn.xingchongArg1 = "乙"
  392. gn.xingchongArg2 = "辛"
  393. found = True
  394. elif gn.text == "丑戌刑":
  395. gn.xingchu1 = "辛"
  396. gn.xingchu2 = None
  397. gn.xingchong = "丁癸冲"
  398. gn.xingchongArg1 = "丁"
  399. gn.xingchongArg2 = "癸"
  400. found = True
  401. elif gn.text == "子卯刑":
  402. gn.xingchu1 = None
  403. gn.xingchu2 = None
  404. gn.xingchong = None
  405. gn.xingchongArg1 = None
  406. gn.xingchongArg2 = None
  407. found = True
  408. if found:
  409. gn.xingchu1WuXing = Common.get_wuxing(gn.xingchu1)
  410. gn.xingchu2WuXing = Common.get_wuxing(gn.xingchu2)
  411. gn.xingchu1ShiShen = Common.get_shishen(gn.xingchu1, bazi.riGan.text)
  412. gn.xingchu2ShiShen = Common.get_shishen(gn.xingchu2, bazi.riGan.text)
  413. def __update_power_of_gaoneng_xing(gn: GaoNeng, bazi: BaZi, dc: DataCenter):
  414. zhu1 = bazi.getZhuByWeiZhi(gn.zhu1)
  415. zhu2 = bazi.getZhuByWeiZhi(gn.zhu2)
  416. gn.xingchu1Power = zhu1.get_canggan_power_by_wuxing(gn.xingchu1WuXing) + zhu2.get_canggan_power_by_wuxing(
  417. gn.xingchu1WuXing)
  418. gn.xingchu2Power = zhu1.get_canggan_power_by_wuxing(gn.xingchu2WuXing) + zhu2.get_canggan_power_by_wuxing(
  419. gn.xingchu2WuXing)
  420. gn.xingchongArg1ShiShen = Common.get_shishen(gn.xingchongArg1, bazi.riGan.text)
  421. gn.xingchongArg2ShiShen = Common.get_shishen(gn.xingchongArg2, bazi.riGan.text)
  422. gn.xingchongArg1Power = dc.get_shishen_power(gn.xingchongArg1ShiShen)
  423. gn.xingchongArg2Power = dc.get_shishen_power(gn.xingchongArg2ShiShen)
  424. def __has_key_in_gaoneng_list(gn: GaoNeng, list: [GaoNeng]):
  425. result = False
  426. for item in list:
  427. if item.key == gn.key:
  428. result = True
  429. break
  430. return result
  431. def __calc_fangxiang(gn: GaoNeng, selfZhu: int):
  432. if gn.guanxi in ["合", "暗合", "三合", "半合", "三会"]:
  433. fromZhu = selfZhu
  434. toZhu = gn.zhu1
  435. if gn.fangxiang == gn.arg2:
  436. toZhu = gn.zhu2
  437. elif gn.fangxiang == gn.arg3:
  438. toZhu = gn.zhu3
  439. if fromZhu == toZhu:
  440. gn.fangxiangTip = ""
  441. elif fromZhu < toZhu:
  442. gn.fangxiangTip = "→"
  443. elif fromZhu > toZhu:
  444. gn.fangxiangTip = "←"
  445. elif gn.guanxi in ["冲", "穿"]:
  446. if selfZhu == gn.zhu1:
  447. if gn.power1 < gn.power2:
  448. gn.fangxiangTip = "↓"
  449. elif gn.power1 > gn.power2:
  450. gn.fangxiangTip = "↑"
  451. else:
  452. gn.fangxiangTip = "="
  453. else:
  454. if gn.power1 < gn.power2:
  455. gn.fangxiangTip = "↑"
  456. elif gn.power1 > gn.power2:
  457. gn.fangxiangTip = "↓"
  458. else:
  459. gn.fangxiangTip = "="
  460. elif gn.guanxi == "拱合":
  461. gn.fangxiangTip = "(" + gn.fangxiang + ")"
  462. def fix_gaoneng_by_text(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, dc: DataCenter):
  463. result: [GaoNeng] = []
  464. tg = Common.is_tiangan(text)
  465. if tg is True:
  466. __fix_gaoneng_for_two(text, zhus, bazi, weizhi, result, dc)
  467. else:
  468. __fix_gaoneng_for_three(text, zhus, bazi, weizhi, result, dc)
  469. __fix_gaoneng_for_two(text, zhus, bazi, weizhi, result, dc)
  470. return result
  471. def __fix_gaoneng_for_two(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, list: [GaoNeng], dc: DataCenter):
  472. for sz in zhus:
  473. data = Common.find_gaoneng_by_texts(text, sz.text)
  474. for dt in data:
  475. gn = __build_gaoneng_object_from_data_as_text(dt, text, sz, None, bazi, dc, False)
  476. if __has_key_in_gaoneng_list(gn, list) is False:
  477. list.append(gn)
  478. def __fix_gaoneng_for_three(text: str, zhus: [SiZhu], bazi: BaZi, weizhi: int, list: [GaoNeng], dc: DataCenter):
  479. for sz2 in zhus:
  480. for sz3 in zhus:
  481. if sz2.weiZhi == sz3.weiZhi:
  482. continue
  483. data = Common.find_gaoneng_by_texts(text, sz2.text, sz3.text)
  484. for dt in data:
  485. gn = __build_gaoneng_object_from_data_as_text(dt, text, sz2, sz3, bazi, dc, False)
  486. if __has_key_in_gaoneng_list(gn, list) is False:
  487. list.append(gn)