Example #1
0
    def GET(self):
        '''Usage: via web.py, e.g. http://fish/live/avaps'''
        web.header('Content-Type', 'text/plain', unique=True)
        web.header('Cache-control', 'no-cache')
        conn = get_database()
        cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
        parser = DecadesConfigParser()
        calfile = parser.get('Config', 'calfile')
        rtlib = rt_derive.derived(cur, calfile)

        #get data
        data = rtlib.derive_data_alt([
            'time_since_midnight', 'utc_time', 'pressure_height_m',
            'static_pressure', 'gin_latitude', 'gin_track_angle',
            'gin_longitude', 'gin_heading', 'gin_d_velocity', 'gin_altitude',
            'gin_speed', 'true_air_speed', 'deiced_true_air_temp_c',
            'dew_point', 'gin_wind_speed', 'wind_angle'
        ], '=id', 'ORDER BY id DESC LIMIT 1')
        #each entry is a length=1 list, so flatten
        for each in data:
            data[each] = data[each][0]

        data['utc_time'] = datetime.fromtimestamp(
            data['utc_time'], timezone('utc')).strftime('%H:%M:%S')
        del data[
            'time_since_midnight']  #as that is needed by derive_data_alt but not in teh return

        return json.dumps(data)  #in *no particular order*
Example #2
0
    def __init__(self):
        self.parser = DecadesConfigParser()

        self.conn = get_database()
        self.cur = self.conn.cursor(
            cursor_factory=psycopg2.extras.NamedTupleCursor)
        self.db = web.database(dbn='postgres',
                               host=self.parser.get('Database', 'host'),
                               db=self.parser.get('Database', 'database'),
                               user=self.parser.get('Database', 'user'),
                               pw=self.parser.get('Database', 'password'))

        self.output_dir = self.parser.get('Config', 'output_dir')
        self.calfile = self.parser.get('Config', 'calfile')
        self.rtlib = rt_derive.derived(self.cur, self.calfile)
Example #3
0
    def __init__(self):
        '''Takes a database connection, and creates a cursor'''
        self.conn = get_database()
        self.cursor = self.conn.cursor(
            cursor_factory=psycopg2.extras.NamedTupleCursor)
        self.output_dir = self.parser.get('Config', 'output_dir')
        #interprets the mode as an octal int
        self.calfile = self.parser.get('Config', 'calfile')
        self.rtlib = rt_derive.derived(self.cursor, self.calfile)
        self.output_create_mode = int(
            self.parser.get('Config', 'output_create_mode'), 8)
        self.conditions = '=id'
        self.orderby = ' ORDER BY utc_time DESC LIMIT 1'
        self.readparas = [
            "flight_number", "static_pressure", "deiced_true_air_temp_c",
            "true_air_speed_ms"
        ]
        #self.writeparas={"sea_twc_v":2,"sea_twc_i":3,"sea_twc_t":4,"sea_083_v":6,"sea_083_i":7,"sea_083_t":8,
        #                 "sea_021_v":10,"sea_021_i":11,"sea_021_t":12,"sea_cmp_v":14,"sea_cmp_i":15,"sea_cmp_t":16 }  # Raw parameters
        self.writeparas = {"sea_twc": 2, "sea_lwc083": 4, "sea_lwc021": 6}

        #details of UDP multicast group for sending SEA output in UDP packet
        self.host = "239.1.4.6"
        self.port = 50001
