Exemple #1
0
    def import_gps_to_database(self, timestamp, sensors, channels, recordset,
                               data: dict):

        print('import_imu_to_database')
        values = np.array(data['values'], dtype=np.float32)

        if len(values) == 0:
            return False

        # Regenerate GPS data to be stored in the DB as SIRF data
        # TODO Better GPS solution?

        # We have one sample per second of GPS data
        for i, val in enumerate(values):
            geo = GPSGeodetic()
            # Discard invalid data
            if math.isnan(val[1]) or math.isnan(val[2]):
                continue

            geo.latitude = val[1] * 1e7
            geo.longitude = val[2] * 1e7
            # altitude = val[3] * 1e7

            # Create sensor timestamps first
            sensor_timestamps = SensorTimestamps()
            sensor_timestamps.timestamps = data['times'][i:i + 1]
            sensor_timestamps.update_timestamps()

            self.add_sensor_data_to_db(recordset, sensors['gps'],
                                       channels['gps'], sensor_timestamps, geo)

        # Commit to file
        self.db.commit()

        return True
    def import_coordinates_to_database(self, sample_rate, timestamp, recordset,
                                       sensors, channels, data: list):

        # print('import_motion_to_database')
        # print('data', data, len(data))

        values = np.array(data, dtype=np.float32)
        # print("Values shape: ", values.shape)
        end_timestamp = timestamp + 1
        # print("timestamps, ", timestamp, end_timestamp)

        # Calculate last index to remove extra values
        real_size = int(np.floor(len(values) / sample_rate) * sample_rate)
        # print('real size:', real_size)

        # Update end_timestamp if required
        if end_timestamp > recordset.end_timestamp.timestamp():
            recordset.end_timestamp = datetime.datetime.fromtimestamp(
                end_timestamp)

        if real_size > 0:
            # Coordinates

            # Build gps data
            geo = GPSGeodetic()
            geo.latitude = values[0][0] * 1e7
            geo.longitude = values[0][1] * 1e7

            # Store
            self.add_sensor_data_to_db(
                recordset, sensors['coordinates'], channels['coordinates'],
                datetime.datetime.fromtimestamp(timestamp),
                datetime.datetime.fromtimestamp(end_timestamp), geo)
Exemple #3
0
    def import_coordinates_to_database(self, sample_rate, coordinates: dict):
        # DL Oct. 17 2018, New import to database
        coordinates_sensor = self.add_sensor_to_db(SensorType.GPS,
                                                   'Coordinates', 'AppleWatch',
                                                   'Wrist', sample_rate, 1)
        coordinates_channel = self.add_channel_to_db(coordinates_sensor,
                                                     Units.NONE,
                                                     DataFormat.UINT8,
                                                     'Coordinates')

        for timestamp in coordinates:
            # print('coordinates', timestamp, len(coordinates[timestamp]['times']),
            #      len(coordinates[timestamp]['values']))

            # Create time array as float64
            timesarray = np.asarray(coordinates[timestamp]['times'],
                                    dtype=np.float64)

            if len(timesarray) is 0:
                self.last_error = "Aucune données temporelles."
                return

            # Other values are float32
            valuesarray = np.asarray(coordinates[timestamp]['values'],
                                     dtype=np.float32)

            # Create one entry per timestamp ?
            # Could we store a vector instead ?
            for i, value in enumerate(valuesarray):
                # Build gps data
                geo = GPSGeodetic()
                geo.latitude = value[0] * 1e7
                geo.longitude = value[1] * 1e7

                # Create sensor timestamps first
                sensor_timestamps = SensorTimestamps()
                sensor_timestamps.timestamps = timesarray[i:i + 1]
                sensor_timestamps.update_timestamps()

                # Calculate recordset
                recordset = self.get_recordset(
                    sensor_timestamps.start_timestamp.timestamp(),
                    session_name=self.session_name)

                # Update timestamps in recordset
                # This should not happen, recordset is initialized at the beginning of the hour
                if sensor_timestamps.start_timestamp < recordset.start_timestamp:
                    recordset.start_timestamp = sensor_timestamps.start_timestamp
                # This can occur though
                if sensor_timestamps.end_timestamp > recordset.end_timestamp:
                    recordset.end_timestamp = sensor_timestamps.end_timestamp

                # Store
                self.add_sensor_data_to_db(recordset, coordinates_sensor,
                                           coordinates_channel,
                                           sensor_timestamps, geo)
                self.update_progress.emit(50 + np.floor(i / len(valuesarray) /
                                                        2 * 100))
Exemple #4
0
    def import_gps_to_database(self, timestamp, recordset, data: list):

        # Create sensors
        gps_sensor = self.add_sensor_to_db(SensorType.GPS, 'GPS', 'OpenIMU-HW',
                                           'Unknown', 1, 1)

        gps_channel = self.add_channel_to_db(gps_sensor, Units.NONE,
                                             DataFormat.UINT8, 'GPS_SIRF')

        # Get data in the form of array
        values = np.array(data, dtype=np.float32)
        # print("Values shape: ", values.shape)
        # print(values[:, 0])
        # print(values[:, 1])

        end_timestamp = timestamp + len(values)

        # Update end_timestamp if required
        if end_timestamp > recordset.end_timestamp.timestamp():
            recordset.end_timestamp = datetime.datetime.fromtimestamp(
                end_timestamp)

        # print('GPS DATA ', values)
        # Regenerate GPS data to be stored in the DB as SIRF data
        # TODO Better GPS solution?

        # We have one sample per second of GPS data
        for i in range(len(values)):
            val = values[i]
            geo = GPSGeodetic()
            # Discard invalid data
            if math.isnan(val[1]) or math.isnan(val[2]):
                continue
            geo.latitude = val[1] * 1e7
            geo.longitude = val[2] * 1e7
            #altitude = val[3] * 1e7
            self.add_sensor_data_to_db(
                recordset, gps_sensor, gps_channel,
                datetime.datetime.fromtimestamp(timestamp + i),
                datetime.datetime.fromtimestamp(timestamp + i), geo)

        # Commit to file
        self.db.commit()
    def import_gps_to_database(self, timestamp, sensors, channels, recordset, data: list):

        # Get data in the form of array
        values = np.array(data, dtype=np.float32)
        print("Values shape: ", values.shape)
        # print(values[:, 0])
        # print(values[:, 1])

        if len(values) == 0:
            return False

        end_timestamp = timestamp + len(values)

        # Update end_timestamp if required
        if end_timestamp > recordset.end_timestamp.timestamp():
            recordset.end_timestamp = datetime.datetime.fromtimestamp(end_timestamp)

        # print('GPS DATA ', values)
        # Regenerate GPS data to be stored in the DB as SIRF data
        # TODO Better GPS solution?

        # We have one sample per second of GPS data
        for i in range(len(values)):
            val = values[i]
            geo = GPSGeodetic()
            # Discard invalid data
            if math.isnan(val[1]) or math.isnan(val[2]):
                continue
            geo.latitude = val[1] * 1e7
            geo.longitude = val[2] * 1e7
            # altitude = val[3] * 1e7
            self.add_sensor_data_to_db(recordset, sensors['gps'], channels['gps'],
                                       datetime.datetime.fromtimestamp(timestamp + i),
                                       datetime.datetime.fromtimestamp(timestamp + i), geo)

        # Commit to file
        self.db.commit()

        return True
