""" 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.

*

*

Don't have an account yet? Register here!
''' return html def loginWidget (user): html = '''

Hello {0} {1}!

You are now logged on to MMD.
'''.format (user.firstname, user.lastname) return html def logoutWidget (): html = '''
You have been logged out.
''' return html def registerFormWidget (): html = '''
Please fill in the form below and click on register.

*

*

*

 

*

*

 

 

*

*

 

Fields marked with * are mandatory.
''' return html def registerWidget (): html = '''

Thank you for registering!

You will receive an email containing a link to complete your registration. This link will stay valid for 24 hours.
Regards from the MURSAT1 team
''' return html def completeRegistrationWidget (code): html = '''

Completing registration!

By clicking confirm 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 cancel the registration or simply do nothing since a registration code is only valid vor 24 hrs.
Greetings from the MURSAT1 Team!
'''.format (code) return html def confirmRegistrationWidget (user): html = '''

Dear {0} {1}!

Thank you for participating in this project by registerting here! We are looking forward to receiving your reports from MURSAT1.
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: http://hofos.at/mmd/?cmd=login.
Greetings from the MURSAT1 team
'''.format (user.firstname, user.lastname) return html def cancelRegistrationWidget (): html = '''

We are sorry!

Your registration has been canceled and all the data has been deleted from our records.
Regards from the MURSAT1 team
''' return html def creditsWidget (): html = '''
Thanks to OpenStreetMap for this great project. Plotting the trajectory would not have been possible without OpenLayers JavaScript Mapping Library and the PyEphem module to compute astronomical data.
''' return html def errorWidget (error_message): html = '''

An error occured!

Error: {0}
Description: {1}
'''.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 () html = ''' '''.format ( user_location.name, user_location.longitude, user_location.latitude, user_location.altitude ) return html # def osmWidget (session): # user_location = session.user.getDefaultLocation () # if not user_location: # user_location = Location () # minutes_preview = 180 # # html = ''' #
# # #
# The map shows the satellite's expected ground track for the next {5} minutes. #
# '''.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}. logout'''.format (session.user.email) else: inout = '''Status: logged out. login''' html = ''' mur.sat logo MURSAT1 Mission Dashboard
{0}. Local time is {1}.
'''.format (inout, time.strftime ('%c')) return html def indexWidget (rcol, lcol, status, debug_info = False): if debug_info: user_location = debug_info.user.getDefaultLocation () if not user_location: user_location = Location () 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}
    
'''.format ( debug_info.session_id, debug_info.ip, debug_info.user.email, debug_info.status, time.strftime ('%c', time.localtime (float (debug_info.expires))), time.strftime ('%c', time.localtime (float (debug_info.renewal))), time.strftime ('%c'), user_location.name, user_location.longitude, user_location.latitude, time.strftime ('%c', time.localtime (float (debug_info.satellite.getLatestSSP()['timestamp'])))) else: debug = '' html = ''' MURSAT1 Dashboard
{0}
{1}
{2}
Development version. Kindly ignore everything below this line.
{3} '''.format (status, lcol, rcol, debug) return html def menuWidget (session): html = ''' '''.format (session.message) return html def dataWidget (session): timestamp, longitude, latitude = session.satellite.getCurrentSSP () html = '''
{0}

Time: 00 D 00 H 00 M 00 S
SSP Longitude: {1}
SSP Latitude: {2}
Altitude: {3}m

Submit a report
View Log of reports

Checkout the project page!
'''.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