示例#1
0
    def __init__(self):
        # date
        self.date = GCGregorianDate()
        # moon times
        self.moonrise = GCTime()
        self.moonset = GCTime()
        # astronomical data from astro-sub-layer
        self.astrodata = GCDayData()

        self.nCaturmasya = 0
        self.hasDST = 0
        self.nFeasting = FeastType.FEAST_NULL
        # data for vaisnava calculations
        self.dayEvents = []

        self.festivals = ''
        self.nFastType = FastType.FAST_NULL
        self.nMhdType = MahadvadasiType.EV_NULL
        self.ekadasi_vrata_name = ''
        self.ekadasi_parana = False
        self.eparana_time1 = 0.0
        self.eparana_time2 = 0.0
        self.eparana_type1 = 0
        self.eparana_type2 = 0
        self.sankranti_zodiac = -1
        #double sankranti_time
        self.sankranti_day = GCGregorianDate()
 def __init__(self):
     self.m_location = GCLocation()
     self.eventTime = GCGregorianDate()
     self.details = GCDayData()
     self.b_adhika = False
     self.celeb_gy = [0] * TRESULT_APP_CELEBS
     self.celeb_date = [
         GCGregorianDate() for i in range(TRESULT_APP_CELEBS)
     ]
    def CalculateMasaList(self, loc, year, count):
        day = GCDayData()
        earth = loc.GetEarthData()

        self.startYear = year
        self.countYears = count
        self.start = GCGregorianDate(date=GetFirstDayOfYear(earth, year))
        self.end = GCGregorianDate(date=GetFirstDayOfYear(earth, year + count))
        self.location = GCLocation()
        self.location.Set(loc)

        i = 0
        prev_masa = -1
        prev_paksa = -1
        prev_gyear = -1
        current = 0
        d = GCGregorianDate(date=self.start)

        while d.IsBeforeThis(self.end):
            day.DayCalc(d, earth)
            if prev_paksa != day.nPaksa:
                day.nMasa = day.MasaCalc(d, earth)
                if prev_masa != day.nMasa:
                    if len(self.arr) > 0:
                        self.arr[-1]['end'] = GCGregorianDate(date=d,
                                                              addDays=-1)
                    prev_masa = day.nMasa
                    self.arr.append({
                        'masa':
                        day.nMasa,
                        'masaName':
                        GCStrings.GetMasaName(day.nMasa),
                        'year':
                        day.nGaurabdaYear,
                        'start':
                        GCGregorianDate(date=d)
                    })
            prev_paksa = day.nPaksa
            d.NextDay()

        self.arr[-1]['end'] = GCGregorianDate(date=d, addDays=-1)
        return len(self.arr)
示例#4
0
def Gregorian2Gaurabda(vc, va, earth):
    day = GCDayData()
    day.DayCalc(vc, earth)
    va.masa = day.MasaCalc(vc, earth)
    va.tithi = day.nTithi
    va.gyear = day.nGaurabdaYear
示例#5
0
def GetGaurabdaYear(vc, earth):
    day = GCDayData()
    day.DayCalc(vc, earth)
    day.MasaCalc(vc, earth)
    return day.nGaurabdaYear
