예제 #1
0
파일: tgdz.py 프로젝트: yanyizhe/bzengine
 def getMDizhi(self):
   if self.time < self.lctime:
     return "丑"
   st = SolarTerm()
   for i in xrange(0,24,2):
     t = st.getJieqiTime(self.time.year, GZTime.JieqiB[i])
     if self.time < t:
       break
   return GZTime.Dizhi[(i/2+1)%12]
예제 #2
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
  def __init__(self, yy):
    self.yy = yy  # Type is GZTime
    self.st = SolarTerm()
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()

    self.t = []

    # 计算交司时刻

    JQMark  = ("大寒", "春分", "小满", "大暑", "秋分", "小雪", "大寒")
    JQYear  = (yy - 1,  yy,   yy,     yy,    yy,     yy,    yy)

    hi = GZTime.Dizhi.index(self.y_dizhi) % 4


    # 交司时刻表: 申初 午正 巳初 卯正 寅初 子正 亥初 酉正
    JSTable = (15, 12, 9, 6, 3, 0, 21, 18) # 寅午戍年

    # 申子辰年:JSTable[4]开始
    # 巳酉丑年:JSTable[2]开始
    # 寅午戍年:JSTable[0]开始
    # 卯未亥年:JSTable[6]开始
    hoff = [4, 2, 0, 6]

    # for i in xrange(0,7):
      # d = self.st.getJieqiTime(JQYear[i], JQMark[i])
      # d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i]]) + timedelta(days=daysOff[i])
      # print d,JQMark[i]

    for i in xrange(0,7):
      d1 = self.st.getJieqiTime(JQYear[i], JQMark[i])
      d2 = datetime(d1.year, d1.month, d1.day, JSTable[(hoff[hi] + i) % 8])
      self.t.append((d2,JQMark[i]))
예제 #3
0
파일: tgdz.py 프로젝트: yanyizhe/bzengine
  def update(self):
    st = SolarTerm()
    self.dhtime = st.getJieqiTime(self.time.year, "大寒")

    self.dztime = st.getJieqiTime(self.time.year, "冬至")
    self.cftime = st.getJieqiTime(self.time.year, "春分")
    self.xztime = st.getJieqiTime(self.time.year, "夏至")
    self.qftime = st.getJieqiTime(self.time.year, "秋分")

    self.lctime = st.getJieqiTime(self.time.year, "立春")
    self.lxtime = st.getJieqiTime(self.time.year, "立夏")
    self.lqtime = st.getJieqiTime(self.time.year, "立秋")
    self.ldtime = st.getJieqiTime(self.time.year, "立冬")
예제 #4
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
  def __init__(self, yy):

    self.year = yy
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()
    self.zhongyun = WuYun.ZhongYun[self.y_tiangan]
    self.st = SolarTerm()

    # 中运的初运日为去年的大寒节日
    self.cy_time = self.st.getJieqiTime(yy - 1, "大寒")
    self.cy_gzt = GZTime()
    self.cy_gzt.setTime(self.cy_time)

    # 判断干德符
    self.gdf = self.y_tiangan == self.cy_gzt.getDTiangan() or self.y_tiangan == self.cy_gzt.getHTiangan()
    self.gdfStr = None
    if self.y_tiangan == self.cy_gzt.getDTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的日干相合"

    if self.y_tiangan == self.cy_gzt.getHTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的时干相合"


    # 计算交司时刻
    # 每时辰八刻(初初刻、初一刻、初二刻、初三刻、初四刻、正初刻、正一刻、正二刻、正三刻、正四刻)
    keList =   [0,     144,   1008, 1872,  2736, 3600,  3744,  4608, 5472,  6336]
    keOff = [0, 6, 2, 8, 4]

    hoff = [3, 9, 15, 21]
    JQMark  = ["大寒", "春分", "芒种", "处暑", "立冬"]
    JQYear  = [yy - 1, yy, yy, yy, yy, yy]
    daysOff = [0,      13,     10,     7,     4]
    hi = GZTime.Dizhi.index(self.y_dizhi) % 4
    self.t = []
    for i in xrange(0,6):
      d = self.st.getJieqiTime(JQYear[i], JQMark[i%5])
      d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i%5]]) + timedelta(days=daysOff[i%5])
      self.t.append(d2)
