def test_empty(self): channel = Channel() self.assertEqual(print(channel), None) self.assertEqual(channel.id_channel, None) self.assertEqual(channel.sensor, None) self.assertEqual(channel.id_data_format, None) self.assertEqual(channel.id_sensor_unit, None) self.assertEqual(channel.label, None)
def add_channel(self, sensor, id_sensor_unit, id_data_format, label): # Create object channel = Channel(sensor=sensor, id_sensor_unit=id_sensor_unit, id_data_format=id_data_format, label=label) self.session.add(channel) self.commit() return channel
def test_to_time_series(self): sensordata = SensorData() sensordata.id_sensor_data = 1 recordset = Recordset() sensordata.recordset = recordset sensor = Sensor() sensor.sampling_rate = 5 sensor.data_rate = 1 sensordata.sensor = sensor channel = Channel() sensordata.channel = channel sensordata.start_timestamp = datetime.datetime.fromtimestamp(0) sensordata.stop_timestamp = datetime.datetime.fromtimestamp(0) sensordata.data = np.array([1, 2, 3, 4, 5], dtype=float) print(sensordata.to_time_series()) print(sensordata)
def test_properties(self): channel = Channel() channel.id_channel = 1 sensor = Sensor() channel.sensor = sensor # print(channel.sensor) channel.id_data_format = 0 channel.id_sensor_unit = 0 channel.label = 'My label' self.assertEqual(channel.id_channel, 1) self.assertEqual(channel.sensor, sensor) self.assertEqual(channel.id_data_format, 0) self.assertEqual(channel.id_sensor_unit, 0) self.assertEqual(channel.label, 'My label')
def test_properties(self): sensordata = SensorData() sensordata.id_sensor_data = 1 recordset = Recordset() sensordata.recordset = recordset sensor = Sensor() sensordata.sensor = sensor channel = Channel() sensordata.channel = channel sensordata.data_timestamp = 10 sensordata.data = [1, 2, 3, 4, 5] self.assertEqual(sensordata.id_sensor_data, 1) self.assertEqual(sensordata.recordset, recordset) self.assertEqual(sensordata.sensor, sensor) self.assertEqual(sensordata.channel, channel) self.assertEqual(sensordata.data_timestamp, 10) self.assertEqual(sensordata.data, [1, 2, 3, 4, 5])
def add_channel(self, sensor, id_sensor_unit, id_data_format, label): # Check if that sensor is already present in the database query = self.session.query( Channel).filter((Channel.sensor == sensor) & (Channel.id_sensor_unit == id_sensor_unit) & (Channel.id_data_format == id_data_format) & (Channel.label == label)) if query.first(): # print("Channel " + label + " already present in DB!") return query.first() # Create object channel = Channel(sensor=sensor, id_sensor_unit=id_sensor_unit, id_data_format=id_data_format, label=label) self.session.add(channel) self.commit() return channel
def test_to_time_series(self): sensordata = SensorData() sensordata.id_sensor_data = 1 recordset = Recordset() sensordata.recordset = recordset sensor = Sensor() sensor.sampling_rate = 5 sensor.data_rate = 1 sensordata.sensor = sensor channel = Channel() sensordata.channel = channel sensordata.data = np.array([1, 2, 3, 4, 5], dtype=float) sensordata.timestamps = SensorTimestamps() sensordata.timestamps.timestamps = np.array([0, 1, 2, 3, 4], dtype=np.float64) sensordata.timestamps.update_timestamps() print(sensordata.to_time_series()) print(sensordata)
def test_get_all_sensor_data_with_args(self): manager = DBManager(filename='openimu.db', overwrite=True, echo=False) # Create sensor in DB group = manager.update_group( Group(name='Group Name', description='Group Description')) participant = manager.update_participant( Participant(name='Participant Name', description='Participant Description', group=group)) sensor = manager.add_sensor(SensorType.ACCELEROMETER, 'Sensor Name', 'Hardware Name', 'Wrist', 30.0, 1) sensor2 = manager.add_sensor(SensorType.GYROMETER, 'Sensor Name', 'Hardware Name', 'Wrist', 30.0, 1) channel1 = manager.add_channel(sensor, Units.GRAVITY_G, DataFormat.FLOAT32, 'Accelerometer_X') channel2 = manager.add_channel(sensor, Units.GRAVITY_G, DataFormat.FLOAT32, 'Accelerometer_Y') timestamps = SensorTimestamps() timestamps.timestamps = np.zeros(40, dtype=np.float64) # will set start and end timestamps.update_timestamps() recordset = manager.add_recordset(participant, 'My Record', timestamps.start_timestamp, timestamps.end_timestamp) data = np.zeros(40, dtype=np.float32) sensordata = manager.add_sensor_data(recordset, sensor, channel1, timestamps, data) sensordata = manager.add_sensor_data(recordset, sensor, channel2, timestamps, data) manager.commit() # Test with no args, return everything in the recordset sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True) self.assertEqual(len(sensordata_res), 2) for sensor_data in sensordata_res: self.assertEqual(len(sensor_data.data), len(data)) # Test with a valid sensor arg sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, sensor=sensor) self.assertEqual(len(sensordata_res), 2) for sensor_data in sensordata_res: self.assertEqual(len(sensor_data.data), len(data)) # Test with not the right sensor arg sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, sensor=sensor2) self.assertEqual(len(sensordata_res), 0) # Testing with invalid sensor arg sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, sensor=Sensor()) self.assertEqual(len(sensordata_res), 0) # Testing with channel1 sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, channel=channel1) self.assertEqual(len(sensordata_res), 1) for sensor_data in sensordata_res: self.assertEqual(len(sensor_data.data), len(data)) # Testing with channel2 sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, channel=channel2) self.assertEqual(len(sensordata_res), 1) for sensor_data in sensordata_res: self.assertEqual(len(sensor_data.data), len(data)) # Testing with invalid channel sensordata_res = manager.get_all_sensor_data(recordset=recordset, convert=True, channel=Channel()) self.assertEqual(len(sensordata_res), 0) manager.close()