Common.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import inspect
  2. import Configs
  3. from Configs import config_wuxing, config_canggan
  4. from model import Tiangan, Dizhi, Shishen, GaonengMid
  5. tiangan_ary = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
  6. dizhi_ary = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"]
  7. wuxing_ary = ["木", "火", "土", "金", "水"]
  8. shishen_ary = ["官", "杀", "比", "劫", "食", "伤", "印", "枭", "财", "才"]
  9. muku_ary = ["辰", "戌", "丑", "未"]
  10. tongdang_ary = ["印", "枭", "比", "劫"]
  11. yidang_ary = ["官", "杀", "财", "才"]
  12. def custom_print(*args, **kwargs):
  13. # 获取当前的栈帧
  14. current_frame = inspect.currentframe()
  15. # 获取上一级栈帧,因为当前栈帧是在 custom_print 内部
  16. caller_frame = inspect.getouterframes(current_frame)[1]
  17. # 获取调用者信息
  18. frame_info = inspect.getframeinfo(caller_frame[0])
  19. # 构建包含文件名和行号的信息
  20. file_line_info = f"{frame_info.filename}:{frame_info.lineno}"
  21. # 打印带有文件和行号信息的原始打印信息
  22. print(file_line_info)
  23. print(*args, **kwargs)
  24. def get_wuxing(text: str):
  25. if text is None:
  26. return None
  27. return config_wuxing[text]
  28. def get_yinyang(text: str):
  29. try:
  30. return Configs.config_yinyang[text]
  31. except KeyError:
  32. return None
  33. def get_shishen(text: str, riyuan: str):
  34. try:
  35. return Configs.config_shishen[riyuan][text]
  36. except KeyError:
  37. return None
  38. def get_canggans(text: str):
  39. if text is None:
  40. return [None, None, None]
  41. return config_canggan[text]
  42. def get_zhangsheng(tiangan: str, dizhi: str):
  43. try:
  44. return Configs.config_zhangsheng[tiangan][dizhi]
  45. except KeyError:
  46. return None
  47. def get_weizhi_of_zhu(wz: int):
  48. try:
  49. return Configs.config_zhu[wz]
  50. except KeyError:
  51. return 0
  52. def get_wuxing_shishen_guanxi(wuxing: str):
  53. try:
  54. return Configs.config_wuxing_shishen_guanxi[wuxing]
  55. except KeyError:
  56. return None
  57. def get_muku_info(text: str):
  58. try:
  59. return Configs.config_muku[text]
  60. except KeyError:
  61. return None
  62. def get_wangshuai(wuxing: str):
  63. return Configs.congfig_wangshuai[wuxing]
  64. def get_xingge(wuxing: str):
  65. return Configs.config_xingge[wuxing]
  66. def get_lushen_tip(key: str):
  67. return Configs.config_lushen_tip[key]
  68. def has_genqi(tianganWuXing: str, dizhiWuXing: str):
  69. cfg = Configs.config_genqi[tianganWuXing]
  70. result = False
  71. if dizhiWuXing in cfg['真']:
  72. result = True
  73. return result
  74. def get_zhenjia(shishen: str):
  75. return Configs.config_zhenjia[shishen]
  76. def find_gaoneng_by_texts(text1: str, text2: str, text3: str = None):
  77. if text3 is None:
  78. text3 = ""
  79. try:
  80. return Configs.config_gaoneng_query[text1 + text2 + text3]
  81. except KeyError:
  82. return []
  83. # 处理甲合什么,冲什么这类查询逻辑
  84. def find_gaoneng_by_key_and_guanxi(key: str, guanxi: str):
  85. result = []
  86. try:
  87. lst = Configs.config_gaoneng_key[key]
  88. for dt in lst:
  89. if dt["guanxi"] == guanxi:
  90. result.append(dt)
  91. except KeyError:
  92. return result
  93. return result
  94. def get_other_arg_in_gaoneng(selfText: str, guanxi: str, gaonengText: str):
  95. result = None
  96. key = selfText + guanxi
  97. for s in gaonengText:
  98. if not s in key:
  99. result = s
  100. break
  101. return result
  102. def get_tiangan_by_dizhi(dizhi: str):
  103. if dizhi == "子":
  104. return "癸"
  105. if dizhi == "丑":
  106. return "己"
  107. if dizhi == "寅":
  108. return "甲"
  109. if dizhi == "卯":
  110. return "乙"
  111. if dizhi == "辰":
  112. return "戊"
  113. if dizhi == "巳":
  114. return "丙"
  115. if dizhi == "午":
  116. return "丁"
  117. if dizhi == "未":
  118. return "己"
  119. if dizhi == "申":
  120. return "庚"
  121. if dizhi == "酉":
  122. return "辛"
  123. if dizhi == "戌":
  124. return "戊"
  125. if dizhi == "亥":
  126. return "壬"
  127. return None
  128. # 查询和日元形成指定食神关系的天干地支
  129. def find_tiangan_dizhi_by_shishenguanxi(riyuan: str, jiancheng: str):
  130. result = []
  131. dts = Shishen.select().where(Shishen.wo == riyuan, Shishen.jiancheng == jiancheng)
  132. if len(dts) > 0:
  133. result.append(dts[0].ta)
  134. dzs = Dizhi.select().where(Dizhi.gan1 == dts[0].ta)
  135. for dz in dzs:
  136. result.append(dz.name)
  137. return result
  138. # 根据指定的arg1,指定的关系,指定的类别,查找符合条件的高能关系
  139. def find_gaoneng_by_arg_guanxi_leibie(arg: str, guanxi: str, leibie: str):
  140. dts = GaonengMid.select().where(GaonengMid.arg1 == arg, GaonengMid.guanxi == guanxi,
  141. GaonengMid.leibie == leibie)
  142. if len(dts) > 0:
  143. return dts
  144. return []
  145. def get_lushen(riyuan: str):
  146. result = None
  147. dts = Tiangan.select().where(Tiangan.name == riyuan)
  148. if len(dts) > 0:
  149. result = dts[0].lushen
  150. return result
  151. def is_lushen(text: str, riyuan: str):
  152. result = False
  153. if text in dizhi_ary:
  154. data = Configs.config_lushen[riyuan]
  155. if text == data["禄神"]:
  156. result = True
  157. return result
  158. def is_banlu(text: str, riyuan: str):
  159. result = False
  160. if text in dizhi_ary:
  161. data = Configs.config_lushen[riyuan]
  162. if text in data["半禄"]:
  163. result = True
  164. return result
  165. def get_banlu(riyuan: str):
  166. data = Configs.config_lushen[riyuan]
  167. return data["半禄"]
  168. def get_xiongji(key: str):
  169. return Configs.config_xiongji[key]
  170. def is_tiangan(text: str):
  171. return text in tiangan_ary
  172. # 用来查询简单的,只有2个参数的高能关系
  173. def queryGaoNengGuanXi(arg1: str, arg2: str, arg3: str, guanxi: str):
  174. dt = GaonengMid.select().where(GaonengMid.arg1 == arg1, GaonengMid.arg2 == arg2, GaonengMid.arg3 == arg3,
  175. GaonengMid.guanxi == guanxi).first()
  176. return dt
  177. # 传入总共多少个藏干,以及当前藏干的index
  178. def calcCangGanPower(cangGanAmount: int, cangGanIndex: int, isMuKu: bool):
  179. power = 0
  180. if cangGanAmount == 1:
  181. power = 1
  182. elif cangGanAmount == 2:
  183. power = 0.5
  184. elif cangGanAmount == 3:
  185. if not isMuKu:
  186. if cangGanIndex == 0:
  187. power = 0.6
  188. elif cangGanIndex == 1:
  189. power = 0.3
  190. elif cangGanIndex == 2:
  191. power = 0.1
  192. else: # 墓库在藏干在数据库中,墓气是第一个,所以要调整下
  193. if cangGanIndex == 0:
  194. power = 0.1
  195. elif cangGanIndex == 1:
  196. power = 0.6
  197. elif cangGanIndex == 2:
  198. power = 0.3
  199. return power
  200. def __find_index_in_list(list: [], target: object):
  201. try:
  202. return list.index(target)
  203. except ValueError:
  204. return -1
  205. def get_max_day(year: int, month: int):
  206. if month in [1, 3, 5, 7, 8, 10, 12]:
  207. return 31
  208. if month in [4, 6, 9, 11]:
  209. return 30
  210. if month == 2:
  211. if year % 4 == 0:
  212. return 29
  213. else:
  214. return 28
  215. return 0