示例#6
0
def writeGaurabdaNextTithiXml(xml, loc, vcStart, vaStart):
    gmasa = vaStart.masa
    gpaksa = 1 if vaStart.tithi >= 15 else 0
    gtithi = vaStart.tithi % 15

    xml.write("<xml>\n")
    xml.write("\t<request name=\"Tithi\" version=\"")
    xml.write(GCStrings.getString(130))
    xml.write("\">\n")
    xml.write("\t\t<arg name=\"longitude\" val=\"")
    xml.write(str(loc.m_fLongitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"latitude\" val=\"")
    xml.write(str(loc.m_fLatitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"timezone\" val=\"")
    xml.write(str(loc.m_fTimezone))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"start date\" val=\"")
    xml.write(str(vcStart))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"masa\" val=\"")
    xml.write(str(gmasa))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"paksa\" val=\"")
    xml.write(str(gpaksa))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"tithi\" val=\"")
    xml.write(str(gtithi))
    xml.write("\" />\n")
    xml.write("\t</request>\n")
    xml.write("\t<result name=\"Tithi\">\n")

    earth = loc.GetEarthData()
    vcs = GCGregorianDate()
    vce = GCGregorianDate()
    sun = SUNDATA()
    A = 0
    day = GCDayData()

    today = GCGregorianDate(date=vcStart)
    today.PreviousDay()
    vcStart.SubtractDays(15)
    for A in range(0, 4):
        vcs.Set(
            GCTithi.CalcTithiEndEx(vcStart, 0, gmasa, gpaksa, gtithi, earth,
                                   vce))
        if not vcs.IsBeforeThis(today):
            oTithi = gpaksa * 15 + gtithi
            oMasa = gmasa
            oPaksa = gpaksa
            oYear = 0
            xml.write("\t<celebration\n")
            xml.write("\t\trtithi=\"")
            xml.write(GCStrings.GetTithiName(oTithi))
            xml.write("\"\n")
            xml.write("\t\trmasa=\"")
            xml.write(GCStrings.GetMasaName(oMasa))
            xml.write("\"\n")
            xml.write("\t\trpaksa=\"")
            xml.write("Gaura" if oPaksa else "Krsna")
            xml.write("\"\n")
            # test ci je ksaya
            today.Set(vcs)
            today.shour = 0.5
            sun.SunCalc(today, earth)
            sunrise = (sun.sunrise_deg + loc.m_fTimezone * 15.0) / 360
            if sunrise < vcs.shour:
                today.Set(vce)
                sun.SunCalc(today, earth)
                sunrise = (sun.sunrise_deg + loc.m_fTimezone * 15.0) / 360
                if sunrise < vce.shour:
                    # normal type
                    vcs.NextDay()
                    xml.write("\t\ttype=\"normal\"\n")
                else:
                    # ksaya
                    vcs.NextDay()
                    day.DayCalc(vcs, earth)
                    oTithi = day.nTithi
                    oPaksa = day.nPaksa
                    oMasa = day.MasaCalc(vcs, earth)
                    oYear = day.nGaurabdaYear
                    xml.write("\t\ttype=\"ksaya\"\n")
            else:
                # normal, alebo prvy den vriddhi
                today.Set(vce)
                sun.SunCalc(today, earth)
                if (sun.sunrise_deg +
                        loc.m_fTimezone * 15.0) / 360 < vce.shour:
                    # first day of vriddhi type
                    xml.write("\t\ttype=\"vriddhi\"\n")
                else:
                    # normal
                    xml.write("\t\ttype=\"normal\"\n")
            xml.write("\t\tdate=\"")
            xml.write(str(vcs))
            xml.write("\"\n")
            xml.write("\t\totithi=\"")
            xml.write(GCStrings.GetTithiName(oTithi))
            xml.write("\"\n")
            xml.write("\t\tomasa=\"")
            xml.write(GCStrings.GetMasaName(oMasa))
            xml.write("\"\n")
            xml.write("\t\topaksa=\"")
            xml.write("Gaura" if oPaksa else "Krsna")
            xml.write("\"\n")
            xml.write("\t/>\n")
            break
        else:
            vcStart.Set(vcs)
            vcs.NextDay()

    xml.write("\t</result>\n")
    xml.write("</xml>\n")
    return 1
