[Pymoul-svn] SF.net SVN: pymoul: [242] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-03-08 02:42:58
|
Revision: 242
http://pymoul.svn.sourceforge.net/pymoul/?rev=242&view=rev
Author: tiran
Date: 2007-03-07 18:42:59 -0800 (Wed, 07 Mar 2007)
Log Message:
-----------
Changed status to beta
Added modules for pod age and eder gira
Modified Paths:
--------------
pymoul/trunk/setup.py
Added Paths:
-----------
pymoul/trunk/src/moul/time/edergira.py
pymoul/trunk/src/moul/time/podage.py
pymoul/trunk/src/moul/time/tests/test_podage.py
Modified: pymoul/trunk/setup.py
===================================================================
--- pymoul/trunk/setup.py 2007-03-08 02:28:11 UTC (rev 241)
+++ pymoul/trunk/setup.py 2007-03-08 02:42:59 UTC (rev 242)
@@ -49,8 +49,7 @@
license = "GPL",
keywords = "myst online uru live moul cyan",
classifiers = (
- 'Development Status :: 1 - Planning',
- 'Environment :: Console',
+ 'Development Status :: 2 - Alpha',
'Environment :: Win32 (MS Windows)',
'Intended Audience :: End Users/Desktop',
'Intended Audience :: Developers',
@@ -114,3 +113,4 @@
kwargs['packages'].append('moul.qt')
setup(**kwargs)
+
Added: pymoul/trunk/src/moul/time/edergira.py
===================================================================
--- pymoul/trunk/src/moul/time/edergira.py (rev 0)
+++ pymoul/trunk/src/moul/time/edergira.py 2007-03-08 02:42:59 UTC (rev 242)
@@ -0,0 +1,41 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""pyMoul Ede Gira day cycle
+
+Based on BrettM's information
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id"
+__revision__ = "$Revision"
+
+
+from datetime import datetime
+from datetime import timedelta
+
+from moul.time.utils import UTC
+from moul.time.utils import td2sec
+from moul.time.utils import utcnow
+
+delta = timedelta(days=0, hours=10, minutes=0) # 10h
+base_dt = datetime(2007, 3, 8, 9, 15, 0) # noon
+
+class EderGiraDay(object):
+ """Eder Gira day cycle class
+ """
+ def __init__(self):
+ pass
Property changes on: pymoul/trunk/src/moul/time/edergira.py
___________________________________________________________________
Name: svn:keywords
+ 'Id Revision'
Name: svn:eol-style
+ native
Added: pymoul/trunk/src/moul/time/podage.py
===================================================================
--- pymoul/trunk/src/moul/time/podage.py (rev 0)
+++ pymoul/trunk/src/moul/time/podage.py 2007-03-08 02:42:59 UTC (rev 242)
@@ -0,0 +1,181 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""pyMoul Pod age time
+
+>>> pod18.gatenumber
+18
+>>> getPodAge('Negilahn') is pod18
+True
+>>> getPodAgeByNumber(18) is pod18
+True
+
+>>> padneg = PodAgeTime('Negilahn')
+>>> for n, dt in iter(padneg):
+... if n > 20:
+... break
+
+>>> isinstance(padneg.get(), datetime)
+True
+
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id"
+__revision__ = "$Revision"
+
+
+import os
+import sys
+from datetime import datetime
+from datetime import timedelta
+from math import floor
+from time import mktime
+
+from moul.time.utils import UTC
+from moul.time.utils import td2sec
+from moul.time.utils import utcnow
+
+class PodAgeRegistry(dict):
+ """Registry for pod ages
+ """
+ __slots__ = ('_bynumber',)
+
+ def __new__(cls, **kw):
+ self = dict.__new__(cls, **kw)
+ self._bynumber = {}
+ return self
+
+ def __setitem__(self, key, item):
+ if not isinstance(item, PodAgeInformation):
+ raise TypeError(item)
+ self._bynumber[item.gatenumber] = item
+ return dict.__setitem__(self, key, item)
+
+ def __delitem__(self, key):
+ item = self[key]
+ del self._bynumber[item.gatenumber]
+ return dict.__delitem__(self, key)
+
+ def register(self, pod):
+ self[pod.name] = pod
+
+ def listNumbers(self):
+ return self._bynumber.keys()
+
+ def byNumber(self, nr):
+ return self._bynumber[nr]
+
+_podRegistry = PodAgeRegistry()
+getPodAge = _podRegistry.get
+getPodAgeByNumber = _podRegistry.byNumber
+registerPodAge = _podRegistry.register
+
+def listPodAges():
+ return [name for name in _podRegistry if name]
+
+class PodAgeInformation(dict):
+ """Information about a pod age
+ """
+ __slots__ = ()
+
+ def __init__(self, __registry=_podRegistry, **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'):
+ if key not in self:
+ raise KeyError(key)
+ __registry.register(self)
+
+ def __getattribute__(self, name):
+ if name in self:
+ return self[name]
+ else:
+ dict.__getattribute__(self, name)
+
+class PodAgeTime(object):
+ """A pod age day cycle and gate event timer
+ """
+ def __init__(self, name):
+ """
+ @param name: Registered name of a pod age
+ @type name: str
+ """
+ if isinstance(name, basestring):
+ age = getPodAge(name)
+ elif isinstance(name, int):
+ age = getPodAgeByNumber(name)
+ else:
+ raise TypeError(name)
+ if age is None:
+ raise ValueError("Unknown age: %s" % name)
+ self._age = age
+ self._name = age.name
+ self.setStart()
+
+ def setStart(self, startdt=None):
+ """Set start date from when the calculations are started
+
+ Internally the date of the last cycle is stored
+
+ @param startdt: date to start counting (None: now)
+ @type startdt: datetime instance or None
+ @return: None
+ """
+ if startdt is None:
+ startdt = utcnow()
+ # 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
+
+ def get(self, count=1):
+ """Get date by count
+
+ @param count: number of cycles from start date
+ @type count: int
+ @return: date and time of next event
+ @rtype: datetime instance
+ """
+ delta = count * self._age.daycycle
+ return self._base + delta
+
+ def __iter__(self):
+ """Iterate through events
+
+ @return: Iterator that yields (number, date)
+ @rtype: iterator (int, datetime)
+ """
+ delta = self._age.daycycle
+ dt = self._base + delta
+ n = 0
+ while True:
+ yield (n, dt)
+ dt += delta
+ n += 1
+
+# pod ages
+pod18 = PodAgeInformation(name = 'Negilahn', gatenumber = 18,
+ base_dt = datetime(2007, 3, 4, 10, 16, 0, tzinfo=UTC))
+
+if __name__ == '__main__':
+ padneg = PodAgeTime('Negilahn')
+ for n, dt in iter(padneg):
+ print n, dt
+ if n > 20:
+ break
Property changes on: pymoul/trunk/src/moul/time/podage.py
___________________________________________________________________
Name: svn:keywords
+ 'Id Revision'
Name: svn:eol-style
+ native
Added: pymoul/trunk/src/moul/time/tests/test_podage.py
===================================================================
--- pymoul/trunk/src/moul/time/tests/test_podage.py (rev 0)
+++ pymoul/trunk/src/moul/time/tests/test_podage.py 2007-03-08 02:42:59 UTC (rev 242)
@@ -0,0 +1,37 @@
+# pyMoul - Python interface to Myst Online URU Live
+# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de>
+
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 2 of the License, or (at your
+# option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc., 59
+# Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""moul.time.podage unit tests
+"""
+__author__ = "Christian Heimes"
+__version__ = "$Id: test_dni.py 122 2007-02-02 17:34:06Z tiran $"
+__revision__ = "$Revision: 122 $"
+
+import os
+import unittest
+from doctest import DocTestSuite
+
+import moul.time.podage
+
+
+def test_suite():
+ return unittest.TestSuite((
+ DocTestSuite('moul.time.podage'),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest="test_suite")
Property changes on: pymoul/trunk/src/moul/time/tests/test_podage.py
___________________________________________________________________
Name: svn:keywords
+ 'Id Revision'
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|