Common.py 5.7 KB

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