Exemple #6
0
    def export_file_sensor_data_gps(self, sensor: Sensor, sensors_data: list,
                                    file_format, directory):

        # GPS is stored as SIRF data structures.
        from libopenimu.importers.wimu import GPSGeodetic

        filename = directory + sensor.name
        if 'CSV' in file_format:
            filename = filename + '.CSV'
        elif 'Matlab' in file_format:
            filename = filename + '.mat'

        print('output to file : ', filename)

        # Write CSV header
        header = str()
        channels = self.get_all_channels(sensor=sensor)

        # Create data array
        # TODO, WILL HANDLE ONLY ONE GPS CHANNEL FOR NOW
        my_array = np.zeros(shape=(len(sensors_data), 3))

        for channel in channels:
            header = header + 'TIME;' + channel.label + '-Latitude;' + channel.label + '-Longitude;'

            for i in range(0, len(sensors_data)):
                gps_data = GPSGeodetic()
                gps_data.from_bytes(sensors_data[i].data)
                # Fill data
                my_array[i][0] = sensors_data[
                    i].timestamps.start_timestamp.timestamp()
                my_array[i][1] = gps_data.get_latitude()
                my_array[i][2] = gps_data.get_longitude()

        # Save CSV
        # print('dims:', my_array.shape)
        # Write values
        if 'CSV' in file_format:
            np.savetxt(filename, my_array, delimiter=";", header=header)
        elif 'Matlab' in file_format:
            sio.savemat(filename, {
                sensor.name: my_array.transpose(),
                'labels': header.split(';')
            },
                        do_compression=True)
Exemple #7
0
    def sensor_current_changed(self, item):
        sensor = self.sensors[item.data(Qt.UserRole)]
        timeseries = []
        # Color map
        colors = [Qt.red, Qt.green, Qt.yellow, Qt.cyan]

        if item.checkState() == Qt.Checked:
            # Choose the correct display for each sensor
            graph = None
            channels = self.dbMan.get_all_channels(sensor=sensor)
            for channel in channels:
                # Will get all data (converted to floats)
                channel_data = []
                for record in self.recordsets:
                    channel_data += self.dbMan.get_all_sensor_data(
                        recordset=record,
                        convert=True,
                        sensor=sensor,
                        channel=channel)
                timeseries.append(self.create_data_timeseries(channel_data))
                timeseries[-1]['label'] = channel.label

            if sensor.id_sensor_type == SensorType.ACCELEROMETER \
                    or sensor.id_sensor_type == SensorType.GYROMETER \
                    or sensor.id_sensor_type == SensorType.BATTERY \
                    or sensor.id_sensor_type == SensorType.LUX \
                    or sensor.id_sensor_type == SensorType.CURRENT \
                    or sensor.id_sensor_type == SensorType.BAROMETER \
                    or sensor.id_sensor_type == SensorType.MAGNETOMETER \
                    or sensor.id_sensor_type == SensorType.TEMPERATURE \
                    or sensor.id_sensor_type == SensorType.HEARTRATE \
                    or sensor.id_sensor_type == SensorType.ORIENTATION \
                    or sensor.id_sensor_type == SensorType.FSR:

                #graph = IMUChartView(self.UI.displayContents)
                graph = IMUChartView(self.UI.mdiArea)
                # graph.add_test_data()
                # Add series
                for series in timeseries:
                    graph.add_data(series['x'],
                                   series['y'],
                                   color=colors.pop(),
                                   legend_text=series['label'])

                graph.set_title(item.text())

            if sensor.id_sensor_type == SensorType.GPS:
                # graph = GPSView(self.UI.mdiArea)
                """base_widget = QWidget(self.UI.displayContents)
                base_widget.setFixedHeight(400)
                base_widget.setMaximumHeight(400)"""
                base_widget = self.UI.mdiArea
                graph = GPSView(base_widget)

                for data in channel_data:
                    gps = GPSGeodetic()
                    gps.from_bytes(data.data)
                    if gps.latitude != 0 and gps.longitude != 0:
                        graph.addPosition(data.timestamps.start_timestamp,
                                          gps.latitude / 1e7,
                                          gps.longitude / 1e7)
                        graph.setCursorPositionFromTime(
                            data.timestamps.start_timestamp)
                    # print (gps)

            if graph is not None:
                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                self.sensors_graphs[sensor.id_sensor] = graph
                #self.UI.displayContents.layout().insertWidget(0,graph)

                graph.show()
                QApplication.instance().processEvents()

                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

                #self.UI.displayArea.ensureWidgetVisible(graph)
                # self.UI.displayArea.verticalScrollBar().setSliderPosition(self.UI.displayArea.verticalScrollBar().maximum())
                # self.tile_graphs_vertically()
                self.UI.mdiArea.tileSubWindows()

        else:
            # Remove from display
            try:
                if self.sensors_graphs[sensor.id_sensor] is not None:
                    self.UI.mdiArea.removeSubWindow(
                        self.sensors_graphs[sensor.id_sensor].parent())
                    self.sensors_graphs[sensor.id_sensor].hide()
                    self.sensors_graphs[sensor.id_sensor] = None
                    # self.tile_graphs_vertically()
                    self.UI.mdiArea.tileSubWindows()
            except KeyError:
                pass
