summaryrefslogtreecommitdiff
path: root/tools/mmd/MmdWidgets.py
blob: 89e04b0850a8b6b384ad86dee84a9a705c5925fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
"""
web widgets for MURSAT1 Dashboard
"""

import time
import ephem
from MmdLocation import Location

def createJavaArray (point_list, name):
  astring = '''var {0} = new Array (\n'''.format (name)
  astring = '{0}\tnew Array ('.format (astring)
  last = 'west'

  for point in point_list:
    if point[0][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, point[0], point[1])
  if astring[-1] == ',':
    astring = astring[:-1]
  astring = '{0}\n\t\t)\n\t);'.format (astring)
  return astring

def dms2degdec (lonlat):
  parts = lonlat.split (':')
  if len (parts) != 3:
    return 0.0
  degrees = float (parts[0])
  fraction =  (float (parts[1]) * 60.0 + float (parts[2])) / 3600
  if parts[0][0] == '-':
    return degrees - fraction
  return degrees + fraction

def computeTrajectory (longitude, latitude, elevation):
  """
  test for static TLE to trajectory computation
  """

  line0 = "ARISSAT-1/RADIOSCAF-B"
  line1 = "1 37772U 98067CK  11220.22334818  .00031592  00000-0  37647-3 0   118"
  line2 = "2 37772  51.6391 258.8215 0013530  58.1430  19.7106 15.60689826   619"

  sat = ephem.readtle (line0, line1, line2)
  graz = ephem.Observer ()
  graz.long, graz.lat, graz.elevation = longitude, latitude, elevation

  sat.compute (graz)
  point_list = [(str (dms2degdec (sat.sublong.__str__ ())), str (dms2degdec (sat.sublat.__str__ ())))]

  # calculate points for next three hours
  for i in range (60 * 3):
    graz.date += ephem.minute
    sat.compute (graz)
    point_list.append (
      (str (dms2degdec (sat.sublong.__str__ ())), str (dms2degdec (sat.sublat.__str__ ())))
      )

  return  point_list[0][0], point_list[0][1], createJavaArray (point_list, 'curves')

def loginFormWidget ():
  html = '''
   Please enter your email and password in the form below.
   <form method="post" accept-charset="UTF-8">
    <table>
     <tr><td class="formfield">Email:</td><td><input type="text" name="email" /></td></tr>
     <tr><td class="formfield">Password:</td><td><input type="password" name="password" /></td></tr>
     <tr><td class="formfield"><input type="submit" value="login" /></td><td></td></tr>
     <!-- <tr><td class="formfield"><input type="submit" value="login" disabled="disabled" /></td><td></td></tr> -->
    </table>
    <input type="hidden" name="cmd" value="login" />
   </form>
   Don't have an account yet?  <a href="?cmd=registerForm">Register</a> here!
  '''

  return html

def loginWidget (user):
  html = '''
  <h3>Hello {0} {1}!</h3>
  <div>
   You are now logged on to MMD.
  </div>
  '''.format (user.firstname, user.lastname)

  return html

def logoutWidget ():
  html = '''
  <div>
   You have been logged out.
  </div>
  '''

  return html

def registerFormWidget ():
  html = '''
   Please fill in the form below and click on register.  You will receive a confirmation email.
   <form method="post" accept-charset="UTF-8">
    <table>
     <tr><td class="formfield">Firstname*:</td><td><input type="text" name="firstname" /></td></tr>
     <tr><td class="formfield">Lastname*: </td><td><input type="text" name="lastname" /></td></tr>
     <tr><td class="formfield">Email*: </td><td><input type="text" name="email" /></td></tr>
     <tr><td class="formfield">Callsign: </td><td><input type="text" name="callsign" /></td></tr>
     <tr><td class="formfield">Password*: </td><td><input type="password" name="password" /></td></tr>
     <tr><td class="formfield">Confirm Password*: </td><td><input type="password" name="confirm" /></td></tr>
     <tr><td colspan="2">You can enter your prefered location if you wish</td></tr>
     <tr><td class="formfield">Name: </td><td><input type="text" name="location_name" /></td></tr>
     <tr><td class="formfield">Longitude: </td><td><input type="text" name="latitude" /></td></tr>
     <tr><td class="formfield">Latitude: </td><td><input type="text" name="longitude" /></td></tr>
     <!-- <tr><td class="formfield"><input type="submit" value="Register" disabled="disabled" /></td><td></td></tr> -->
     <tr><td class="formfield"><input type="submit" value="register" /></td><td></td></tr>
    </table>
    <input type="hidden" name="cmd" value="register" />
   </form>
   Fields marked with a * are mandatory.
  '''

  return html

