From d07617fd3fb065a304ecdd53096e45954d07ee1e Mon Sep 17 00:00:00 2001 From: Jogi Hofmüller Date: Thu, 11 Aug 2011 08:45:41 +0000 Subject: - more Satellite code git-svn-id: https://svn.spreadspace.org/mur.sat@120 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- tools/mmd/MmdDb.py | 11 +++++++++++ tools/mmd/MmdSatellite.py | 20 ++++++++++++++++---- tools/mmd/TODO | 11 +++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) (limited to 'tools') diff --git a/tools/mmd/MmdDb.py b/tools/mmd/MmdDb.py index 74b11bd..aa6ff03 100644 --- a/tools/mmd/MmdDb.py +++ b/tools/mmd/MmdDb.py @@ -122,6 +122,17 @@ class Db: self.cursor.execute ('INSERT INTO ssps (timestamp, longitude, latitude) VALUES (?,?,?)', (timestamp, longitude, latitude,)) self.conn.commit () + def satelliteLoadTrajectory (self, timestamp, count): + ''' + get count rows from table ssps, starting at >= timestamp + ''' + self.cursor.execute ('SELECT * FROM ssps WHERE timestamp >=? ORDER BY timestamp ASC LIMIT ?', (timestamp, count,)) + return self.cursor.fetchall () + + def satelliteLoadCurrentSSP (self, timestamp): + self.cursor.execute ('SELECT * FROM ssps WHERE timestamp >=? LIMIT 1', (timestamp,)) + return self.cursor.fetchone () + def close (self): self.cursor.close () self.conn.close () diff --git a/tools/mmd/MmdSatellite.py b/tools/mmd/MmdSatellite.py index 1575648..8085773 100644 --- a/tools/mmd/MmdSatellite.py +++ b/tools/mmd/MmdSatellite.py @@ -47,16 +47,18 @@ class Satellite: self.db = Db () def getCurrentSSP (self): - pass + ssp = self._loadCurrentSSP () + return ssp['timestamp'], ssp['longitude'], ssp['latitude'] def getTrajectoryAsJavaArray (self, minutes = 180): - pass + # FIXME include java array code here + return self._loadTrajectory (minutes) def _loadTrajectory (self, minutes): - pass + return self.db.satelliteLoadTrajectory (time.strftime ('%s'), minutes) def _loadCurrentSSP (self): - pass + return self.db.satelliteLoadCurrentSSP (time.strftime ('%s')) def computeTrajectory (self): sat = ephem.readtle (self._tle[0], self._tle[1], self._tle[2]) @@ -96,10 +98,20 @@ class Satellite: if __name__ == "__main__": satellite = Satellite () + minutes = 30 try: assert satellite._loadTLE (), 'loading TLE failed' print satellite._tle assert satellite.computeTrajectory (), 'computing trajectory failed' + trajectory = satellite.getTrajectoryAsJavaArray (minutes) + assert trajectory, 'got not trajectory' + assert len (trajectory) == minutes, 'count={0}, minutes={1}'.format (len (trajectory), minutes) + print time.strftime ('%c', time.gmtime (float (time.strftime ('%s')))), time.strftime ('%s') + for t in trajectory: + print t['timestamp'], time.strftime ('%c', time.gmtime (t['timestamp'])) + t, lon, lat = satellite.getCurrentSSP () + assert t, 'loading current SSP failed' + print lon, lat, time.strftime ('%c', time.gmtime (t)) except AssertionError as e: print 'Error: {0}'.format (e) diff --git a/tools/mmd/TODO b/tools/mmd/TODO index cc5341d..c0ef046 100644 --- a/tools/mmd/TODO +++ b/tools/mmd/TODO @@ -1,10 +1,13 @@ Things to do for completing this app +- satellite + - add retreival of current SSP + - add trajectory to class + - registration - - add user's location data - - change the registration form - - complete class Location - - make class LocationList + - add location.altitude + - complete class Location + - make class LocationList - user - change profile data (password) -- cgit v1.2.3