示例#7
0
def writeGaurabdaTithiXml(xml, loc, vaStart, vaEnd):
    gyearA = vaStart.gyear
    gyearB = vaEnd.gyear
    gmasa = vaStart.masa
    gpaksa = 1 if vaStart.tithi >= 15 else 0
    gtithi = vaStart.tithi % 15

    if gyearB < gyearA:
        gyearB = gyearA

    xml.write("<xml>\n")
    xml.write("\t<request name=\"Tithi\" version=\"")
    xml.write(GCStrings.getString(130))
    xml.write("\">\n")
    xml.write("\t\t<arg name=\"longitude\" val=\"")
    xml.write(str(loc.m_fLongitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"latitude\" val=\"")
    xml.write(str(loc.m_fLatitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"timezone\" val=\"")
    xml.write(str(loc.m_fTimezone))
    xml.write("\" />\n")
    if gyearA > 1500:
        xml.write("\t\t<arg name=\"year-start\" val=\"")
        xml.write(str(gyearA))
        xml.write("\" />\n")
        xml.write("\t\t<arg name=\"year-end\" val=\"")
        xml.write(str(gyearB))
        xml.write("\" />\n")
    else:
        xml.write("\t\t<arg name=\"gaurabdayear-start\" val=\"")
        xml.write(str(gyearA))
        xml.write("\" />\n")
        xml.write("\t\t<arg name=\"gaurabdayear-end\" val=\"")
        xml.write(str(gyearB))
        xml.write("\" />\n")
    xml.write("\t\t<arg name=\"masa\" val=\"")
    xml.write(str(gmasa))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"paksa\" val=\"")
    xml.write(str(gpaksa))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"tithi\" val=\"")
    xml.write(str(gtithi))
    xml.write("\" />\n")
    xml.write("\t</request>\n")
    xml.write("\t<result name=\"Tithi\">\n")

    earth = loc.GetEarthData()
    vcs = GCGregorianDate()
    vce = GCGregorianDate()
    today = GCGregorianDate()
    sun = SUNDATA()
    day = GCDayData()
    A = B = 0

    if gyearA > 1500:
        A = gyearA - 1487
        B = gyearB - 1485
    else:
        A = gyearA
        B = gyearB

    for A in range(A, B + 1):
        vcs.Set(GCTithi.CalcTithiEnd(A, gmasa, gpaksa, gtithi, earth, vce))
        if gyearA > 1500:
            if (vcs.year < gyearA) or (vcs.year > gyearB):
                continue
        oTithi = gpaksa * 15 + gtithi
        oMasa = gmasa
        oPaksa = gpaksa
        oYear = 0
        xml.write("\t<celebration\n")
        xml.write("\t\trtithi=\"")
        xml.write(GCStrings.GetTithiName(oTithi))
        xml.write("\"\n")
        xml.write("\t\trmasa=\"")
        xml.write(GCStrings.GetMasaName(oMasa))
        xml.write("\"\n")
        xml.write("\t\trpaksa=\"")
        xml.write('Gaura' if oPaksa else "Krsna")
        xml.write("\"\n")
        # test ci je ksaya
        today.Set(vcs)
        today.shour = 0.5
        sun.SunCalc(today, earth)
        sunrise = (sun.sunrise_deg + loc.m_fTimezone * 15.0) / 360
        if sunrise < vcs.shour:
            today.Set(vce)
            sun.SunCalc(today, earth)
            sunrise = (sun.sunrise_deg + loc.m_fTimezone * 15.0) / 360
            if sunrise < vce.shour:
                # normal type
                vcs.NextDay()
                xml.write("\t\ttype=\"normal\"\n")
            else:
                # ksaya
                vcs.NextDay()
                day.DayCalc(vcs, earth)
                oTithi = day.nTithi
                oPaksa = day.nPaksa
                oMasa = day.MasaCalc(vcs, earth)
                oYear = day.nGaurabdaYear
                xml.write("\t\ttype=\"ksaya\"\n")
        else:
            # normal, alebo prvy den vriddhi
            today.Set(vce)
            sun.SunCalc(today, earth)
            if (sun.sunrise_deg + loc.m_fTimezone * 15.0) / 360 < vce.shour:
                # first day of vriddhi type
                xml.write("\t\ttype=\"vriddhi\"\n")
            else:
                # normal
                xml.write("\t\ttype=\"normal\"\n")
        xml.write("\t\tdate=\"")
        xml.write(str(vcs))
        xml.write("\"\n")
        xml.write("\t\totithi=\"")
        xml.write(GCStrings.GetTithiName(oTithi))
        xml.write("\"\n")
        xml.write("\t\tomasa=\"")
        xml.write(GCStrings.GetMasaName(oMasa))
        xml.write("\"\n")
        xml.write("\t\topaksa=\"")
        xml.write('Gaura' if oPaksa else 'Krsna')
        xml.write("\"\n")
        xml.write("\t/>\n")

    xml.write("\t</result>\n")
    xml.write("</xml>\n")
    return 1
