예제 #1
0
    def delete_log_entry(log_id, token):
        """
        delete a log entry (DB & file), validate token first

        :return: True on success
        """
        con = sqlite3.connect(get_db_filename(),
                              detect_types=sqlite3.PARSE_DECLTYPES)
        cur = con.cursor()
        cur.execute('select Token from Logs where Id = ?', (log_id, ))
        db_tuple = cur.fetchone()
        if db_tuple is None:
            return False
        if token != db_tuple[0]:  # validate token
            return False

        # kml file
        kml_path = get_kml_filepath()
        kml_file_name = os.path.join(kml_path,
                                     log_id.replace('/', '.') + '.kml')
        if os.path.exists(kml_file_name):
            os.unlink(kml_file_name)

        #preview image
        preview_image_filename = os.path.join(get_overview_img_filepath(),
                                              log_id + '.png')
        if os.path.exists(preview_image_filename):
            os.unlink(preview_image_filename)

        log_file_name = get_log_filename(log_id)
        print('deleting log entry {} and file {}'.format(
            log_id, log_file_name))
        os.unlink(log_file_name)
        cur.execute("DELETE FROM LogsGenerated WHERE Id = ?", (log_id, ))
        cur.execute("DELETE FROM Logs WHERE Id = ?", (log_id, ))
        con.commit()
        cur.close()
        con.close()

        # need to clear the cache as well
        clear_ulog_cache()

        return True
예제 #2
0
def generate_overview_img(ulog, log_id):
    ''' This funciton will generate overwie for loaded ULog data
        '''
    output_filename = os.path.join(get_overview_img_filepath(),
                                   log_id + '.png')

    if os.path.exists(output_filename):
        return

    try:
        cur_dataset = ulog.get_dataset('vehicle_gps_position')
        t = cur_dataset.data['timestamp']
        indices = cur_dataset.data['fix_type'] > 2  # use only data with a fix
        lon = cur_dataset.data['lon'][indices] / 1e7  # degrees
        lat = cur_dataset.data['lat'][indices] / 1e7

        min_lat = min(lat)
        max_lat = max(lat)

        min_lon = min(lon)
        max_lon = max(lon)

        z = get_zoom((min_lat, min_lon, max_lat, max_lon)) - 2
        if z < 0:
            z = 0

        render_map = smopy.Map((min_lat, min_lon, max_lat, max_lon), z=z)
        fig, axes = plt.subplots(nrows=1, ncols=1)
        render_map.show_mpl(figsize=(8, 6), ax=axes)

        x, y = render_map.to_pixels(lat, lon)
        axes.plot(x, y, 'r')

        axes.set_axis_off()
        plt.savefig(output_filename, bbox_inches='tight')
        plt.close(fig)

        print('Saving overview file ' + output_filename)

    except:
        # Ignore. Eg. if topic not found
        print('Error generating overview file: ' + output_filename +
              ' - No GPS?')
예제 #3
0
extra_patterns = [
    (r'/upload', UploadHandler),
    (r'/browse', BrowseHandler),
    (r'/browse_data_retrieval', BrowseDataRetrievalHandler),
    (r'/3d', ThreeDHandler),
    (r'/radio_controller', RadioControllerHandler),
    (r'/edit_entry', EditEntryHandler),
    (r'/?', UploadHandler),  #root should point to upload
    (r'/download', DownloadHandler),
    (r'/dbinfo', DBInfoHandler),
    (r'/error_label', UpdateErrorLabelHandler),
    (r"/stats", RedirectHandler, {
        "url": "/plot_app?stats=1"
    }),
    (r'/overview_img/(.*)', StaticFileHandler, {
        'path': get_overview_img_filepath()
    }),
]

server = None
custom_port = 5006
while server is None:
    try:
        server = Server(applications,
                        extra_patterns=extra_patterns,
                        **server_kwargs)
    except OSError as e:
        # if we get a port bind error and running locally with '-f',
        # automatically select another port (useful for opening multiple logs)
        if e.errno == errno.EADDRINUSE and show_ulog_file:
            custom_port += 1
예제 #4
0
        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)
예제 #5
0
        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)