123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import math
- import time
- from datetime import datetime
- from time import mktime
- import FangAnLogic
- import GaoNengLogic
- import GeJuLogic
- import JianKangLogic
- import JieGouLogic
- import PowerLogic
- import ShenShaLogic
- import SiZhuLogic
- import SimpleLuckyDay
- import XingGeLogic
- import logic
- from DataCenter import DataCenter
- from LocalModel import BaZi, SiZhuInfoRequest
- from model import Wannianli, Taiyangpianyi
- # TODO 入口函数
- def fill_sizhu_in_bazi(bazi: BaZi, dc: DataCenter):
- # 四柱
- SiZhuLogic.fill_sizhu(bazi, dc)
- # 初步罗列高能关系(不计算力量对比,用来更新后续的墓库状态)
- dc.list_gaoneng()
- # 然后根据高能关系更新墓库状态
- dc.update_muku_state()
- # 然后可以开始更新五行十神力量分布了(涉及power计算,所以要先确定墓库状态)
- dc.update_counter()
- # 能量
- PowerLogic.calc_powers(bazi, dc)
- # 高能
- GaoNengLogic.check_gaoneng(bazi, dc)
- # 神煞
- ShenShaLogic.check_shenshas(bazi)
- # 墓库
- SiZhuLogic.check_muku(bazi, dc)
- # 确定墓库状态之后,更新藏干能量
- SiZhuLogic.update_powers(bazi, dc)
- # 计算高能关系带来的能量变动
- GaoNengLogic.update_gaoneng_power(bazi, dc)
- # 性格
- XingGeLogic.fill_xingge(bazi)
- # 格局
- GeJuLogic.fill_geju(bazi, dc)
- # 八字结构
- JieGouLogic.calc_jiegou(bazi, dc)
- # 健康
- JianKangLogic.check_jiankang(bazi)
- # 方案
- FangAnLogic.calc_fangan(bazi, dc)
- # 近日运势
- SimpleLuckyDay.calc_simple_lucky_day(bazi, dc)
- # 生成内容
- # ContentLogic.createContent(bazi)
- def __get_date_time(dt: str):
- v = time.strptime(dt, "%Y-%m-%d %H:%M")
- return datetime.fromtimestamp(mktime(v))
- def __get_date_time2(dt: str):
- v = time.strptime(dt, "%Y-%m-%d %H:%M:%S")
- return datetime.fromtimestamp(mktime(v))
- def calc_date_of_sizhu(request: SiZhuInfoRequest):
- dtm = __get_date_time(request.datetime)
- startDtm = __get_date_time2(request.startDate)
- # print("地区起始时间:", startDtm)
- # print(dtm.year, dtm.month, dtm.day, dtm.hour, dtm.minute, request.weidu, request.jingdu, request.location)
- dts = Wannianli.select().where(Wannianli.nian == dtm.year, Wannianli.yue == dtm.month, Wannianli.ri == dtm.day)
- # aifs = AreaInfo.select().where(AreaInfo.sheng == request.sheng, AreaInfo.shi == request.shi,
- # AreaInfo.qu == request.qu)
- tys = Taiyangpianyi.select().where(Taiyangpianyi.month == dtm.month, Taiyangpianyi.day == dtm.day)
- if len(dts) > 0 and len(tys) > 0:
- # 获得该地区在1月1日0点0分的时间,这个作为基准时间
- # startHour = aifs[0].hour
- # startMin = aifs[0].minute
- # startSec = aifs[0].second
- # print("00:00 基准时间", request.sheng, request.shi, request.qu, startHour, startMin, startSec)
- # 计算日期在这个时间上的偏差值,这个和地区无关,只看365天中太阳的位置计算出的总偏差秒数
- # 这个时间仍然是以0点0分为基准的
- diffMin = math.trunc(tys[0].diff / 60)
- diffSec = tys[0].diff - diffMin * 60
- # print(dtm.month, dtm.day, "太阳偏移秒差异", tys[0].diff, diffMin, diffSec)
- import datetime
- # 计算上面2个结果调整后的这一天0点0分的时间
- dtmArg1 = datetime.timedelta(hours=0, minutes=diffMin, seconds=diffSec)
- startDtm -= dtmArg1
- # print(dtm.month, dtm.day, "00:00", startDtm)
- # print(dtm.hour, dtm.minute, dtm.second)
- # 再追加上当前的时分
- dtmArg2 = datetime.timedelta(hours=dtm.hour, minutes=dtm.minute, seconds=dtm.second)
- startDtm += dtmArg2
- dtm += dtmArg1
- hfd = logic.get_hour_of_day(dts[0].ri_gan, startDtm.hour)
- request.texts = [
- dts[0].nian_gan, dts[0].yue_gan,
- dts[0].ri_gan, hfd[0],
- dts[0].nian_zhi, dts[0].yue_zhi,
- dts[0].ri_zhi, hfd[1],
- ]
- return startDtm
- def next_tiangan(tiangan: str):
- return SiZhuLogic.next_tiangan(tiangan)
- def next_dizhi(dizhi: str):
- return SiZhuLogic.next_dizhi(dizhi)
- def get_dizhi_by_hour(hour: int):
- return SiZhuLogic.get_dizhi_by_hour(hour)
- def get_tiangan_start_of_hour(day_tiangan: str):
- return SiZhuLogic.get_tiangan_start_of_hour(day_tiangan)
- def get_tiangan_by_hour(start_tiangan: str, hour: int):
- return SiZhuLogic.get_tiangan_by_hour(start_tiangan, hour)
|