def registerWidget ():
  html = '''
  <h3>Thank you for registering!</h3>
  <div>
   You will receive an email containing a link to complete your registration.  This link will stay valid for 24 hours.
  </div>
  <div>
   Regards from the MURSAT1 team
  </div>
  '''

  return html

def completeRegistrationWidget (code):
  html = '''
  <h3>Completing registration!</h3>
  <div>
   By clicking <a href="?cmd=confirmRegistration&code={0}">confirm</a> you confirm you registration to the MURSAT1 Mission Dashboard.  If you received an email that brought you here but never registered, you might want to <a href="?cmd=cancelRegistration&code={0}">cancel</a> the registration or simply do nothing since a registration code is only valid vor 24 hrs.
  </div>
  <div>
   Greetings from the MURSAT1 Team!
  </div>
  '''.format (code)

  return html

def confirmRegistrationWidget (user):
  html = '''
  <h3>Dear {0} {1}!</h3>
   <div>
    Thank you for participating in this project by registerting here!  We are looking forward to receiving your reports from MURSAT1.
   </div>
   <div>
    Sessions here stay valid for 48 hours after your last click.  If your session expires, just use your email and password to logon again using this link: <a href="http://hofos.at/mmd/?cmd=login">http://hofos.at/mmd/?cmd=login</a>.
   </div>
   <div>
    Greetings from the MURSAT1 team
   </div>
   '''.format (user.firstname, user.lastname)

  return html

def cancelRegistrationWidget ():
  html = '''
  <h3>We are sorry!</h3>
  <div>
   Your registration has been canceled and all the data has been deleted from our records.
  </div>
  <div>
   Regards from the MURSAT1 team
  </div>
  '''

  return html

def errorWidget (error_message):
  html = '''
  <h3>An error occured!</h3>
  <div>Error: {0}</div>
  <div>Description: {1}</div>
  '''.format (error_message['error'], error_message['description'])

  return html

def submitFormWidget ():
  html = '''
  sorry, no form yet!
  '''
  
  return html

def submitWidget ():
  html = '''
  need processing of data
  '''

  return html

def logWidget ():
  html = '''
  Log data, lot's of log data ...
  '''

  return html

def osmWidget (session):
  user_location = session.user.getDefaultLocation ()
  if not user_location:
    user_location = Location ()
  minutes_preview = 180

  html = '''
  <div id="osm"></div>
  <script src="http://www.openlayers.org/api/OpenLayers.js"></script>
  <script type="text/javascript">
    // satellite and user position
    var from = new OpenLayers.Projection ("EPSG:4326");
    var to = new OpenLayers.Projection ("EPSG:900913");
    var sat_position = new OpenLayers.LonLat ({0}, {1}).transform (from, to);
    var user_location = new OpenLayers.LonLat ({2}, {3}).transform (from, to);

    // create a map
    var map = new OpenLayers.Map ("osm");
    map.addLayer (new OpenLayers.Layer.OSM ());

    // create a markers
    var markersLayer = new OpenLayers.Layer.Markers ("Markers");
    var sat = new OpenLayers.Marker (sat_position);
    var user = new OpenLayers.Marker (user_location);
    user.setOpacity (0.5);
    map.addLayer (markersLayer);
    markersLayer.addMarker (sat);
    markersLayer.addMarker (user);

    // array build by python ;)
    {4}

    // points/polygons
    var lineLayer = new OpenLayers.Layer.Vector ("Polygons");
    map.addLayer (lineLayer);
    // map.addControl (new OpenLayers.Control.DrawFeature(lineLayer, OpenLayers.Handler.Path));
    var Features = new Array ();
    // var colors = new Array ('#ff0000', '#00ff00', '#0000ff');

    for (var i = 0; i < curves.length; i++)
    {{
      var points = new Array ();
      for (var j = 0; j < curves[i].length; j++)
      {{
        points.push (new OpenLayers.Geometry.Point (curves[i][j].lon, curves[i][j].lat));
      }}
      var c = i % 3;
      var lineStyle = {{strokeColor: '#003366', strokeOpacity: 1, strokeWidth: 1}};
      Features.push (new OpenLayers.Feature.Vector (new OpenLayers.Geometry.LineString (points), null, lineStyle))
    }}

    lineLayer.addFeatures (Features);

    // zoom to world view
    map.zoomTo (1);
    
  </script>
  <div class="info">
   The map shows the satellite's expected ground track for the next {5} minutes.
  </div>
  '''.format (
    session.satellite.longitude,
    session.satellite.latitude,
    user_location.longitude,
    user_location.latitude,
    session.satellite.getTrajectoryAsJavaArray ('curves', minutes_preview),
    minutes_preview
    )

  return html