Example #4
0
    def GET(self):
        web.header('Content-Type', 'text/html; charset=utf-8', unique=True)
        web.header('Cache-control', 'no-cache')
        conn = get_database()
        cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
        parser = DecadesConfigParser()
        calfile = parser.get('Config', 'calfile')
        rtlib = rt_derive.derived(cur, calfile)

        #get stat data (taken directly from pydecades/decades_server.py)
        prtgindata = rtlib.derive_data_alt([
            'time_since_midnight', 'utc_time', 'derindex', 'flight_number',
            'pressure_height_kft', 'static_pressure', 'gin_latitude',
            'gin_longitude', 'gin_heading'
        ], '=id', 'ORDER BY id DESC LIMIT 1')
        #get corcon separately so gin/prt stuff is independant of it.
        corcondata = rtlib.derive_data_alt([
            'time_since_midnight', 'utc_time', 'derindex', 'true_air_speed',
            'deiced_true_air_temp_c', 'dew_point', 'gin_wind_speed',
            'wind_angle'
        ], '=id', 'ORDER BY id DESC LIMIT 1')

        #open output div
        output = u'<div id="statblock">'
        if (corcondata['time_since_midnight']
                and abs(corcondata['derindex'] - prtgindata['derindex']) < 10):
            output = output + u'<p>Flight %s %s</p>' % (
                prtgindata['flight_number'][0],
                datetime.utcfromtimestamp(
                    prtgindata['utc_time']).strftime('%H:%M:%SZ'))
            output = output + (
                u'<p>Heading %.0f° Speed %.0fkts Height %.0fkft Pressure %.0fmb</p>'
                % (prtgindata['gin_heading'], corcondata['true_air_speed'],
                   prtgindata['pressure_height_kft'],
                   prtgindata['static_pressure']))
            output = output + (
                u'<p>Lat %.0f°%.0f\'%.2f" Long %.0f°%.0f\'%.2f" Wind %.1fms¯¹ / %.0f°</p>'
                % tuple(
                    self.deg_to_dms(prtgindata['gin_latitude']) +
                    self.deg_to_dms(prtgindata['gin_longitude']) +
                    [corcondata['gin_wind_speed'], corcondata['wind_angle']]))
            output = output + (u'<p>Temp %.1f°C Dewpoint %.1f°C</p>' %
                               (corcondata['deiced_true_air_temp_c'],
                                corcondata['dew_point']))
        elif (prtgindata['time_since_midnight']):
            output = output + u'<p>Flight %s %s</p>' % (
                prtgindata['flight_number'][0],
                datetime.utcfromtimestamp(
                    prtgindata['utc_time']).strftime('%H:%M:%SZ'))
            output = output + (
                u'<p>Heading %.0f° Speed %.0fkts Height %.0fkft Pressure %.0fmb</p>'
                % (prtgindata['gin_heading'], float('NaN'),
                   prtgindata['pressure_height_kft'],
                   prtgindata['static_pressure']))
            output = output + (
                u'<p>Lat %.0f°%.0f\'%.2f" Long %.0f°%.0f\'%.2f" Wind %.1fms¯¹ / %.0f°</p>'
                % tuple(
                    self.deg_to_dms(prtgindata['gin_latitude']) +
                    self.deg_to_dms(prtgindata['gin_longitude']) +
                    [float('NaN'), float('NaN')]))
            output = output + (u'<p>Temp %.1f°C Dewpoint %.1f°C</p>' %
                               (float('NaN'), float('NaN')))
        else:
            output = output + u'<p>Flight ####</p>'
        #close output div
        output = output + u'</div>'

        return output
Example #5
0
 def setUp(self):
     factory = DecadesFactory(get_database(),
                              parser.get('Config', 'calfile'))
     self.proto = factory.buildProtocol('128.0.0.1')
Example #6
0
    def GET(self):
        '''Usage: via web.py, e.g. http://fish/live/livejson'''
        web.header('Content-Type',
                   'application/json; charset=utf-8',
                   unique=True)
        web.header('Cache-control', 'no-cache')
        web.header('Access-Control-Allow-Origin', '*')
        conn = get_database()
        cur = conn.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
        parser = DecadesConfigParser()
        calfile = parser.get('Config', 'calfile')
        rtlib = rt_derive.derived(cur, calfile)
        user_data = web.input(para=[])
        if len(user_data.para) == 0:
            #no paras sent, send default
            parameters = self.default
        else:
            parameters = filter(None, user_data.para)  #strips empty entries

        if 'javascript_time' in parameters:
            parameters.remove('javascript_time')  #strips javascript time
            #as it is computed below.
        conditions = '=id '
        orderby = 'ORDER BY id DESC LIMIT 1'
        if user_data.has_key('to') and user_data.to > '':
            try:
                #sanitise (coerce to INT)
                to = int(user_data.to)
                conditions = conditions + 'AND utc_time <=%s ' % to
                orderby = 'ORDER BY id'
            except ValueError:
                #can't be converted to integer, ignore
                pass

        if user_data.has_key('frm') and user_data.frm > '':
            try:
                #sanitise (coerce to INT)
                frm = int(user_data.frm)
                conditions = conditions + 'AND utc_time >=%s ' % frm
                orderby = 'ORDER BY id LIMIT 36000'  #i.e. 10 hrs
            except ValueError:
                #can't be converted to integer, ignore
                pass

            #get data
        data = rtlib.derive_data_alt(self.always + parameters, conditions,
                                     orderby)
        keylist = data.keys()
        #loop over records, make each record self-contained
        dataout = []
        for n in range(0, len(data[keylist[0]])):
            dataout.append({})
            for each in keylist:
                if not (np.isnan(data[each][n])):  #don't return NaNs
                    dataout[n][each] = np.asscalar(data[each][n])
                #else:
                #   del dataout[n];
                #   break; #go on to next entry
            #Javascript time is in integer milliseconds
            dataout[n]['javascript_time'] = dataout[n]['utc_time'] * 1000

        #data['utc_time'] = datetime.fromtimestamp(data['utc_time'],timezone('utc')).strftime('%H:%M:%S')
        return json.dumps(dataout, allow_nan=False)  #in *no particular order*