예제 #5
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
class WuYun:
  ZhongYun = {
  "甲": "土运太过--岁土太过,雨湿流行",
  "己": "土运不及--岁土不及,风乃大行",

  "乙": "金运不及--岁金不及,炎火乃行",
  "庚": "金运太过--岁金太过,燥气流行",

  "丙": "水运太过--岁水太过,寒气流行",
  "辛": "水运不及--岁水不及,湿乃大行",

  "丁": "木运不及--岁木不及,燥乃大行",
  "壬": "木运太过--岁木太过,风气流行",

  "戊": "火运太过--岁火太过,炎暑流行",
  "癸": "火运不及--岁火不及,寒乃大行"
  }

  WuYun = "初运 二运 三运 四运 终运".split(' ')

  # 阳干
  # YangGan = ["甲", "丙", "戊", "庚", "壬"]

  def __init__(self, yy):

    self.year = yy
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()
    self.zhongyun = WuYun.ZhongYun[self.y_tiangan]
    self.st = SolarTerm()

    # 中运的初运日为去年的大寒节日
    self.cy_time = self.st.getJieqiTime(yy - 1, "大寒")
    self.cy_gzt = GZTime()
    self.cy_gzt.setTime(self.cy_time)

    # 判断干德符
    self.gdf = self.y_tiangan == self.cy_gzt.getDTiangan() or self.y_tiangan == self.cy_gzt.getHTiangan()
    self.gdfStr = None
    if self.y_tiangan == self.cy_gzt.getDTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的日干相合"

    if self.y_tiangan == self.cy_gzt.getHTiangan():
      self.gdf = True
      self.gdfStr = "年干与交运第一天的时干相合"


    # 计算交司时刻
    # 每时辰八刻(初初刻、初一刻、初二刻、初三刻、初四刻、正初刻、正一刻、正二刻、正三刻、正四刻)
    keList =   [0,     144,   1008, 1872,  2736, 3600,  3744,  4608, 5472,  6336]
    keOff = [0, 6, 2, 8, 4]

    hoff = [3, 9, 15, 21]
    JQMark  = ["大寒", "春分", "芒种", "处暑", "立冬"]
    JQYear  = [yy - 1, yy, yy, yy, yy, yy]
    daysOff = [0,      13,     10,     7,     4]
    hi = GZTime.Dizhi.index(self.y_dizhi) % 4
    self.t = []
    for i in xrange(0,6):
      d = self.st.getJieqiTime(JQYear[i], JQMark[i%5])
      d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i%5]]) + timedelta(days=daysOff[i%5])
      self.t.append(d2)
      # print WuYun.WuYun[i%5], " | ", self.t[i]

  # 年的天干地支
  def getYTD(self):
    return self.y_tiangan + self.y_dizhi

  def __str__(self):
    ss =  "中运:" + self.zhongyun + "\n" \
        "初运日: " + str(self.cy_gzt.time) + " : " + str(self.cy_gzt) + "\n"
    if self.gdf:
      ss += "干德符 --> 平气 : " + self.gdfStr
    return ss

  # 五运三纪
  def getWuYunSanJi(self):
    ss = str(self.year) + " 五运三纪: "
    if self.gdf:
      ss += "平气" + " (干德符: " + self.gdfStr + ")"
    else:
      ss += self.zhongyun
    return ss


  def getZhongYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    wy = WuYin(i % 2, i % 5)
    return wy

  def getZhongYunZhiQi(self):
    zy = self.getZhongYun()
    return zy.getQi(), zy.getTaiShao()

  def getKeYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    wy = WuYin(i % 2, i % 5)
    res = []
    for i in xrange(0,5):
      res.append(wy.next(i))
    return res

  def getKeYunList(self):
    kyL = self.getKeYun()
    res = []
    for i in kyL:
      res.append(str(i))
    return res

  def getZhuYunList(self):
    zyL = self.getZhuYun()
    res = []
    for i in zyL:
      res.append(str(i))
    return res

  def getZhuYun(self):
    i = GZTime.Tiangan.index(self.y_tiangan)
    j = i % 5
    wy = WuYin(i % 2, j)
    res = [wy]
    wy2 = wy
    while not wy2.isJiao():
        wy2 = wy2.prev(1)
        res.insert(0,wy2)

    while not wy.isYu():
      wy = wy.next(1)
      res.append(wy)
    return res

  # 五运交司时刻
  def getWuYunTime(self):
    tt = []
    for i in xrange(0,5):
      tt.append(str(self.t[i]) + " - " + str(self.t[i+1]))
    return tt

  def getWuYunTimeFormatStr(self):
    s = "| {0:68}|\n".format("五运交司时刻:")
    for i in xrange(0,5):
      s +=  "| " + WuYun.WuYun[i] +  " : {0:^54} |".format(str(self.t[i]) + " - " + str(self.t[i+1]))
      if i != 4:
        s += "\n"
    return s

  # 相得不相得
  def calcZhuKe(self, zz, kk):
    z = zz.index
    k = kk.index
    if z == k:
      return True, "同气求"
    if ((z+1) % 5) == k:
      return True, "主生客"
    if (z-1) % 5 == k:
      return True, "客生主"
    if (z+2) % 5 == k:
      return False, "主克客"
    if (z-2) % 5 == k:
      return True, "客克主"
    return None

  # 判断主运与客运是否相得
  def getXiangDe(self, zy, ky):
    xd = []
    for i in xrange(0,5):
      xd.append(self.calcZhuKe(zy[i],ky[i]))
    return xd

  def getXiangDeFormatStr(self, zy, ky):
    s = "| 相得   |"
    xd = [None, None, None, None, None]
    for i in xrange(0,5):
      xd[i] = self.calcZhuKe(zy[i], ky[i])
      if xd[i][0]:
        s += " {0:12}".format(xd[i][1])
      else:
        s += " {0:^8} ".format("X")
      s += "|"
    return s

  # 判断主运与客运是否不相得
  def getBuXiangDeFormatStr(self, zy, ky):
    s = "| 不相得 |"
    xd = [None, None, None, None, None]
    for i in xrange(0,5):
      xd[i] = self.calcZhuKe(zy[i], ky[i])
      if not xd[i][0]:
        s += " {0:12}".format(xd[i][1])
      else:
        s += " {0:^8} ".format("X")
      s += "|"
    return s

  def toSimpleJson(self):
    zy = self.getZhuYun()
    ky = self.getKeYun()
    ret = {}
    ret["交司时刻"] = self.getWuYunTime()
    ret["客运"] = self.getKeYunList()
    ret["中运"] = str(self.getZhongYun())
    ret["主运"] = self.getZhuYunList()
    ret["相得"] = self.getXiangDe(zy, ky)
    return ret

  def toString(self):
    zy = self.getZhuYun()
    ky = self.getKeYun()
    ret = ""
    sep = "+---------------------------------------------------------------+"
    ret += sep
    ret += "\n|{0:^65}|".format("五运")
    ret += "\n" + sep
    ret += "\n" + self.getWuYunTimeFormatStr()
    ret += "\n" + sep
    ret += "\n|        |   初运   |   二运   |   三运   |   四运   |   终运   |"
    ret += "\n|  客运  | " + " | ".join(self.getKeYunList()) + " | "
    ret += "\n|  中运  | {0:^56}| ".format(str(self.getZhongYun()))
    ret += "\n|  主运  | " + " | ".join(list2str(zy)) + " | "
    ret += "\n" + sep
    ret += "\n" + self.getXiangDeFormatStr(zy, ky)
    ret += "\n" + self.getBuXiangDeFormatStr(zy, ky)
    ret += "\n" + sep
    return ret