def statusWidget (session):
  if session.status == 'auth':
    inout = '''Status: logged in as {0}. <span id="logout"><a href="?cmd=logout">logout</a></span>'''.format (session.user.email)
  else:
    inout = '''Status: logged out. <span id="login"><a href="?cmd=loginForm">login</a></span>'''
  html = '''
   <a href="/mmd/">
    <img src="http://sat.mur.at/pics/sat-logo-notext.png" alt="mur.sat logo" />
   </a>
   MURSAT1 Mission Dashboard
   <div class="info">
    {0}. Local time is {1}.
   </div>
  '''.format (inout, time.strftime ('%c'))

  return html

def indexWidget (lcol, rcol, status, debug_info = False):
  if debug_info:
    user_location = debug_info.user.getDefaultLocation ()
    if not user_location:
      user_location = Location ()
    debug = '''
    <pre class="debug">
     Debug Info
     ==========
     SESSION:
     SessionId: {0}
     IP: {1}
     Email: {2}
     Status: {3}
     Expires: {4}
     Renewal: {5}
     Now: {6}
     =====
     USER:
     User's Location Name: {7}
     Longitude: {8}
     Latitude: {9}
     ==========
     SATELLITE:
     Latest SSP: {10}
    </pre>
    '''.format (
      debug_info.session_id,
      debug_info.ip,
      debug_info.user.email,
      debug_info.status,
      debug_info.expires,
      debug_info.renewal,
      time.strftime ('%s'),
      user_location.name,
      user_location.longitude,
      user_location.latitude,
      debug_info.satellite.getLatestSSP()['timestamp'])
  else:
    debug = ''

  html = '''
<!Doctype html>
<html>
 <head>
  <title>MURSAT1 Dashboard</title>
  <meta charset="utf-8" />
  <link rel="stylesheet" type="text/css" href="static/mmd.css" />
 </head>
 <body>
  <div id="status">
   {0}
  </div>
  <div id="lcol">
   {1}
  </div>
  <div id="rcol">
   {2}
  </div>
  <div id="dev">
   Development version!  Tracking <a href="http://www.arissat1.org/v3/">ARISSAT-1</a> for now ;)
  </div>
   {3}
 </body>
</html>
  '''.format (status, lcol, rcol, debug)

  return html

def dataWidget (session):
  timestamp, longitude, latitude = session.satellite.getCurrentSSP ()

  html = '''
   <div id="datahead">
    {0}
   </div>
   <hr />
   <div>Time: 00 D 00 H 00 M 00 S</div>
   <div title="Longitude of sub satellite point in degrees east/west of Greenwich">SSP Longitude: {1}</div>
   <div title="Latitude of sub satellite point in degrees north/south o equator">SSP Latitude: {2}</div>
   <div title="Satellite's altitude above sea level in meters">Altitude: {3}m</div>
   <hr />
   <div><a href="?cmd=submitForm">Submit</a> a report</div>
   <div>View <a href="?cmd=viewlog">Log</a> of reports</div>
   <hr />
   <div>Checkout the <a href="http://sat.mur.at/">project page</a>!</div>
  '''.format (session.satellite.name, session.satellite.longitude, session.satellite.latitude, session.satellite.altitude)
  
  return html

if __name__ == "__main__":
  pass

# vim: ft=html tw=0 ts=2 expandtab
# EOF