ContentLogic.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import Common
  2. from LocalModel import BaZi, SiZhuWeiZhi, LiuZhu, ContentGaoNeng, ContentInfo
  3. from model import Wannianli, GaonengMid, ShishenJiedu, LuckyDay
  4. def createContent(bazi: BaZi):
  5. return
  6. year = 2024
  7. month = 5
  8. maxDay = Common.get_max_day(year, month)
  9. total = []
  10. for day in range(1, maxDay + 1):
  11. results = __create_contents_by_date(year, month, day)
  12. for info in results:
  13. # print(info.riyuan, info.text, info.fromCangGan, info.fromGongHe, info.fromXing)
  14. total.append(info.to_db_data())
  15. print("calc content over")
  16. LuckyDay.insert_many(total).execute()
  17. print("save content over")
  18. def __create_contents_by_date(year: int, month: int, day: int):
  19. infoList: [ContentInfo] = []
  20. dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).first()
  21. if dt is not None:
  22. for riyuan in Common.tiangan_ary:
  23. # print(month, day, riyuan)
  24. zhu0 = __build_zhu(riyuan, SiZhuWeiZhi.rigan.value, riyuan)
  25. zhu1 = __build_zhu(dt.nian_gan, SiZhuWeiZhi.liu_niangan.value, riyuan)
  26. zhu2 = __build_zhu(dt.yue_gan, SiZhuWeiZhi.liu_yuegan.value, riyuan)
  27. zhu3 = __build_zhu(dt.ri_gan, SiZhuWeiZhi.liu_rigan.value, riyuan)
  28. zhu11 = __build_zhu(dt.nian_zhi, SiZhuWeiZhi.liu_nianzhi.value, riyuan)
  29. zhu12 = __build_zhu(dt.yue_zhi, SiZhuWeiZhi.liu_yuezhi.value, riyuan)
  30. zhu13 = __build_zhu(dt.ri_zhi, SiZhuWeiZhi.liu_rizhi.value, riyuan)
  31. tgZhus = [zhu1, zhu2, zhu0]
  32. dzZhus = [zhu11, zhu12]
  33. lst: [ContentGaoNeng] = []
  34. __calc_tiangan_gaonengs(zhu3.text, tgZhus, riyuan, lst)
  35. __calc_dizhi_gaonengs(zhu13.text, dzZhus, riyuan, lst)
  36. __calc_canggan_gaonengs(riyuan, [zhu13], lst)
  37. __calc_gonghe_data(lst, [zhu0, zhu1, zhu2, zhu3], riyuan)
  38. __calc_xing_data(lst, [zhu0, zhu1, zhu2, zhu3], riyuan)
  39. __build_info(lst, year, month, day, riyuan, infoList)
  40. return infoList
  41. def __calc_gonghe_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
  42. for item in lst:
  43. if item.guanxi == "拱合":
  44. tg = Common.get_tiangan_by_dizhi(item.fangxiang)
  45. for zhu in tgZhus:
  46. dt = GaonengMid.select().where(GaonengMid.arg1 == tg, GaonengMid.arg2 == zhu.text,
  47. GaonengMid.arg3 == None).first()
  48. if dt is not None:
  49. gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
  50. gn.fromGongHe = True
  51. lst.append(gn)
  52. def __calc_xing_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
  53. for item in lst:
  54. if item.guanxi == "刑":
  55. chong1 = ""
  56. chong2 = ""
  57. if item.text == "巳申刑":
  58. chong1 = "丙"
  59. chong2 = "壬"
  60. elif item.text == "寅巳刑":
  61. chong1 = "甲"
  62. chong2 = "庚"
  63. elif item.text == "戌未刑":
  64. chong1 = "乙"
  65. chong2 = "辛"
  66. elif item.text == "丑戌刑":
  67. chong1 = "丁"
  68. chong2 = "癸"
  69. dt = GaonengMid.select().where(GaonengMid.arg1 == chong1, GaonengMid.arg2 == chong2,
  70. GaonengMid.guanxi == "冲").first()
  71. if dt is not None:
  72. gn = __build_content_gaoneng(dt, riyuan, -1, -1, None)
  73. gn.fromXing = True
  74. lst.append(gn)
  75. # 刑出的高能关系在藏干中已经计算过了,所以这里不再计算
  76. # xingchus = __get_zengqiang_of_xing(item.text)
  77. # for tg in xingchus:
  78. # for zhu in tgZhus:
  79. # dt = GaonengMid.select().where(GaonengMid.arg1 == tg, GaonengMid.arg2 == zhu.text,
  80. # GaonengMid.arg3 == None).first()
  81. # if dt is not None:
  82. # gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
  83. # gn.fromXing = True
  84. # lst.append(gn)
  85. def __build_info(lst: [ContentGaoNeng], year: int, month: int, day: int, riyuan: str, infoList: [ContentInfo]):
  86. for item in lst:
  87. if __has_info(item.text, infoList) is True:
  88. continue
  89. info = ContentInfo()
  90. info.year = year
  91. info.month = month
  92. info.day = day
  93. info.riyuan = riyuan
  94. info.text = item.text
  95. info.tip = item.tip
  96. info.arg1 = item.arg1
  97. info.arg2 = item.arg2
  98. info.arg3 = item.arg3
  99. info.shishen1 = item.shishen1
  100. info.shishen2 = item.shishen2
  101. info.shishen3 = item.shishen3
  102. info.guanxi = item.guanxi
  103. info.times = __count_gaoneng_in_list(info.text, lst)
  104. info.fromCangGan = item.fromCangGan
  105. info.fromGongHe = item.fromGongHe
  106. info.fromXing = item.fromXing
  107. info.fangxiang = item.fangxiang
  108. infoList.append(info)
  109. for item in infoList:
  110. __fill_jiedu(item)
  111. def __fill_jiedu(info: ContentInfo):
  112. if info.text == "辰辰自刑":
  113. info.jiedu1 = "容易庸人自扰"
  114. info.jiedu2 = "自我纠结,想不通"
  115. info.jiedu3 = "容易进入哲学思维模式"
  116. elif info.text == "午午自刑":
  117. info.jiedu1 = "容易空想,产生自我心理幻想"
  118. info.jiedu2 = "容易无中生有,又以此与人吵架"
  119. info.jiedu3 = "容易找人吐槽个没完没了"
  120. elif info.text == "亥亥自刑":
  121. info.jiedu1 = "容易顾虑太多"
  122. info.jiedu2 = "容易选择困难"
  123. elif info.text == "酉酉自刑":
  124. info.jiedu1 = "容易神神叨叨"
  125. info.jiedu2 = "容易为金钱烦恼"
  126. info.jiedu3 = "容易与人抬杠"
  127. elif info.guanxi in ["半合", "三会", "拱合"]:
  128. __fill_jiedu_by_shishen_zengqiang(info, Common.get_shishen(info.fangxiang, info.riyuan))
  129. elif info.guanxi == "刑":
  130. zengqiangList = __get_zengqiang_of_xing(info.text)
  131. for zq in zengqiangList:
  132. __fill_jiedu_by_shishen_zengqiang(info, Common.get_shishen(zq, info.riyuan))
  133. elif info.text in ["辰戌冲", "丑未冲"]:
  134. i = 1
  135. elif info.guanxi in ["三合"]:
  136. i = 1
  137. else:
  138. guanxi = info.guanxi
  139. if guanxi == "暗合":
  140. guanxi = "合"
  141. jd = ShishenJiedu.select().where(ShishenJiedu.arg1 == info.shishen1,
  142. ShishenJiedu.arg2 == info.shishen2,
  143. ShishenJiedu.guanxi == guanxi).first()
  144. if jd is not None:
  145. info.jiedu1 = jd.tip1
  146. info.jiedu2 = jd.tip2
  147. info.jiedu3 = jd.tip3
  148. info.jiedu4 = jd.tip4
  149. info.jiedu5 = jd.tip5
  150. else:
  151. print(info.riyuan, info.shishen1, info.shishen2, info.guanxi, info.text, info.year, info.month, info.day,
  152. " 未收录")
  153. def __get_zengqiang_of_xing(text: str):
  154. result = []
  155. if text == "巳申刑":
  156. result.append("戊")
  157. result.append("庚")
  158. elif text == "寅巳刑":
  159. result.append("丙")
  160. result.append("戊")
  161. elif text == "戌未刑":
  162. result.append("丁")
  163. elif text == "丑戌刑":
  164. result.append("辛")
  165. return result
  166. def __fill_jiedu_by_shishen_zengqiang(item: ContentInfo, zengqiang: str):
  167. if zengqiang in ["官", "杀"]:
  168. item.jiedu1 = "跟机会相关的事情发生变动"
  169. elif zengqiang in ["财", "才"]:
  170. item.jiedu1 = "跟财富相关的事情发生变动"
  171. elif zengqiang in ["印", "枭"]:
  172. item.jiedu1 = "跟事业相关的事情发生变动"
  173. elif zengqiang in ["食", "伤"]:
  174. item.jiedu1 = "跟自我行动或思考相关的事情发生变动"
  175. elif zengqiang in ["比", "劫"]:
  176. item.jiedu1 = "跟朋友、圈子相关的事情发生变动"
  177. def __has_info(text: str, lst: [ContentInfo]):
  178. result = False
  179. for info in lst:
  180. if info.text == text:
  181. result = True
  182. break
  183. return result
  184. def __count_gaoneng_in_list(text: str, lst: [ContentGaoNeng]):
  185. ct = 0
  186. for gn in lst:
  187. if gn.text == text:
  188. ct += 1
  189. return ct
  190. def __build_zhu(text: str, weizhi: int, riyuan: str):
  191. zhu = LiuZhu()
  192. zhu.text = text
  193. zhu.weizhi = weizhi
  194. zhu.shishen = Common.get_shishen(text, riyuan)
  195. zhu.isTianGan = Common.is_tiangan(text)
  196. if not zhu.isTianGan:
  197. gans = Common.get_canggans(text)
  198. zhu.gan1 = gans[0]
  199. zhu.gan2 = gans[1]
  200. zhu.gan3 = gans[2]
  201. zhu.gan1ShiShen = Common.get_shishen(zhu.gan1, riyuan)
  202. zhu.gan2ShiShen = Common.get_shishen(zhu.gan2, riyuan)
  203. zhu.gan3ShiShen = Common.get_shishen(zhu.gan3, riyuan)
  204. return zhu
  205. def __calc_tiangan_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGaoNeng]):
  206. for zhu in zhus:
  207. dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu.text)
  208. if len(dts) > 0:
  209. for dt in dts:
  210. gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
  211. lst.append(gn)
  212. def __calc_dizhi_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGaoNeng]):
  213. for zhu2 in zhus:
  214. for zhu3 in zhus:
  215. if zhu2.weizhi == zhu3.weizhi:
  216. continue
  217. dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu2.text,
  218. GaonengMid.arg3 == zhu3.text)
  219. if len(dts) > 0:
  220. for dt in dts:
  221. gn = __build_content_gaoneng(dt, riyuan, -1, zhu2.weizhi, zhu3.weizhi)
  222. lst.append(gn)
  223. for zhu in zhus:
  224. dts = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu.text, GaonengMid.arg3 == None)
  225. if len(dts) > 0:
  226. for dt in dts:
  227. gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
  228. lst.append(gn)
  229. def __calc_canggan_gaonengs(riyuan: str, zhus: [LiuZhu], lst: [ContentGaoNeng]):
  230. for zhu in zhus:
  231. gans = Common.get_canggans(zhu.text)
  232. for gan in gans:
  233. if gan is None:
  234. continue
  235. dts = GaonengMid.select().where(GaonengMid.arg1 == riyuan, GaonengMid.arg2 == gan)
  236. if len(dts) > 0:
  237. for dt in dts:
  238. gn = __build_content_gaoneng(dt, riyuan, SiZhuWeiZhi.rigan.value, zhu.weizhi, None)
  239. gn.fromCangGan = True
  240. lst.append(gn)
  241. def __build_content_gaoneng(dt: GaonengMid, riyuan: str, zhu1: int, zhu2: int, zhu3: int):
  242. gn = ContentGaoNeng()
  243. gn.text = dt.desc
  244. gn.arg1 = dt.arg1
  245. gn.arg2 = dt.arg2
  246. gn.arg3 = dt.arg3
  247. gn.guanxi = dt.guanxi
  248. gn.shishen1 = Common.get_shishen(gn.arg1, riyuan)
  249. gn.shishen2 = Common.get_shishen(gn.arg2, riyuan)
  250. gn.shishen3 = Common.get_shishen(gn.arg3, riyuan)
  251. gn.zhu1 = zhu1
  252. gn.zhu2 = zhu2
  253. gn.zhu3 = zhu3
  254. gn.key = __calc_key_of_gaoneng_data(zhu1, zhu2, zhu3, gn.text)
  255. gn.tip = dt.tip
  256. gn.fangxiang = dt.fangxiang
  257. return gn
  258. def __calc_key_of_gaoneng_data(zhu1: int, zhu2: int, zhu3: int, text: str):
  259. lst = [zhu1, zhu2]
  260. if zhu3 is not None:
  261. lst.append(zhu3)
  262. lst.sort()
  263. key = text
  264. for v in lst:
  265. key += str(v)
  266. return key