[Pymoul-svn] SF.net SVN: pymoul: [263] pymoul/trunk/src/moul/time/podage.py
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-03-18 22:50:56
|
Revision: 263 http://pymoul.svn.sourceforge.net/pymoul/?rev=263&view=rev Author: tiran Date: 2007-03-18 15:50:45 -0700 (Sun, 18 Mar 2007) Log Message: ----------- Pod age time code update Modified Paths: -------------- pymoul/trunk/src/moul/time/podage.py Modified: pymoul/trunk/src/moul/time/podage.py =================================================================== --- pymoul/trunk/src/moul/time/podage.py 2007-03-16 15:17:59 UTC (rev 262) +++ pymoul/trunk/src/moul/time/podage.py 2007-03-18 22:50:45 UTC (rev 263) @@ -48,7 +48,20 @@ from moul.time.utils import UTC from moul.time.utils import td2sec from moul.time.utils import utcnow +from moul.time.dni import PRORAHN_PER_PAHRTAHVO +from moul.time.dni import FACTOR_SP + +# constants for pod day length +PAHRTAHVO_SEC = PRORAHN_PER_PAHRTAHVO * FACTOR_SP +PODDAY_SEC = 13 * PAHRTAHVO_SEC +PODDAY_TD = timedelta(seconds=PODDAY_SEC) +# base datetime for calculations +#BASE_DT = datetime(2007, 3, 4, 10, 16, 0, tzinfo=UTC) +# XXX Uru's main game server is off 3min 35sec +BASE_DT = datetime(2007, 3, 7, 1, 7, 57, tzinfo=UTC) +#BASE_DT = datetime(2007, 3, 7, 1, 10, 9, tzinfo=UTC) + class PodAgeRegistry(dict): """Registry for pod ages """ @@ -71,6 +84,8 @@ return dict.__delitem__(self, key) def register(self, pod): + if pod.gatenumber < 0: + return False self[pod.name] = pod def listNumbers(self): @@ -92,14 +107,11 @@ """ __slots__ = () - def __init__(self, __registry=_podRegistry, **kw): + def __init__(self, **kw): super(PodAgeInformation, self).__init__(**kw) - self['daycycle'] = timedelta(days=0, hours=15, minutes=43) - self['daycycle_sec'] = td2sec(self['daycycle']) - for key in ('name', 'gatenumber'): + for key in ('name', 'gatenumber', 'offset'): if key not in self: raise KeyError(key) - __registry.register(self) def __getattribute__(self, name): if name in self: @@ -119,6 +131,8 @@ age = getPodAge(name) elif isinstance(name, int): age = getPodAgeByNumber(name) + elif isinstance(name, PodAgeInformation): + age = name else: raise TypeError(name) if age is None: @@ -138,11 +152,12 @@ """ if startdt is None: startdt = utcnow() + base_dt = BASE_DT + self._age.offset # calculate completed cycles since base_dt - sec = td2sec(startdt - self._age.base_dt) - cycles = floor(sec / self._age.daycycle_sec) - delta = int(cycles) * self._age.daycycle - self._base = self._age.base_dt + delta + sec = td2sec(startdt - base_dt) + cycles = floor(sec / PODDAY_SEC) + delta = int(cycles) * PODDAY_TD + self._base = base_dt + delta def get(self, count=1): """Get date by count @@ -152,7 +167,7 @@ @return: date and time of next event @rtype: datetime instance """ - delta = count * self._age.daycycle + delta = count * PODDAY_TD return self._base + delta def __iter__(self): @@ -161,7 +176,7 @@ @return: Iterator that yields (number, date) @rtype: iterator (int, datetime) """ - delta = self._age.daycycle + delta = PODDAY_TD dt = self._base + delta n = 0 while True: @@ -170,12 +185,80 @@ n += 1 # pod ages -pod18 = PodAgeInformation(name = 'Negilahn', gatenumber = 18, - base_dt = datetime(2007, 3, 4, 10, 16, 0, tzinfo=UTC)) +registerPodAge(PodAgeInformation( + name = 'Dereno', + gatenumber = 25, + offset = timedelta(seconds=1*PAHRTAHVO_SEC) + )) +registerPodAge(PodAgeInformation( + name = 'Negilahn', + gatenumber = 18, + offset = timedelta(seconds=0) + )) + +registerPodAge(PodAgeInformation( + name = 'Payiferen', + gatenumber = -1, + offset = timedelta(seconds=-1) + )) + +registerPodAge(PodAgeInformation( + name = 'Tetsonot', + gatenumber = -1, + offset = timedelta(seconds=-1) + )) + + +from moul.time.dni import DniTime +from moul.time.utils import normalizeTZ + +def forumTimeTable(limit=10, fmt="%Y-%m-%d %H:%M:%S %Z", tzlist=('UTC', 'CET', + 'US/Mountain', 'US/Pacific', 'US/Eastern', + 'Australia/Sydney')): + """Small utility function to create a nice list for the forum + """ + for tz in tzlist: + print "[spoiler=%s]" % tz + for age in listPodAges(): + pat = PodAgeTime(age) + print age + print "--------------------------------------------------------------------" + for n, dt in iter(pat): + if n > limit: + break + dni = DniTime.fromUTC(dt) + ldt = normalizeTZ(tz, dt) + print "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt), + str(dni), dni.pahrtahvo) + print "[/spoiler]" + +def allTzList(limit=50, fmt="%Y-%m-%d %H:%M:%S %Z"): + """Small utility function to create a nice list for the forum + """ + base = os.path.dirname(__file__) + for tz in common_timezones: + continent = tz.split('/')[0] + if continent not in ('UTC', 'US', 'Australia', 'Europe', 'America'): + continue + tzname = tz.replace('/', '_') + fd = open(os.path.join(base, 'out', "%s.html" % tzname), 'w') + print >>fd, "<html><head><title>%s</title></head><body><pre>" % tz + for age in listPodAges(): + pat = PodAgeTime(age) + print age, tzname + print >>fd, age + print >>fd, "--------------------------------------------------------------------" + for n, dt in iter(pat): + if n > limit: + break + dni = DniTime.fromUTC(dt) + ldt = normalizeTZ(tz, dt) + print >>fd, "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt), + str(dni), dni.pahrtahvo) + print >>fd, "\n" + print >>fd, "</pre></body></html>" + fd.close() + if __name__ == '__main__': - padneg = PodAgeTime('Negilahn') - for n, dt in iter(padneg): - print n, dt - if n > 20: - break + forumTimeTable(tzlist=('UTC',)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |