import Common from LocalModel import BaZi, SiZhuWeiZhi, LiuZhu, ContentGaoNeng, ContentInfo from model import Wannianli, GaonengMid, ShishenJiedu, LuckyDay def createContent(bazi: BaZi): return year = 2024 month = 5 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") LuckyDay.insert_many(total).execute() print("save content over") def __create_contents_by_date(year: int, month: int, day: int): infoList: [ContentInfo] = [] dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).first() 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 = 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.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 = GaonengMid.select().where(GaonengMid.arg1 == chong1, GaonengMid.arg2 == chong2, GaonengMid.guanxi == "冲").first() 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 = 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 = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.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 = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu2.text, GaonengMid.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 = GaonengMid.select().where(GaonengMid.arg1 == key, GaonengMid.arg2 == zhu.text, GaonengMid.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 = GaonengMid.select().where(GaonengMid.arg1 == riyuan, GaonengMid.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: GaonengMid, 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