示例#8
0
def writeXml(xml, loc, vc):
    date = GCGregorianDate()
    xml.write("<xml>\n")
    xml.write("\t<request name=\"Tithi\" version=\"")
    xml.write(GCStrings.getString(130))
    xml.write("\">\n")
    xml.write("\t\t<arg name=\"longitude\" val=\"")
    xml.write(str(loc.m_fLongitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"latitude\" val=\"")
    xml.write(str(loc.m_fLatitude))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"timezone\" val=\"")
    xml.write(str(loc.m_fTimezone))
    xml.write("\" />\n")
    xml.write("\t\t<arg name=\"startdate\" val=\"")
    xml.write(str(vc))
    xml.write("\" />\n")
    xml.write("\t</request>\n")
    xml.write("\t<result name=\"Tithi\">\n")

    d1 = GCGregorianDate()
    d2 = GCGregorianDate()
    dn = GCGregorianDate()
    dt = GCTime()
    earth = loc.GetEarthData()

    day = GCDayData()
    day.DayCalc(vc, earth)

    d = GCGregorianDate(date=vc)
    d.tzone = loc.m_fTimezone
    d.shour = day.sun.sunrise_deg / 360.0 + loc.m_fTimezone / 24.0

    GCTithi.GetPrevTithiStart(earth, d, d1)
    GCTithi.GetNextTithiStart(earth, d, d2)

    dt.SetDegTime(d1.shour * 360)
    # start tithi at t[0]
    xml.write("\t\t<tithi\n\t\t\tid=\"")
    xml.write(str(day.nTithi))
    xml.write("\"\n")
    xml.write("\t\t\tname=\"")
    xml.write(GCStrings.GetTithiName(day.nTithi))
    xml.write("\"\n")
    xml.write("\t\t\tstartdate=\"")
    xml.write(str(d1))
    xml.write("\"\n")
    xml.write("\t\t\tstarttime=\"")
    xml.write(repr(dt))
    xml.write("\"\n")

    dt.SetDegTime(d2.shour * 360)
    xml.write("\t\t\tenddate=\"")
    xml.write(str(d2))
    xml.write("\"\n")
    xml.write("\t\t\tendtime=\"")
    xml.write(repr(dt))
    xml.write("\"\n />")

    xml.write("\t</result>\n")
    xml.write("</xml>\n")

    return 1
示例#9
0
def CalcTithiDate(nGYear, nMasa, nPaksa, nTithi, earth):
    i = 0
    gy = 0
    d = GCGregorianDate()
    dtemp = GCGregorianDate()
    day = GCDayData()
    tithi = 0
    counter = 0
    tmp = 0

    if nGYear >= 464 and nGYear < 572:
        tmp = gGaurBeg[(nGYear - 464) * 26 + nMasa * 2 + nPaksa]
        d.month = (tmp & 0x3e0) >> 5
        d.day = (tmp & 0x1f)
        d.year = (tmp & 0xfffc00) >> 10
        d.tzone = earth.tzone
        d.NextDay()

        day.DayCalc(d, earth)
        day.nMasa = day.MasaCalc(d, earth)
        gy = day.nGaurabdaYear
    else:
        #d = GetFirstDayOfYear(earth, nGYear + 1486)
        d.day = 15
        d.month = 2 + nMasa
        d.year = nGYear + 1486
        if d.month > 12:
            d.month -= 12
            d.year += 1
        d.shour = 0.5
        d.tzone = earth.tzone

        i = 0
        while True:
            d.AddDays(13)
            day.DayCalc(d, earth)
            day.nMasa = day.MasaCalc(d, earth)
            gy = day.nGaurabdaYear
            i += 1
            if i >= 30: break
            if (day.nPaksa == nPaksa) and (day.nMasa == nMasa): break

    if i >= 30:
        d.year = d.month = d.day = -1
        return d

    # we found masa and paksa
    # now we have to find tithi
    tithi = nTithi + nPaksa * 15

    if day.nTithi == tithi:
        # loc1
        # find tithi juncts in this day and according to that times,
        # look in previous or next day for end and start of this tithi
        d.PreviousDay()
        day.DayCalc(d, earth)
        if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
            d.NextDay()
        return d

    if day.nTithi < tithi:
        # do increment of date until nTithi == tithi
        #   but if nTithi > tithi
        #       then do decrement of date
        counter = 0
        while counter < 16:
            d.NextDay()
            day.DayCalc(d, earth)
            if day.nTithi == tithi:
                return d
            if (day.nTithi < tithi) and (day.nPaksa != nPaksa):
                return d
            if day.nTithi > tithi:
                return d
            counter += 1
        # somewhere is error
        d.year = d.month = d.day = 0
        return d
    else:
        # do decrement of date until nTithi <= tithi
        counter = 0
        while counter < 16:
            d.PreviousDay()
            day.DayCalc(d, earth)
            if day.nTithi == tithi:
                return d
            if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
                d.NextDay()
                return d
            if day.nTithi < tithi:
                d.NextDay()
                return d
            counter += 1
        # somewhere is error
        d.year = d.month = d.day = 0
        return d

    # now we know the type of day-accurancy
    # nType = 0 means, that we dont found a day
    # nType = 1 means, we find day, when tithi was present at sunrise
    # nType = 2 means, we found day, when tithi started after sunrise
    #                  but ended before next sunrise
    #

    return d
