Thread: [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. |
From: <ti...@us...> - 2007-03-26 07:01:59
|
Revision: 280 http://pymoul.svn.sourceforge.net/pymoul/?rev=280&view=rev Author: tiran Date: 2007-03-26 00:01:58 -0700 (Mon, 26 Mar 2007) Log Message: ----------- Added HTML table creator for podage lists 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-25 17:55:31 UTC (rev 279) +++ pymoul/trunk/src/moul/time/podage.py 2007-03-26 07:01:58 UTC (rev 280) @@ -126,6 +126,10 @@ else: dict.__getattribute__(self, name) + def __str__(self): + return ("%s (gate: %i, offset: %0.2f Pahrtahvotee)" % + (self['name'], self['gatenumber'], self['offset'])) + class PodAgeTime(object): """A pod age day cycle and gate event timer """ @@ -207,32 +211,49 @@ from moul.time.dni import DniTime from moul.time.utils import normalizeTZ +def _createTimeList(limit): + data = {} + for name in listPodAges(): + age = getPodAge(name) + pat = PodAgeTime(name) + agedata = data[name] = {} + dts = agedata['dt'] = [] + dnis = agedata['dni'] = [] + agedata['age'] = age + for n, dt in iter(pat): + if n > limit: + break + dnis.append(DniTime.fromUTC(dt)) + dts.append(dt) + return data + def forumTimeTable(limit=5, 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 """ + data = _createTimeList(limit) for tz in tzlist: print "[spoiler=%s]" % tz - for age in listPodAges(): - pat = PodAgeTime(age) - print + for name in listPodAges(): + agedata = data[name] + age = agedata['age'] print age - print 20 * "-" - for n, dt in iter(pat): - if n > limit: - break + print 50 * "-" + for dt, dni in zip(agedata['dt'], agedata['dni']): #dni = DniTime.fromUTC(dt) ldt = normalizeTZ(tz, dt) print ldt.strftime(fmt) #print "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt), # str(dni), dni.pahrtahvo) + print print "[/spoiler]" def allTzList(limit=50, fmt="%Y-%m-%d %H:%M %Z"): """Small utility function to create a nice list for the forum """ from pytz import common_timezones + data = _createTimeList(limit) base = os.path.join(os.path.dirname(__file__), 'out') if not os.path.isdir(base): os.mkdir(base) @@ -241,24 +262,34 @@ if continent not in ('UTC', 'US', 'Australia', 'Europe', 'America'): continue tzname = tz.replace('/', '_') - fd = open(os.path.join(base, "%s.html" % tzname), 'w') - print >>fd, "<html><head><title>%s</title></head><body><pre>" % tz + fd = open(os.path.join(base, "%s.html" % tzname), 'w', 16*1024) + print >>fd, "<html><head><title>%s</title></head><body><table border='1'>" % tz print tzname - for age in listPodAges(): - pat = PodAgeTime(age) - print >>fd - print >>fd, age - print >>fd, 20*"-" - for n, dt in iter(pat): - if n > limit: - break + th = [] + tr = [] + for i in range(limit): + tr.append([]) + for name in listPodAges(): + agedata = data[name] + #th.append(str(agedata['age'])) + th.append(name) + for i in range(limit): #dni = DniTime.fromUTC(dt) + dt = agedata['dt'][i] ldt = normalizeTZ(tz, dt) - #print >>fd, "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt), + tr[i].append(ldt.strftime(fmt)) + #print "Earth: %s, D'ni: %s, %i" % (ldt.strftime(fmt), # str(dni), dni.pahrtahvo) - print >>fd, ldt.strftime(fmt) - print >>fd, "\n" - print >>fd, "</pre></body></html>" + print >>fd, "<tr>" + for td in th: + print >>fd, "<td>%s</td>" % td + print >>fd, "</tr>" + for row in tr: + print >>fd, "<tr>" + for d in row: + print >>fd, "<td>%s</td>" % d + print >>fd, "</tr>" + print >>fd, "</table></body></html>" fd.close() if __name__ == '__main__': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-04-15 22:27:52
|
Revision: 282 http://pymoul.svn.sourceforge.net/pymoul/?rev=282&view=rev Author: tiran Date: 2007-04-15 15:27:52 -0700 (Sun, 15 Apr 2007) Log Message: ----------- Added Payiferen and Tetsonot 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-04-15 13:01:05 UTC (rev 281) +++ pymoul/trunk/src/moul/time/podage.py 2007-04-15 22:27:52 UTC (rev 282) @@ -58,10 +58,7 @@ 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, 0, tzinfo=UTC) -#BASE_DT = datetime(2007, 3, 7, 1, 10, 9, tzinfo=UTC) +BASE_DT = datetime(2007, 4, 16, 1, 45, 15, tzinfo=UTC) class PodAgeRegistry(dict): """Registry for pod ages @@ -85,7 +82,7 @@ return dict.__delitem__(self, key) def register(self, pod): - if pod.gatenumber < 0: + if pod.gatenumber is None: return False self[pod.name] = pod @@ -188,7 +185,7 @@ @return: Iterator that yields (number, date) @rtype: iterator (int, datetime) """ - dt = self._base #+ PODDAY_TD + dt = self._base - 3*PODDAY_TD n = 0 while True: yield (n, dt) @@ -199,15 +196,28 @@ registerPodAge(PodAgeInformation( name = 'Negilahn', gatenumber = 18, - offset = 0, # Pahrtahvotee + offset = -1.49, # Pahrtahvotee )) registerPodAge(PodAgeInformation( name = 'Dereno', gatenumber = 25, - offset = 1, # Pahrtahvo + offset = -0.46, # Pahrtahvo )) +registerPodAge(PodAgeInformation( + name = 'Payiferen', + gatenumber = 13, + offset = 0, # Pahrtahvo + )) + +registerPodAge(PodAgeInformation( + name = 'Tetsonot', + gatenumber = None, + offset = 0, # Pahrtahvotee + )) + + from moul.time.dni import DniTime from moul.time.utils import normalizeTZ @@ -293,8 +303,9 @@ fd.close() if __name__ == '__main__': - #forumTimeTable(tzlist=('CET',)) + forumTimeTable(tzlist=('CET',)) #forumTimeTable(tzlist=('UTC',)) - forumTimeTable(tzlist=('US/Pacific',)) + #forumTimeTable(tzlist=('US/Pacific',)) #forumTimeTable() #allTzList() + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |