logic.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. from DBTools import DBWanNianLi
  2. from tools import *
  3. from yixue import *
  4. def get_last_day_info(year: int):
  5. dt = DBWanNianLi.query_first_by(nian=year, yue=12, ri=31)
  6. if dt is not None:
  7. if dt.ri_gan == "":
  8. return None
  9. else:
  10. return dt
  11. else:
  12. return None
  13. def _do_update_ri_by_year(year: int, start_rigan: str, start_rizhi: str):
  14. pass
  15. # last_rigan = start_rigan
  16. # last_rizhi = start_rizhi
  17. # for month in range(1, 13):
  18. # max_day = get_max_day(year, month)
  19. # print("处理", year, month, "月数据")
  20. # for day in range(1, max_day + 1):
  21. # if month == 1 and day == 1:
  22. # rigan = last_rigan
  23. # rizhi = last_rizhi
  24. # else:
  25. # rigan = next_tiangan(last_rigan)
  26. # rizhi = next_dizhi(last_rizhi)
  27. # last_rigan = rigan
  28. # last_rizhi = rizhi
  29. # Wannianli.update({
  30. # "ri_gan": rigan,
  31. # "ri_zhi": rizhi,
  32. # }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
  33. # print("update over last:", last_rigan, last_rizhi)
  34. def update_ri_by_year(year: int):
  35. start = DBWanNianLi.query_by(nian=year, yue=1, ri=1)
  36. start_data = start[0]
  37. if start_data.ri_gan == "":
  38. print(year, "1月1日未配置初始值,从上一年取得数据")
  39. last_year = get_last_day_info(year - 1)
  40. if last_year is not None:
  41. print("上一年最后一天是", last_year.ri_gan, last_year.ri_zhi)
  42. next_rigan = next_tiangan(last_year.ri_gan)
  43. next_rizhi = next_dizhi(last_year.ri_zhi)
  44. print("新年第一天的开始是", next_rigan, next_rizhi)
  45. _do_update_ri_by_year(year, next_rigan, next_rizhi)
  46. else:
  47. print("上一年也没数据")
  48. else:
  49. _do_update_ri_by_year(year, start_data.ri_gan, start_data.ri_zhi)
  50. def get_wannianli_data(year: int, month: int, day: int):
  51. return None
  52. # dt = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day)
  53. # if len(dt) > 0:
  54. # return dt[0]
  55. # else:
  56. # print(year, month, day, "has empty data")
  57. # return None
  58. # def get_jieqi_of_month(jieqi: WannianliJieqi, month: int):
  59. # ary = [jieqi.xiaohan, jieqi.lichun, jieqi.jingzhe, jieqi.qingming, jieqi.lixia,
  60. # jieqi.mangzhong, jieqi.xiaoshu, jieqi.liqiu, jieqi.bailu, jieqi.hanlu,
  61. # jieqi.lidong, jieqi.daxue]
  62. # return ary[month - 1]
  63. def _do_update_yue_by_year(year: int, month: int, start_yuegan: str, start_yuezhi: str):
  64. pass
  65. # jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
  66. # jieqi_day = get_jieqi_of_month(jieqi[0], month)
  67. # print("处理", year, month, "月数据, 节气日期是:", jieqi_day)
  68. # key_day = str(jieqi_day).split(".")[1]
  69. # max_day = get_max_day(year, month)
  70. # for day in range(1, max_day + 1):
  71. # if day < int(key_day):
  72. # yuegan = start_yuegan
  73. # yuezhi = start_yuezhi
  74. # else:
  75. # yuegan = next_tiangan(start_yuegan)
  76. # yuezhi = next_dizhi(start_yuezhi)
  77. # # print(year, month, day, yuegan, yuezhi)
  78. # Wannianli.update({
  79. # "yue_gan": yuegan,
  80. # "yue_zhi": yuezhi,
  81. # }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
  82. # print("update month over ", year, month)
  83. def prepare_yue_data(year: int, month: int):
  84. if month == 1:
  85. print(year, month, "月份未配置初始值,从上年12月取得数据")
  86. last_month = get_wannianli_data(year - 1, 12, 31)
  87. else:
  88. print(year, month, "月份未配置初始值,从当年上个月取得数据")
  89. max_day = get_max_day(year, month - 1)
  90. last_month = get_wannianli_data(year, month - 1, max_day)
  91. if last_month.yue_gan == "":
  92. print("未取得合适的数据", year, month, ",请检查上年12月或本年上个月的数据是否已录入")
  93. return False
  94. else:
  95. # _do_update_yue_by_year(year, month, last_month.yue_gan, last_month.yue_zhi)
  96. return True
  97. def update_yue_by_year(year: int):
  98. pass
  99. # for month in range(1, 13):
  100. # start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == 1)
  101. # start_data = start[0]
  102. # if start_data.yue_gan == "":
  103. # if not prepare_yue_data(year, month):
  104. # break
  105. # else:
  106. # if year == 1901 and month == 1:
  107. # _do_update_yue_by_year(year, month, start_data.yue_gan, start_data.yue_zhi)
  108. # else:
  109. # if not prepare_yue_data(year, month):
  110. # break
  111. def _do_update_nian_by_year(year: int, start_niangan: str, start_nianzhi: str):
  112. pass
  113. # jieqi = WannianliJieqi.select().where(WannianliJieqi.nianfen == year)
  114. # jieqi_key = str(jieqi[0].chuxi).split(".")
  115. # jieqi_month = int(jieqi_key[0])
  116. # jieqi_day = int(jieqi_key[1])
  117. # for month in range(1, 13):
  118. # max_day = get_max_day(year, month)
  119. # for day in range(1, max_day + 1):
  120. # niangan = ""
  121. # nianzhi = ""
  122. # if month < jieqi_month:
  123. # niangan = start_niangan
  124. # nianzhi = start_nianzhi
  125. # elif month == jieqi_month:
  126. # if day > jieqi_day:
  127. # niangan = next_tiangan(start_niangan)
  128. # nianzhi = next_dizhi(start_nianzhi)
  129. # else:
  130. # niangan = start_niangan
  131. # nianzhi = start_nianzhi
  132. # elif month > jieqi_month:
  133. # niangan = next_tiangan(start_niangan)
  134. # nianzhi = next_dizhi(start_nianzhi)
  135. # Wannianli.update({
  136. # "nian_gan": niangan,
  137. # "nian_zhi": nianzhi,
  138. # }).where(Wannianli.nian == year, Wannianli.yue == month, Wannianli.ri == day).execute()
  139. # print(year, month, "年数据更新完成")
  140. def update_nian_by_year(year: int):
  141. pass
  142. # start = Wannianli.select().where(Wannianli.nian == year, Wannianli.yue == 1, Wannianli.ri == 1)
  143. # start_data = start[0]
  144. # if start_data.nian_gan == "":
  145. # print("没有1月1日数据,从上一年取数")
  146. # last_year = get_wannianli_data(year - 1, 12, 31)
  147. # if last_year is not None:
  148. # _do_update_nian_by_year(year, last_year.nian_gan, last_year.nian_zhi)
  149. # else:
  150. # _do_update_nian_by_year(year, start_data.nian_gan, start_data.nian_zhi)
  151. def get_hour_of_day(day_tiangan: str, hour: int):
  152. start_tiangan = get_tiangan_start_of_hour(day_tiangan)
  153. tiangan = get_tiangan_by_hour(start_tiangan, hour)
  154. dizhi = get_dizhi_by_hour(hour)
  155. return [tiangan, dizhi]