123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- import Common
- from DBTools import DBWanNianLi, DBShiShenJieDu, DBGaoNeng
- from LocalModel import SiZhuWeiZhi, LiuZhu, ContentGaoNeng, ContentInfo
- def createContent():
- return
- year = 2024
- month = 6
- maxDay = Common.get_max_day(year, month)
- total = []
- for day in range(1, maxDay + 1):
- results = __create_contents_by_date(year, month, day)
- for info in results:
- # print(info.riyuan, info.text, info.fromCangGan, info.fromGongHe, info.fromXing)
- total.append(info.to_db_data())
- print("calc content over")
- # 操作前把luck day 这个表格清空
- DBLuckDay.delete_by()
- DBLuckDay.insert_all(total)
- print("save content over")
- def __create_contents_by_date(year: int, month: int, day: int):
- infoList: [ContentInfo] = []
- dt = DBWanNianLi.query_first_by(nian=year, yue=month, ri=day)
- if dt is not None:
- for riyuan in Common.tiangan_ary:
- # print(month, day, riyuan)
- zhu0 = __build_zhu(riyuan, SiZhuWeiZhi.rigan.value, riyuan)
- zhu1 = __build_zhu(dt.nian_gan, SiZhuWeiZhi.liu_niangan.value, riyuan)
- zhu2 = __build_zhu(dt.yue_gan, SiZhuWeiZhi.liu_yuegan.value, riyuan)
- zhu3 = __build_zhu(dt.ri_gan, SiZhuWeiZhi.liu_rigan.value, riyuan)
- zhu11 = __build_zhu(dt.nian_zhi, SiZhuWeiZhi.liu_nianzhi.value, riyuan)
- zhu12 = __build_zhu(dt.yue_zhi, SiZhuWeiZhi.liu_yuezhi.value, riyuan)
- zhu13 = __build_zhu(dt.ri_zhi, SiZhuWeiZhi.liu_rizhi.value, riyuan)
- tgZhus = [zhu1, zhu2, zhu0]
- dzZhus = [zhu11, zhu12]
- lst: [ContentGaoNeng] = []
- __calc_tiangan_gaonengs(zhu3.text, tgZhus, riyuan, lst)
- __calc_dizhi_gaonengs(zhu13.text, dzZhus, riyuan, lst)
- __calc_canggan_gaonengs(riyuan, [zhu13], lst)
- __calc_gonghe_data(lst, [zhu0, zhu1, zhu2, zhu3], riyuan)
- __calc_xing_data(lst, [zhu0, zhu1, zhu2, zhu3], riyuan)
- __build_info(lst, year, month, day, riyuan, infoList)
- return infoList
- def __calc_gonghe_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
- for item in lst:
- if item.guanxi == "拱合":
- tg = Common.get_tiangan_by_dizhi(item.fangxiang)
- for zhu in tgZhus:
- dt = DBGaoNeng.query_first_by(arg1=tg, arg2=zhu.text, arg3=None)
- if dt is not None:
- gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
- gn.fromGongHe = True
- lst.append(gn)
- def __calc_xing_data(lst: [ContentGaoNeng], tgZhus: [LiuZhu], riyuan: str):
- for item in lst:
- if item.guanxi == "刑":
- chong1 = ""
- chong2 = ""
- if item.text == "巳申刑":
- chong1 = "丙"
- chong2 = "壬"
- elif item.text == "寅巳刑":
- chong1 = "甲"
- chong2 = "庚"
- elif item.text == "戌未刑":
- chong1 = "乙"
- chong2 = "辛"
- elif item.text == "丑戌刑":
- chong1 = "丁"
- chong2 = "癸"
- dt = DBGaoNeng.query_first_by(arg1=chong1, arg2=chong2, guanxi="冲")
- if dt is not None:
- gn = __build_content_gaoneng(dt, riyuan, -1, -1, None)
- gn.fromXing = True
- lst.append(gn)
- # 刑出的高能关系在藏干中已经计算过了,所以这里不再计算
- # xingchus = __get_zengqiang_of_xing(item.text)
- # for tg in xingchus:
- # for zhu in tgZhus:
- # dt = GaonengMid.select().where(GaonengMid.arg1 == tg, GaonengMid.arg2 == zhu.text,
- # GaonengMid.arg3 == None).first()
- # if dt is not None:
- # gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
- # gn.fromXing = True
- # lst.append(gn)
- def __build_info(lst: [ContentGaoNeng], year: int, month: int, day: int, riyuan: str, infoList: [ContentInfo]):
- for item in lst:
- if __has_info(item.text, infoList) is True:
- continue
- info = ContentInfo()
- info.year = year
- info.month = month
- info.day = day
- info.riyuan = riyuan
- info.text = item.text
- info.tip = item.tip
- info.arg1 = item.arg1
- info.arg2 = item.arg2
- info.arg3 = item.arg3
- info.shishen1 = item.shishen1
- info.shishen2 = item.shishen2
- info.shishen3 = item.shishen3
- info.guanxi = item.guanxi
- info.times = __count_gaoneng_in_list(info.text, lst)
- info.fromCangGan = item.fromCangGan
- info.fromGongHe = item.fromGongHe
- info.fromXing = item.fromXing
- info.fangxiang = item.fangxiang
- infoList.append(info)
- for item in infoList:
- __fill_jiedu(item)
- def __fill_jiedu(info: ContentInfo):
- if info.text == "辰辰自刑":
- info.jiedu1 = "容易庸人自扰"
- info.jiedu2 = "自我纠结,想不通"
- info.jiedu3 = "容易进入哲学思维模式"
- elif info.text == "午午自刑":
- info.jiedu1 = "容易空想,产生自我心理幻想"
- info.jiedu2 = "容易无中生有,又以此与人吵架"
- info.jiedu3 = "容易找人吐槽个没完没了"
- elif info.text == "亥亥自刑":
- info.jiedu1 = "容易顾虑太多"
- info.jiedu2 = "容易选择困难"
- elif info.text == "酉酉自刑":
- info.jiedu1 = "容易神神叨叨"
- info.jiedu2 = "容易为金钱烦恼"
- info.jiedu3 = "容易与人抬杠"
- elif info.guanxi in ["半合", "三会", "拱合"]:
- __fill_jiedu_by_shishen_zengqiang(info, Common.get_shishen(info.fangxiang, info.riyuan))
- elif info.guanxi == "刑":
- zengqiangList = __get_zengqiang_of_xing(info.text)
- for zq in zengqiangList:
- __fill_jiedu_by_shishen_zengqiang(info, Common.get_shishen(zq, info.riyuan))
- elif info.text in ["辰戌冲", "丑未冲"]:
- i = 1
- elif info.guanxi in ["三合"]:
- i = 1
- else:
- guanxi = info.guanxi
- if guanxi == "暗合":
- guanxi = "合"
- jd = DBShiShenJieDu.query_first_by(arg1=info.shishen1, arg2=info.shishen2, guanxi=guanxi)
- # jd = ShishenJiedu.select().where(ShishenJiedu.arg1 == info.shishen1,
- # ShishenJiedu.arg2 == info.shishen2,
- # ShishenJiedu.guanxi == guanxi).first()
- if jd is not None:
- info.jiedu1 = jd.tip1
- info.jiedu2 = jd.tip2
- info.jiedu3 = jd.tip3
- info.jiedu4 = jd.tip4
- info.jiedu5 = jd.tip5
- else:
- print(info.riyuan, info.shishen1, info.shishen2, info.guanxi, info.text, info.year, info.month, info.day,
- " 未收录")
- def __get_zengqiang_of_xing(text: str):
- result = []
- if text == "巳申刑":
- result.append("戊")
- result.append("庚")
- elif text == "寅巳刑":
- result.append("丙")
- result.append("戊")
- elif text == "戌未刑":
- result.append("丁")
- elif text == "丑戌刑":
- result.append("辛")
- return result
- def __fill_jiedu_by_shishen_zengqiang(item: ContentInfo, zengqiang: str):
- if zengqiang in ["官", "杀"]:
- item.jiedu1 = "跟机会相关的事情发生变动"
- elif zengqiang in ["财", "才"]:
- item.jiedu1 = "跟财富相关的事情发生变动"
- elif zengqiang in ["印", "枭"]:
- item.jiedu1 = "跟事业相关的事情发生变动"
- elif zengqiang in ["食", "伤"]:
- item.jiedu1 = "跟自我行动或思考相关的事情发生变动"
- elif zengqiang in ["比", "劫"]:
- item.jiedu1 = "跟朋友、圈子相关的事情发生变动"
- def __has_info(text: str, lst: [ContentInfo]):
- result = False
- for info in lst:
- if info.text == text:
- result = True
- break
- return result
- def __count_gaoneng_in_list(text: str, lst: [ContentGaoNeng]):
- ct = 0
- for gn in lst:
- if gn.text == text:
- ct += 1
- return ct
- def __build_zhu(text: str, weizhi: int, riyuan: str):
- zhu = LiuZhu()
- zhu.text = text
- zhu.weizhi = weizhi
- zhu.shishen = Common.get_shishen(text, riyuan)
- zhu.isTianGan = Common.is_tiangan(text)
- if not zhu.isTianGan:
- gans = Common.get_canggans(text)
- zhu.gan1 = gans[0]
- zhu.gan2 = gans[1]
- zhu.gan3 = gans[2]
- zhu.gan1ShiShen = Common.get_shishen(zhu.gan1, riyuan)
- zhu.gan2ShiShen = Common.get_shishen(zhu.gan2, riyuan)
- zhu.gan3ShiShen = Common.get_shishen(zhu.gan3, riyuan)
- return zhu
- def __calc_tiangan_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGaoNeng]):
- for zhu in zhus:
- dts = DBGaoNeng.query_by(arg1=key, arg2=zhu.text)
- if len(dts) > 0:
- for dt in dts:
- gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
- lst.append(gn)
- def __calc_dizhi_gaonengs(key: str, zhus: [LiuZhu], riyuan: str, lst: [ContentGaoNeng]):
- for zhu2 in zhus:
- for zhu3 in zhus:
- if zhu2.weizhi == zhu3.weizhi:
- continue
- dts = DBGaoNeng.query_by(arg1=key, arg2=zhu2.text, arg3=zhu3.text)
- if len(dts) > 0:
- for dt in dts:
- gn = __build_content_gaoneng(dt, riyuan, -1, zhu2.weizhi, zhu3.weizhi)
- lst.append(gn)
- for zhu in zhus:
- dts = DBGaoNeng.query_by(arg1=key, arg2=zhu.text, arg3=None)
- if len(dts) > 0:
- for dt in dts:
- gn = __build_content_gaoneng(dt, riyuan, -1, zhu.weizhi, None)
- lst.append(gn)
- def __calc_canggan_gaonengs(riyuan: str, zhus: [LiuZhu], lst: [ContentGaoNeng]):
- for zhu in zhus:
- gans = Common.get_canggans(zhu.text)
- for gan in gans:
- if gan is None:
- continue
- dts = DBGaoNeng.query_by(arg1=riyuan, arg2=gan)
- if len(dts) > 0:
- for dt in dts:
- gn = __build_content_gaoneng(dt, riyuan, SiZhuWeiZhi.rigan.value, zhu.weizhi, None)
- gn.fromCangGan = True
- lst.append(gn)
- def __build_content_gaoneng(dt: DBGaoNeng, riyuan: str, zhu1: int, zhu2: int, zhu3: int):
- gn = ContentGaoNeng()
- gn.text = dt.desc
- gn.arg1 = dt.arg1
- gn.arg2 = dt.arg2
- gn.arg3 = dt.arg3
- gn.guanxi = dt.guanxi
- gn.shishen1 = Common.get_shishen(gn.arg1, riyuan)
- gn.shishen2 = Common.get_shishen(gn.arg2, riyuan)
- gn.shishen3 = Common.get_shishen(gn.arg3, riyuan)
- gn.zhu1 = zhu1
- gn.zhu2 = zhu2
- gn.zhu3 = zhu3
- gn.key = __calc_key_of_gaoneng_data(zhu1, zhu2, zhu3, gn.text)
- gn.tip = dt.tip
- gn.fangxiang = dt.fangxiang
- return gn
- def __calc_key_of_gaoneng_data(zhu1: int, zhu2: int, zhu3: int, text: str):
- lst = [zhu1, zhu2]
- if zhu3 is not None:
- lst.append(zhu3)
- lst.sort()
- key = text
- for v in lst:
- key += str(v)
- return key
|