예제 #6
0
파일: 5y6q.py 프로젝트: yanyizhe/bzengine
class LiuQi:
  sep = "+--------------------------------------------------------------------------------+"

  # 主气
  ZhuQiName = (
    ("初气" , "厥阴风木"),  # 大寒 立春 雨水 惊蛰 春分 (春分前60日87.5刻)
    ("二气" , "少阴君火"),  # 春分 清明 谷雨 立夏 小满 (春分后60日87.5刻)
    ("三气" , "少阳相火"),  # 小满 芒种 夏至 小暑 大暑 (夏至前后各30日43刻)
    ("四气" , "太阴湿土"),  # 大暑 立秋 处暑 白露 秋分 (秋分前60日87.5刻)
    ("五气" , "阳明燥金"),  # 秋分 寒露 霜降 立冬 小雪 (秋分后60日87.5刻)
    ("终气" , "太阳寒水")   # 小雪 大雪 冬至 小寒 大寒 (冬至前后各30日43刻)
  )

  # 客气顺序
  KeQiName = ("厥阴风木","少阴君火","太阴湿土","少阳相火","阳明燥金","太阳寒水")


  def __init__(self, yy):
    self.yy = yy  # Type is GZTime
    self.st = SolarTerm()
    self.gz = GZTime(yy)
    self.y_tiangan = self.gz.getYTiangan()
    self.y_dizhi = self.gz.getYDizhi()

    self.t = []

    # 计算交司时刻

    JQMark  = ("大寒", "春分", "小满", "大暑", "秋分", "小雪", "大寒")
    JQYear  = (yy - 1,  yy,   yy,     yy,    yy,     yy,    yy)

    hi = GZTime.Dizhi.index(self.y_dizhi) % 4


    # 交司时刻表: 申初 午正 巳初 卯正 寅初 子正 亥初 酉正
    JSTable = (15, 12, 9, 6, 3, 0, 21, 18) # 寅午戍年

    # 申子辰年:JSTable[4]开始
    # 巳酉丑年:JSTable[2]开始
    # 寅午戍年:JSTable[0]开始
    # 卯未亥年:JSTable[6]开始
    hoff = [4, 2, 0, 6]

    # for i in xrange(0,7):
      # d = self.st.getJieqiTime(JQYear[i], JQMark[i])
      # d2 = datetime(d.year, d.month, d.day, hoff[hi]) + timedelta(seconds=keList[keOff[i]]) + timedelta(days=daysOff[i])
      # print d,JQMark[i]

    for i in xrange(0,7):
      d1 = self.st.getJieqiTime(JQYear[i], JQMark[i])
      d2 = datetime(d1.year, d1.month, d1.day, JSTable[(hoff[hi] + i) % 8])
      self.t.append((d2,JQMark[i]))
      # if i > 0:
      #   print self.t[i][0] - self.t[i-1][0]

  # 司天
  def getSiTian(self):
    i = GZTime.Dizhi.index(self.y_dizhi) % 6
    return LiuQi.KeQiName[(i+1)%6]

  def getSiTianZhiQi(self):
    return self.getSiTian()[-3:]

  def getZaiQuanZhiQi(self):
    return self.getZaiQuan()[-3:]

  # 在泉
  def getZaiQuan(self):
    i = GZTime.Dizhi.index(self.y_dizhi) % 6
    return LiuQi.KeQiName[(i+4)%6]

  def getZhuQiList(self):
    ret = []
    for i in LiuQi.ZhuQiName:
      ret.append(i[1])
    return ret

  def getZhuqiNameFormatStr(self):
    s = "|        |"
    for i in LiuQi.ZhuQiName:
      s += "    " + i[0] + "   |"
    return s

  def getZhuqiFormatStr(self):
    s = "|  主气  |"
    for i in LiuQi.ZhuQiName:
      s += "  " + i[1] + " |"
    return s

  def getZhuqiByIndex(self, i):
    return LiuQi.ZhuQiName[i][1]

  def getKeQiByIndex(self, i):
    j = GZTime.Dizhi.index(self.y_dizhi) % 6
    j = ((j+1)%6 - 2) % 6
    return LiuQi.KeQiName[(j + i) % 6]

  def getXiangDeFormatStr(self):
    for i in xrange(0,6):
      z = self.getZhuqiByIndex(i)
      k = self.getKeQiByIndex(i)
      r = self.calcZhuKe(z,k)

    # TODO

  def calcZhuKe(self, zz, kk):
    T = "木 火 土 金 水".split(" ")
    z = T.index(zz)
    k = T.index(kk)
    if z == k:
      return True, "同气求"
    if ((z+1) % 5) == k:
      return True, "主生客"
    if (z-1) % 5 == k:
      return True, "客生主"
    if (z+2) % 5 == k:
      return False, "主克客"
    if (z-2) % 5 == k:
      return True, "客克主"
    return None

  def getKeQiList(self):
    ret = []
    j = GZTime.Dizhi.index(self.y_dizhi) % 6
    j = ((j+1)%6 - 2) % 6

    for i in xrange(0,6):
      ret.append(LiuQi.KeQiName[(j + i) % 6])
    return ret

  def getKeqiFormatStr(self):
    s = "|  客气  |"
    kqL = self.getKeQiList()

    for i in kqL:
      s += "  " + i + " |"
    return s

  def getJiaoSiShiKe(self):
    ret = []
    for i in xrange(0,6):
      tt = self.t[i][1] + " " + str(self.t[i][0]) + "  -  " + self.t[i+1][1] + " " + str(self.t[i+1][0])
      # ret[LiuQi.ZhuQiName[i][0]] = tt
      ret.append(tt)
    return ret

  def getJiaoSiShiKeStr(self):
    s = "| {0:85}|\n".format("六气交司时刻:")
    for i in xrange(0,6):
      tt = self.t[i][1] + " " + str(self.t[i][0]) + "  -  " + self.t[i+1][1] + " " + str(self.t[i+1][0])
      s +=  "| " + LiuQi.ZhuQiName[i][0] +  " :{0:^76} |".format(tt)
      if i != 5:
        s += "\n"
    return s

  def toSimpleJson(self):
    ret = {}
    ret["交司时刻"] = self.getJiaoSiShiKe()
    ret["司天"] = self.getSiTian()
    ret["在泉"] = self.getZaiQuan()
    ret["客气"] = self.getKeQiList()
    ret["主气"] = self.getZhuQiList()
    return ret

  def toString(self):
    s = LiuQi.sep
    s += "\n"
    s += "|{0:^82}|".format("六气")
    s += "\n" + LiuQi.sep
    s += "\n" + self.getJiaoSiShiKeStr()
    s += "\n" + LiuQi.sep
    s += "\n|        |{0:^41}".format("司天:" + self.getSiTian()) + "|{0:^41}|".format("在泉:" + self.getZaiQuan())
    s += "\n" + LiuQi.sep
    s += "\n" + self.getZhuqiNameFormatStr()
    s += "\n" + self.getKeqiFormatStr()
    s += "\n" + self.getZhuqiFormatStr()
    s += "\n" + LiuQi.sep
    return s