def get(self, *args, **kwargs): """ GET request """ jsonlist = [] # get the logs (but only the public ones) con = sqlite3.connect(get_db_filename(), detect_types=sqlite3.PARSE_DECLTYPES) cur = con.cursor() # get vehicle name information from vehicle table cur.execute('select UUID, Name from Vehicle') db_tuples = cur.fetchall() vehicle_table = {db_tuple[0]: db_tuple[1] for db_tuple in db_tuples} cur.execute( 'select Id, Date, Description, WindSpeed, Rating, VideoUrl, ErrorLabels, ' 'Source, Feedback, Type from Logs where Public = 1') # need to fetch all here, because we will do more SQL calls while # iterating (having multiple cursor's does not seem to work) db_tuples = cur.fetchall() for db_tuple in db_tuples: jsondict = {} db_data = DBData() log_id = db_tuple[0] jsondict['log_id'] = log_id jsondict['log_date'] = db_tuple[1].strftime('%Y-%m-%d') db_data.description = db_tuple[2] db_data.wind_speed = db_tuple[3] db_data.rating = db_tuple[4] db_data.video_url = db_tuple[5] db_data.error_labels = sorted([int(x) for x in db_tuple[6].split(',') if len(x) > 0]) \ if db_tuple[6] else [] db_data.source = db_tuple[7] db_data.feedback = db_tuple[8] db_data.type = db_tuple[9] jsondict.update(db_data.to_json_dict()) db_data_gen = get_generated_db_data_from_log(log_id, con, cur) if db_data_gen is None: continue jsondict.update(db_data_gen.to_json_dict()) # add vehicle name jsondict['vehicle_name'] = vehicle_table.get( jsondict['vehicle_uuid'], '') airframe_data = get_airframe_data(jsondict['sys_autostart_id']) jsondict['airframe_name'] = airframe_data.get('name', '') \ if airframe_data is not None else '' jsondict['airframe_type'] = airframe_data.get('type', jsondict['sys_autostart_id']) \ if airframe_data is not None else jsondict['sys_autostart_id'] jsonlist.append(jsondict) cur.close() con.close() self.set_header('Content-Type', 'application/json') self.write(json.dumps(jsonlist))
def get_columns_from_tuple(db_tuple, counter): """ load the columns (list of strings) from a db_tuple """ db_data = DBData() log_id = db_tuple[0] log_date = db_tuple[1].strftime('%Y-%m-%d') db_data.description = db_tuple[2] db_data.feedback = '' db_data.type = '' db_data.wind_speed = db_tuple[3] db_data.rating = db_tuple[4] db_data.video_url = db_tuple[5] db_data_gen = get_generated_db_data_from_log(log_id, con, cur) if db_data_gen is None: return None # bring it into displayable form ver_sw = db_data_gen.ver_sw if len(ver_sw) > 10: ver_sw = ver_sw[:6] if len(db_data_gen.ver_sw_release) > 0: try: release_split = db_data_gen.ver_sw_release.split() release_type = int(release_split[1]) if release_type == 255: # it's a release ver_sw = release_split[0] except: pass airframe_data = get_airframe_data(db_data_gen.sys_autostart_id) if airframe_data is None: airframe = db_data_gen.sys_autostart_id else: airframe = airframe_data['name'] flight_modes = ', '.join([ flight_modes_table[x][0] for x in db_data_gen.flight_modes if x in flight_modes_table ]) m, s = divmod(db_data_gen.duration_s, 60) h, m = divmod(m, 60) duration_str = '{:d}:{:02d}:{:02d}'.format(h, m, s) # make sure to break long descriptions w/o spaces (otherwise they # mess up the layout) description = html_long_word_force_break(db_data.description) return [ counter, '<a href="plot_app?log=' + log_id + '">' + log_date + '</a>', description, db_data_gen.mav_type, airframe, db_data_gen.sys_hw, ver_sw, duration_str, db_data.rating_str(), db_data_gen.num_logged_errors, flight_modes ]
def label_callback(airframe_id, short): """ get the airframe label for the sys_autostart id """ if short: return airframe_id airframe_data = get_airframe_data(airframe_id) if airframe_data is None: airframe_label = airframe_id else: airframe_type = '' if 'type' in airframe_data: airframe_type = ', ' + airframe_data['type'] airframe_label = airframe_data.get('name')+ \ airframe_type+' ('+airframe_id+')' return airframe_label
def get(self): table_header = """ <thead> <tr> <th>#</th> <th>Upload Date</th> <th>Description</th> <th>Type</th> <th>Airframe</th> <th>Hardware</th> <th>Software</th> <th>Duration</th> <th>Rating</th> <th>Errors</th> <th>Flight Modes</th> </tr> </thead> <tbody> """ table_footer = "</tbody>" table_data = "" # get the logs (but only the public ones) con = sqlite3.connect(get_db_filename(), detect_types=sqlite3.PARSE_DECLTYPES) cur = con.cursor() cur.execute( 'select Id, Date, Description, WindSpeed, Rating, VideoUrl ' 'from Logs where Public = 1') # need to fetch all here, because we will do more SQL calls while # iterating (having multiple cursor's does not seem to work) db_tuples = cur.fetchall() counter = 1 for db_tuple in db_tuples: db_data = DBData() log_id = db_tuple[0] log_date = db_tuple[1].strftime('%Y-%m-%d') db_data.description = db_tuple[2] db_data.feedback = '' db_data.type = '' db_data.wind_speed = db_tuple[3] db_data.rating = db_tuple[4] db_data.video_url = db_tuple[5] # try to get the additional data from the DB cur.execute('select * from LogsGenerated where Id = ?', [log_id]) db_tuple = cur.fetchone() if db_tuple is None: # need to generate from file # Note that this is not necessary in most cases, as the entry is # also generated after uploading (but with a timeout) db_data_gen = generate_db_data_from_log_file(log_id, con) else: # get it from the DB db_data_gen = DBDataGenerated() db_data_gen.duration_s = db_tuple[1] db_data_gen.mav_type = db_tuple[2] db_data_gen.estimator = db_tuple[3] db_data_gen.sys_autostart_id = db_tuple[4] db_data_gen.sys_hw = db_tuple[5] db_data_gen.ver_sw = db_tuple[6] db_data_gen.num_logged_errors = db_tuple[7] db_data_gen.num_logged_warnings = db_tuple[8] db_data_gen.flight_modes = \ set([int(x) for x in db_tuple[9].split(',') if len(x) > 0]) db_data_gen.ver_sw_release = db_tuple[10] db_data_gen.vehicle_uuid = db_tuple[11] # bring it into displayable form ver_sw = db_data_gen.ver_sw if len(ver_sw) > 10: ver_sw = ver_sw[:6] if len(db_data_gen.ver_sw_release) > 0: try: release_split = db_data_gen.ver_sw_release.split() release_type = int(release_split[1]) if release_type == 255: # it's a release ver_sw = release_split[0] except: pass airframe_data = get_airframe_data(db_data_gen.sys_autostart_id) if airframe_data is None: airframe = db_data_gen.sys_autostart_id else: airframe = airframe_data['name'] flight_modes = ', '.join([ flight_modes_table[x][0] for x in db_data_gen.flight_modes if x in flight_modes_table ]) m, s = divmod(db_data_gen.duration_s, 60) h, m = divmod(m, 60) duration_str = '{:d}:{:02d}:{:02d}'.format(h, m, s) # make sure to break long descriptions w/o spaces (otherwise they # mess up the layout) description = html_long_word_force_break(db_data.description) table_data += """ <tr> <td>{counter}</td> <td><a href="plot_app?log={log_id}">{date}</a></td> <td>{description}</td> <td>{mav_type}</td> <td>{airframe}</td> <td>{hw}</td> <td>{sw}</td> <td>{duration}</td> <td>{rating}</td> <td>{num_errors}</td> <td>{flight_modes}</td> </tr> """.format(log_id=log_id, counter=counter, date=log_date, description=description, rating=db_data.rating_str(), wind_speed=db_data.wind_speed_str(), mav_type=db_data_gen.mav_type, airframe=airframe, hw=db_data_gen.sys_hw, sw=ver_sw, duration=duration_str, num_errors=db_data_gen.num_logged_errors, flight_modes=flight_modes) counter += 1 cur.close() con.close() template = _ENV.get_template(BROWSE_TEMPLATE) self.write( template.render(table_data=table_header + table_data + table_footer))
def get_columns_from_tuple(db_tuple, counter): """ load the columns (list of strings) from a db_tuple """ db_data = DBDataJoin() log_id = db_tuple[0] log_date = db_tuple[1].strftime('%Y-%m-%d') db_data.description = db_tuple[2] db_data.feedback = '' db_data.type = '' db_data.wind_speed = db_tuple[3] db_data.rating = db_tuple[4] db_data.video_url = db_tuple[5] generateddata_log_id = db_tuple[6] if log_id != generateddata_log_id: print('Join failed, loading and updating data') db_data_gen = get_generated_db_data_from_log(log_id, con, cur) if db_data_gen is None: return None db_data.add_generated_db_data_from_log(db_data_gen) else: db_data.duration_s = db_tuple[7] db_data.mav_type = db_tuple[8] db_data.estimator = db_tuple[9] db_data.sys_autostart_id = db_tuple[10] db_data.sys_hw = db_tuple[11] db_data.ver_sw = db_tuple[12] db_data.num_logged_errors = db_tuple[13] db_data.num_logged_warnings = db_tuple[14] db_data.flight_modes = \ {int(x) for x in db_tuple[15].split(',') if len(x) > 0} db_data.ver_sw_release = db_tuple[16] db_data.vehicle_uuid = db_tuple[17] db_data.flight_mode_durations = \ [tuple(map(int, x.split(':'))) for x in db_tuple[18].split(',') if len(x) > 0] db_data.start_time_utc = db_tuple[19] # bring it into displayable form ver_sw = db_data.ver_sw if len(ver_sw) > 10: ver_sw = ver_sw[:6] if len(db_data.ver_sw_release) > 0: try: release_split = db_data.ver_sw_release.split() release_type = int(release_split[1]) if release_type == 255: # it's a release ver_sw = release_split[0] except: pass airframe_data = get_airframe_data(db_data.sys_autostart_id) if airframe_data is None: airframe = db_data.sys_autostart_id else: airframe = airframe_data['name'] flight_modes = ', '.join([ flight_modes_table[x][0] for x in db_data.flight_modes if x in flight_modes_table ]) m, s = divmod(db_data.duration_s, 60) h, m = divmod(m, 60) duration_str = '{:d}:{:02d}:{:02d}'.format(h, m, s) start_time_str = 'N/A' if db_data.start_time_utc != 0: start_datetime = datetime.fromtimestamp(db_data.start_time_utc) start_time_str = start_datetime.strftime("%Y-%m-%d %H:%M") # make sure to break long descriptions w/o spaces (otherwise they # mess up the layout) description = html_long_word_force_break(db_data.description) search_only_columns = [] if db_data.ver_sw is not None: search_only_columns.append(db_data.ver_sw) if db_data.ver_sw_release is not None: search_only_columns.append(db_data.ver_sw_release) if db_data.vehicle_uuid is not None: search_only_columns.append(db_data.vehicle_uuid) image_col = '<div class="no_map_overview"> Not rendered / No GPS </div>' image_filename = os.path.join(get_overview_img_filepath(), log_id + '.png') if os.path.exists(image_filename): image_col = '<img class="map_overview" src="/overview_img/' image_col += log_id + '.png" alt="Overview Image Load Failed" height=50/>' if sim: templog_id = log_id + "sim" elif real: templog_id = log_id + "real" else: templog_id = log_id return Columns([ counter, '<a href="thiel_app?log=' + templog_id + 'desc:' + description + '">' + log_date + '</a>', image_col, description, db_data.mav_type, airframe, db_data.sys_hw, ver_sw, duration_str, start_time_str, db_data.rating_str(), db_data.num_logged_errors, flight_modes ], search_only_columns)
def get_columns_from_tuple(db_tuple, counter): """ load the columns (list of strings) from a db_tuple """ db_data = DBData() log_id = db_tuple[0] log_date = db_tuple[1].strftime('%Y-%m-%d') db_data.description = db_tuple[2] db_data.feedback = '' db_data.type = '' db_data.wind_speed = db_tuple[3] db_data.rating = db_tuple[4] db_data.video_url = db_tuple[5] db_data_gen = get_generated_db_data_from_log(log_id, con, cur) if db_data_gen is None: return None # bring it into displayable form ver_sw = db_data_gen.ver_sw if len(ver_sw) > 10: ver_sw = ver_sw[:6] if len(db_data_gen.ver_sw_release) > 0: try: release_split = db_data_gen.ver_sw_release.split() release_type = int(release_split[1]) if release_type == 255: # it's a release ver_sw = release_split[0] except: pass airframe_data = get_airframe_data(db_data_gen.sys_autostart_id) if airframe_data is None: airframe = db_data_gen.sys_autostart_id else: airframe = airframe_data['name'] flight_modes = ', '.join([ flight_modes_table[x][0] for x in db_data_gen.flight_modes if x in flight_modes_table ]) m, s = divmod(db_data_gen.duration_s, 60) h, m = divmod(m, 60) duration_str = '{:d}:{:02d}:{:02d}'.format(h, m, s) # make sure to break long descriptions w/o spaces (otherwise they # mess up the layout) description = html_long_word_force_break(db_data.description) search_only_columns = [] if db_data_gen.ver_sw is not None: search_only_columns.append(db_data_gen.ver_sw) if db_data_gen.ver_sw_release is not None: search_only_columns.append(db_data_gen.ver_sw_release) if db_data_gen.vehicle_uuid is not None: search_only_columns.append(db_data_gen.vehicle_uuid) image_col = '<div class="no_map_overview"> Not rendered / No GPS </div>' image_filename = os.path.join(get_overview_img_filepath(), log_id + '.png') if os.path.exists(image_filename): image_col = '<img class="map_overview" src="/overview_img/' image_col += log_id + '.png" alt="Overview Image Load Failed" height=50/>' return Columns([ counter, '<a href="plot_app?log=' + log_id + '">' + log_date + '</a>', image_col, description, db_data_gen.mav_type, airframe, db_data_gen.sys_hw, ver_sw, duration_str, db_data.rating_str(), db_data_gen.num_logged_errors, flight_modes ], search_only_columns)