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