import inspect import Configs from Configs import config_wuxing, config_canggan from model import Tiangan, Dizhi, Shishen, GaonengMid tiangan_ary = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"] dizhi_ary = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] wuxing_ary = ["木", "火", "土", "金", "水"] shishen_ary = ["官", "杀", "比", "劫", "食", "伤", "印", "枭", "财", "才"] muku_ary = ["辰", "戌", "丑", "未"] tongdang_ary = ["印", "枭", "比", "劫"] yidang_ary = ["官", "杀", "财", "才"] def custom_print(*args, **kwargs): # 获取当前的栈帧 current_frame = inspect.currentframe() # 获取上一级栈帧,因为当前栈帧是在 custom_print 内部 caller_frame = inspect.getouterframes(current_frame)[1] # 获取调用者信息 frame_info = inspect.getframeinfo(caller_frame[0]) # 构建包含文件名和行号的信息 file_line_info = f"{frame_info.filename}:{frame_info.lineno}" # 打印带有文件和行号信息的原始打印信息 print(file_line_info) print(*args, **kwargs) def get_wuxing(text: str): if text is None: return None return config_wuxing[text] def get_yinyang(text: str): try: return Configs.config_yinyang[text] except KeyError: return None def get_shishen(text: str, riyuan: str): try: return Configs.config_shishen[riyuan][text] except KeyError: return None def get_canggans(text: str): if text is None: return [None, None, None] return config_canggan[text] def get_zhangsheng(tiangan: str, dizhi: str): try: return Configs.config_zhangsheng[tiangan][dizhi] except KeyError: return None def get_weizhi_of_zhu(wz: int): try: return Configs.config_zhu[wz] except KeyError: return 0 def get_wuxing_shishen_guanxi(wuxing: str): try: return Configs.config_wuxing_shishen_guanxi[wuxing] except KeyError: return None def get_muku_info(text: str): try: return Configs.config_muku[text] except KeyError: return None def get_wangshuai(wuxing: str): return Configs.congfig_wangshuai[wuxing] def get_xingge(wuxing: str): return Configs.config_xingge[wuxing] def get_lushen_tip(key: str): return Configs.config_lushen_tip[key] def has_genqi(tianganWuXing: str, dizhiWuXing: str): cfg = Configs.config_genqi[tianganWuXing] result = False if dizhiWuXing in cfg['真']: result = True return result def get_zhenjia(shishen: str): return Configs.config_zhenjia[shishen] def find_gaoneng_by_texts(text1: str, text2: str, text3: str = None): if text3 is None: text3 = "" try: return Configs.config_gaoneng_query[text1 + text2 + text3] except KeyError: return [] # 处理甲合什么,冲什么这类查询逻辑 def find_gaoneng_by_key_and_guanxi(key: str, guanxi: str): result = [] try: lst = Configs.config_gaoneng_key[key] for dt in lst: if dt["guanxi"] == guanxi: result.append(dt) except KeyError: return result return result def get_other_arg_in_gaoneng(selfText: str, guanxi: str, gaonengText: str): result = None key = selfText + guanxi for s in gaonengText: if not s in key: result = s break return result def get_tiangan_by_dizhi(dizhi: str): if dizhi == "子": return "癸" if dizhi == "丑": return "己" if dizhi == "寅": return "甲" if dizhi == "卯": return "乙" if dizhi == "辰": return "戊" if dizhi == "巳": return "丙" if dizhi == "午": return "丁" if dizhi == "未": return "己" if dizhi == "申": return "庚" if dizhi == "酉": return "辛" if dizhi == "戌": return "戊" if dizhi == "亥": return "壬" return None # 查询和日元形成指定食神关系的天干地支 def find_tiangan_dizhi_by_shishenguanxi(riyuan: str, jiancheng: str): result = [] dts = Shishen.select().where(Shishen.wo == riyuan, Shishen.jiancheng == jiancheng) if len(dts) > 0: result.append(dts[0].ta) dzs = Dizhi.select().where(Dizhi.gan1 == dts[0].ta) for dz in dzs: result.append(dz.name) return result # 根据指定的arg1,指定的关系,指定的类别,查找符合条件的高能关系 def find_gaoneng_by_arg_guanxi_leibie(arg: str, guanxi: str, leibie: str): dts = GaonengMid.select().where(GaonengMid.arg1 == arg, GaonengMid.guanxi == guanxi, GaonengMid.leibie == leibie) if len(dts) > 0: return dts return [] def get_lushen(riyuan: str): result = None dts = Tiangan.select().where(Tiangan.name == riyuan) if len(dts) > 0: result = dts[0].lushen return result def is_lushen(text: str, riyuan: str): result = False if text in dizhi_ary: data = Configs.config_lushen[riyuan] if text == data["禄神"]: result = True return result def is_banlu(text: str, riyuan: str): result = False if text in dizhi_ary: data = Configs.config_lushen[riyuan] if text in data["半禄"]: result = True return result def get_banlu(riyuan: str): data = Configs.config_lushen[riyuan] return data["半禄"] def get_xiongji(key: str): return Configs.config_xiongji[key] def is_tiangan(text: str): return text in tiangan_ary # 用来查询简单的,只有2个参数的高能关系 def queryGaoNengGuanXi(arg1: str, arg2: str, arg3: str, guanxi: str): dt = GaonengMid.select().where(GaonengMid.arg1 == arg1, GaonengMid.arg2 == arg2, GaonengMid.arg3 == arg3, GaonengMid.guanxi == guanxi).first() return dt # 传入总共多少个藏干,以及当前藏干的index def calcCangGanPower(cangGanAmount: int, cangGanIndex: int, isMuKu: bool): power = 0 if cangGanAmount == 1: power = 1 elif cangGanAmount == 2: power = 0.5 elif cangGanAmount == 3: if not isMuKu: if cangGanIndex == 0: power = 0.6 elif cangGanIndex == 1: power = 0.3 elif cangGanIndex == 2: power = 0.1 else: # 墓库在藏干在数据库中,墓气是第一个,所以要调整下 if cangGanIndex == 0: power = 0.1 elif cangGanIndex == 1: power = 0.6 elif cangGanIndex == 2: power = 0.3 return power def __find_index_in_list(list: [], target: object): try: return list.index(target) except ValueError: return -1 def get_max_day(year: int, month: int): if month in [1, 3, 5, 7, 8, 10, 12]: return 31 if month in [4, 6, 9, 11]: return 30 if month == 2: if year % 4 == 0: return 29 else: return 28 return 0