Exemple #8
0
    def sensor_graph_selected(self, sensor_item):
        sensor_id = sensor_item.property("sensor_id")
        sensor = self.sensors[sensor_id]
        sensor_label = sensor.name + " (" + sensor.location + ")"

        if sensor_item.isChecked():
            # Choose the correct display for each sensor
            graph_window = None
            timeseries, channel_data = self.get_sensor_data(sensor)  # Fetch all sensor data

            # Color map for curves
            colors = [Qt.blue, Qt.green, Qt.yellow, Qt.red]

            graph_type = self.get_sensor_graph_type(sensor)
            graph_window = GraphWindow(graph_type, sensor, self.UI.mdiArea)
            graph_window.setStyleSheet(self.styleSheet() + graph_window.styleSheet())

            if graph_type == GraphType.LINECHART:
                # Add series
                for series in timeseries:
                    graph_window.graph.add_data(series['x'], series['y'], color=colors.pop(),
                                                legend_text=series['label'])

                graph_window.graph.set_title(sensor_label)

            if graph_type == GraphType.MAP:
                for data in channel_data:
                    gps = GPSGeodetic()
                    gps.from_bytes(data.data)
                    if gps.latitude != 0 and gps.longitude != 0:
                        graph_window.graph.addPosition(data.timestamps.start_timestamp, gps.latitude / 1e7,
                                                       gps.longitude / 1e7)
                        graph_window.setCursorPositionFromTime(data.timestamps.start_timestamp)

            if graph_window is not None:
                self.UI.mdiArea.addSubWindow(graph_window).setWindowTitle(sensor_label)
                self.sensors_graphs[sensor.id_sensor] = graph_window
                # self.UI.displayContents.layout().insertWidget(0,graph)

                graph_window.show()
                QApplication.instance().processEvents()

                graph_window.aboutToClose.connect(self.graph_was_closed)
                graph_window.requestData.connect(self.query_sensor_data)
                graph_window.graph.cursorMoved.connect(self.graph_cursor_changed)
                graph_window.graph.selectedAreaChanged.connect(self.graph_selected_area_changed)
                graph_window.graph.clearedSelectionArea.connect(self.on_timeview_clear_selection_requested)
                graph_window.zoomAreaRequested.connect(self.graph_zoom_area)
                graph_window.zoomResetRequested.connect(self.graph_zoom_reset)

                self.UI.mdiArea.tileSubWindows()
        else:
            # Remove from display
            try:
                if self.sensors_graphs[sensor.id_sensor] is not None:
                    self.UI.mdiArea.removeSubWindow(self.sensors_graphs[sensor.id_sensor].parent())
                    self.sensors_graphs[sensor.id_sensor].hide()
                    del self.sensors_graphs[sensor.id_sensor]
                    self.UI.mdiArea.tileSubWindows()
            except KeyError:
                pass
        self.update_tile_buttons_state()
Exemple #9
0
                    channel_data = manager.get_all_sensor_data(recordset=record, convert=True, sensor=sensor,
                                                               channel=channel)
                    timeseries_gyro.append(create_data_timeseries(channel_data))
                    timeseries_gyro[-1]['label'] = channel.label
            if sensor.id_sensor_type == SensorType.GPS:
                print('Found GPS')
                channels = manager.get_all_channels(sensor=sensor)
                for channel in channels:
                    print('Found channel GPS', channel)
                    # No convesion for GPS, stored in raw binary
                    channel_data = manager.get_all_sensor_data(recordset=record, convert=False, sensor=sensor,
                                                               channel=channel)

                    from libopenimu.importers.wimu import GPSGeodetic
                    for sensor_data in channel_data:
                        geo = GPSGeodetic()
                        geo.from_bytes(sensor_data.data)
                        # print(geo)
                        gps_vals[sensor_data.start_timestamp] = [geo.get_latitude(), geo.get_longitude()]

        # Only first recordset
        break

    # Create widgets
    def create_window(label=''):
        window = QMainWindow()
        view = IMUChartView(window)
        window.setCentralWidget(view)
        window.setWindowTitle(label)
        window.resize(640, 480)
        return [window, view]
