summaryrefslogtreecommitdiff
path: root/tools/mmd
diff options
context:
space:
mode:
authorJogi Hofmüller <jogi@mur.at>2011-08-11 11:36:21 +0000
committerJogi Hofmüller <jogi@mur.at>2011-08-11 11:36:21 +0000
commit4c4e979a95eaaf4d07bae728cedef2e9ccc274aa (patch)
treeaf836f572d44acf8a54449e9c0f5d625c15c96e1 /tools/mmd
parent- more Satellite code (diff)
- more Satellite code
- rounding longitude and latitude to 10^-5 now - added java array creation to class Satellite - included class satellite in osmWidget () git-svn-id: https://svn.spreadspace.org/mur.sat@121 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'tools/mmd')
-rw-r--r--tools/mmd/MmdCommands.py2
-rw-r--r--tools/mmd/MmdSatellite.py43
-rw-r--r--tools/mmd/MmdSession.py2
-rw-r--r--tools/mmd/MmdWidgets.py17
-rw-r--r--tools/mmd/TODO4
5 files changed, 43 insertions, 25 deletions
diff --git a/tools/mmd/MmdCommands.py b/tools/mmd/MmdCommands.py
index c1dbeb9..410acfe 100644
--- a/tools/mmd/MmdCommands.py
+++ b/tools/mmd/MmdCommands.py
@@ -130,7 +130,7 @@ def index (session):
display the index page
"""
satellite = {'longitude': 15.4426, 'latitude': 47.06576}
- return indexWidget (dataWidget (), osmWidget (satellite, session.user), statusWidget (session), session)
+ return indexWidget (dataWidget (), osmWidget (session), statusWidget (session), session)
def mmdtest (env, cookie):
body = ''
diff --git a/tools/mmd/MmdSatellite.py b/tools/mmd/MmdSatellite.py
index 8085773..67a9052 100644
--- a/tools/mmd/MmdSatellite.py
+++ b/tools/mmd/MmdSatellite.py
@@ -27,7 +27,7 @@ def createJavaArray (point_list, name):
def dms2degdec (lonlat):
'''
convert a position argument from Deg:Min:Sec.Frac to
- Deg.Frac
+ Deg.Frac and round the result to 5 decimal points
'''
parts = lonlat.split (':')
@@ -36,8 +36,8 @@ def dms2degdec (lonlat):
degrees = float (parts[0])
fraction = (float (parts[1]) * 60.0 + float (parts[2])) / 3600
if parts[0][0] == '-':
- return degrees - fraction
- return degrees + fraction
+ return round (degrees - fraction, 5)
+ return round (degrees + fraction, 5)
class Satellite:
@@ -50,9 +50,26 @@ class Satellite:
ssp = self._loadCurrentSSP ()
return ssp['timestamp'], ssp['longitude'], ssp['latitude']
- def getTrajectoryAsJavaArray (self, minutes = 180):
- # FIXME include java array code here
- return self._loadTrajectory (minutes)
+ def getTrajectoryAsJavaArray (self, name, minutes = 180):
+ astring = '''var {0} = new Array (\n'''.format (name)
+ astring = '{0}\tnew Array ('.format (astring)
+ last = 'west'
+
+ for row in self._loadTrajectory (minutes):
+ if str (row['longitude'])[0] == '-':
+ if last == 'east':
+ astring = astring[:-1]
+ astring = '{0}\n\t\t),\n\tnew Array ('.format (astring)
+ last = 'west'
+ else:
+ last = 'east'
+ astring = '{0}\n\t\tnew OpenLayers.LonLat ({1}, {2}).transform (from, to),'.format (
+ astring, row['longitude'], row['latitude'])
+ if astring[-1] == ',':
+ astring = astring[:-1]
+ astring = '{0}\n\t\t)\n\t);'.format (astring)
+ return astring
+
def _loadTrajectory (self, minutes):
return self.db.satelliteLoadTrajectory (time.strftime ('%s'), minutes)
@@ -61,6 +78,11 @@ class Satellite:
return self.db.satelliteLoadCurrentSSP (time.strftime ('%s'))
def computeTrajectory (self):
+ '''
+ computes 5 hours of future trajectory data, starting at the
+ latest timestamp found in data base
+ '''
+
sat = ephem.readtle (self._tle[0], self._tle[1], self._tle[2])
graz = ephem.Observer ()
graz.long, graz.lat, graz.elevation = 15.44226, 47.06576, 376
@@ -73,12 +95,10 @@ class Satellite:
while timestamp % 60 != 0:
timestamp += 1
- print graz.date
for i in range (60 * 5):
graz.date = time.strftime ('%Y/%m/%d %H:%M:%S', time.gmtime (timestamp))
sat.compute (graz)
self.db.satelliteInsertNewSSP (timestamp, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()))
- # print timestamp, dms2degdec (sat.sublong.__str__ ()), dms2degdec (sat.sublat.__str__ ()), graz.date, time.strftime ('%Y/%m/%d %H:%M:%S', time.localtime (timestamp))
timestamp += 60
return True
@@ -103,12 +123,9 @@ if __name__ == "__main__":
assert satellite._loadTLE (), 'loading TLE failed'
print satellite._tle
assert satellite.computeTrajectory (), 'computing trajectory failed'
- trajectory = satellite.getTrajectoryAsJavaArray (minutes)
+ trajectory = satellite.getTrajectoryAsJavaArray ('curves', 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']))
+ print trajectory
t, lon, lat = satellite.getCurrentSSP ()
assert t, 'loading current SSP failed'
print lon, lat, time.strftime ('%c', time.gmtime (t))
diff --git a/tools/mmd/MmdSession.py b/tools/mmd/MmdSession.py
index 801f089..848a342 100644
--- a/tools/mmd/MmdSession.py
+++ b/tools/mmd/MmdSession.py
@@ -4,6 +4,7 @@ Session class for MURSAT1 Mission Dashboard
from cgi import parse_qs, escape
from MmdDb import Db
from MmdUser import User
+from MmdSatellite import Satellite
import time
# session timeout set to 2 days
@@ -20,6 +21,7 @@ class Session:
self.headers = []
self.db = Db ()
self.user = User ()
+ self.satellite = Satellite ()
s = self.db.sessionFind (session_id)
if not s:
now = int (time.strftime ('%s'))
diff --git a/tools/mmd/MmdWidgets.py b/tools/mmd/MmdWidgets.py
index cd8a347..c725945 100644
--- a/tools/mmd/MmdWidgets.py
+++ b/tools/mmd/MmdWidgets.py
@@ -207,15 +207,12 @@ def logWidget ():
return html
-def osmWidget (satellite, user):
- user_location = user.getDefaultLocation ()
+def osmWidget (session):
+ user_location = session.user.getDefaultLocation ()
if not user_location:
user_location = Location ()
- longitude, latitude, java = computeTrajectory (user_location.longitude, user_location.latitude, 300)
+ timestamp, longitude, latitude = session.satellite.getCurrentSSP ()
- #
- # how can we use { and } in javascript that can be ignored by python format ()?
- #
html = '''
<div id="osm"></div>
<script src="http://www.openlayers.org/api/OpenLayers.js"></script>
@@ -267,7 +264,13 @@ def osmWidget (satellite, user):
map.zoomTo (1);
</script>
- '''.format (longitude, latitude, user_location.longitude, user_location.latitude, java)
+ '''.format (
+ longitude,
+ latitude,
+ user_location.longitude,
+ user_location.latitude,
+ session.satellite.getTrajectoryAsJavaArray (30)
+ )
return html
diff --git a/tools/mmd/TODO b/tools/mmd/TODO
index c0ef046..bf5858a 100644
--- a/tools/mmd/TODO
+++ b/tools/mmd/TODO
@@ -1,9 +1,5 @@
Things to do for completing this app
-- satellite
- - add retreival of current SSP
- - add trajectory to class
-
- registration
- add location.altitude
- complete class Location