示例#10
0
def CalcTithiEndEx(vcStart, GYear, nMasa, nPaksa, nTithi, earth, endTithi):
    d = GCGregorianDate()
    dtemp = GCGregorianDate()
    day = GCDayData()
    tithi = 0
    counter = 0
    sunrise = 0.0
    start = GCGregorianDate()
    end = GCGregorianDate()
    start.shour = -1.0
    end.shour = -1.0
    start.day = start.month = start.year = -1
    end.day = end.month = end.year = -1

    d.Set(vcStart)

    i = 0
    while True:
        d.AddDays(13)
        day.DayCalc(d, earth)
        day.nMasa = day.MasaCalc(d, earth)
        gy = day.nGaurabdaYear
        i += 1
        if ((day.nPaksa == nPaksa) and (day.nMasa == nMasa)) or i > 30:
            break

    if i > 30:
        d.year = d.month = d.day = -1
        return d

    # we found masa and paksa
    # now we have to find tithi
    tithi = nTithi + nPaksa * 15

    if day.nTithi == tithi:
        # loc1
        # find tithi juncts in this day and according to that times,
        # look in previous or next day for end and start of this tithi
        nType = 1
    else:
        if day.nTithi < tithi:
            # do increment of date until nTithi == tithi
            #   but if nTithi > tithi
            #       then do decrement of date
            counter = 0
            while counter < 30:
                d.NextDay()
                day.DayCalc(d, earth)
                if day.nTithi == tithi:
                    break
                if (day.nTithi < tithi) and (day.nPaksa != nPaksa):
                    d.PreviousDay()
                    break
                if day.nTithi > tithi:
                    d.PreviousDay()
                    break
                counter += 1
            # somewhere is error
            if counter >= 30:
                d.year = d.month = d.day = 0
                nType = 0
        else:
            # do decrement of date until nTithi <= tithi
            counter = 0
            while counter < 30:
                d.PreviousDay()
                day.DayCalc(d, earth)
                if day.nTithi == tithi:
                    break
                if (day.nTithi > tithi) and (day.nPaksa != nPaksa):
                    break
                if day.nTithi < tithi:
                    break
                counter += 1
            # somewhere is error
            if counter >= 30:
                d.year = d.month = d.day = 0
                nType = 0

        if day.nTithi == tithi:
            # do the same as in loc1
            nType = 1
        else:
            # nTithi != tithi and nTithi < tithi
            # but on next day is nTithi > tithi
            # that means we will find start and the end of tithi
            # in this very day or on next day before sunrise
            nType = 2

    # now we know the type of day-accurancy
    # nType = 0 means, that we dont found a day
    # nType = 1 means, we find day, when tithi was present at sunrise
    # nType = 2 means, we found day, when tithi started after sunrise
    #                  but ended before next sunrise
    #
    sunrise = day.sun.sunrise_deg / 360 + earth.tzone / 24

    if nType == 1:
        d1 = GCGregorianDate()
        d2 = GCGregorianDate()
        d.shour = sunrise
        GCTithi.GetPrevTithiStart(earth, d, d1)
        #d = d1
        #d.shour += 0.02
        GCTithi.GetNextTithiStart(earth, d, d2)

        endTithi.Set(d2)
        return d1
    elif nType == 2:
        d1 = GCGregorianDate()
        d2 = GCGregorianDate()
        d.shour = sunrise
        GCTithi.GetNextTithiStart(earth, d, d1)
        d.Set(d1)
        d.shour += 0.1
        d.NormalizeValues()
        GCTithi.GetNextTithiStart(earth, d, d2)

        endTithi.Set(d2)
        return d1

    # if nType == 0, then this algoritmus has some failure
    if nType == 0:
        d.year = 0
        d.month = 0
        d.day = 0
        d.shour = 0.0
        endTithi.Set(d)
    else:
        d.Set(start)
        endTithi.Set(end)

    return d