Exemple #10
0
    def sensor_current_changed(self, item):
        sensor = self.sensors[item.data(Qt.UserRole)]
        timeseries = []
        # Color map
        colors = [Qt.red, Qt.green, Qt.darkBlue]

        if item.checkState() == Qt.Checked:
            # Choose the correct display for each sensor

            channels = self.dbMan.get_all_channels(sensor=sensor)
            for channel in channels:
                # Will get all data (converted to floats)
                channel_data = []
                for record in self.recordsets:
                    channel_data += self.dbMan.get_all_sensor_data(
                        recordset=record,
                        convert=True,
                        sensor=sensor,
                        channel=channel)

            if sensor.id_sensor_type == SensorType.ACCELEROMETER \
                or sensor.id_sensor_type == SensorType.GYROMETER \
                    or sensor.id_sensor_type == SensorType.BATTERY\
                        or sensor.id_sensor_type == SensorType.LUX:

                timeseries.append(self.create_data_timeseries(channel_data))
                timeseries[-1]['label'] = channel.label

                graph = IMUChartView()
                # graph.add_test_data()
                # Add series
                for series in timeseries:
                    graph.add_data(series['x'],
                                   series['y'],
                                   color=colors.pop(),
                                   legend_text=series['label'])

                graph.set_title(item.text())
                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                graph.show()

                self.sensors_graphs[sensor.id_sensor] = graph
                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

                self.tile_graphs_vertically()

            if sensor.id_sensor_type == SensorType.GPS:
                graph = GPSView(self.UI.mdiArea)

                for data in channel_data:
                    gps = GPSGeodetic()
                    gps.from_bytes(data.data)
                    if gps.latitude != 0 and gps.longitude != 0:
                        graph.addPosition(data.start_timestamp,
                                          gps.latitude / 1e7,
                                          gps.longitude / 1e7)
                        graph.setCursorPositionFromTime(data.start_timestamp)
                    # print (gps)

                self.UI.mdiArea.addSubWindow(graph).setWindowTitle(item.text())
                graph.show()
                self.sensors_graphs[sensor.id_sensor] = graph
                graph.aboutToClose.connect(self.graph_was_closed)
                graph.cursorMoved.connect(self.graph_cursor_changed)

        else:
            # Remove from display
            if self.sensors_graphs[sensor.id_sensor] is not None:
                self.UI.mdiArea.removeSubWindow(
                    self.sensors_graphs[sensor.id_sensor].parent())
                self.sensors_graphs[sensor.id_sensor] = None
Exemple #11
0
                    timeseries_gyro[-1]['label'] = channel.label
            if sensor.id_sensor_type == SensorType.GPS:
                print('Found GPS')
                channels = manager.get_all_channels(sensor=sensor)
                for channel in channels:
                    print('Found channel GPS', channel)
                    # No convesion for GPS, stored in raw binary
                    channel_data = manager.get_all_sensor_data(
                        recordset=record,
                        convert=False,
                        sensor=sensor,
                        channel=channel)

                    from libopenimu.importers.wimu import GPSGeodetic
                    for sensor_data in channel_data:
                        geo = GPSGeodetic()
                        geo.from_bytes(sensor_data.data)
                        # print(geo)
                        gps_vals[sensor_data.start_timestamp] = [
                            geo.get_latitude(),
                            geo.get_longitude()
                        ]

        # Only first recordset
        break

    # Create widgets
    def create_window(label=''):
        window = QMainWindow()
        view = IMUChartView(window)
        window.setCentralWidget(view)