示例#1
0
    def add_sensor_data(self, recordset: Recordset, sensor: Sensor,
                        channel: Channel, start_timestamp, end_timestamp,
                        data):

        # Create object
        sensordata = SensorData(recordset=recordset,
                                sensor=sensor,
                                channel=channel,
                                start_timestamp=start_timestamp,
                                end_timestamp=end_timestamp,
                                data=data.tobytes())

        # Custom SQL code
        """
        self.session.execute("INSERT INTO tabSensorsData (id_recordset, id_sensor, id_channel, data_timestamp, data) "
                             "VALUES (:id_recordset, :id_sensor, :id_channel, :data_timestamp, :data)",
                             {'id_recordset': recordset.id_recordset, 'id_sensor': sensor.id_sensor,
                              'id_channel': channel.id_channel, 'data_timestamp': timestamp, 'data': data.tobytes()})

        """

        self.session.add(sensordata)

        # Do not commit, too slow!
        return sensordata
示例#2
0
    def add_sensor_data(self, recordset: Recordset, sensor: Sensor,
                        channel: Channel, timestamps: SensorTimestamps, data):

        # Create object
        sensordata = SensorData(recordset=recordset,
                                sensor=sensor,
                                channel=channel,
                                timestamps=timestamps,
                                data=data.tobytes())

        self.session.add(sensordata)

        # Do not commit, too slow!
        return sensordata
示例#3
0
 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)
示例#4
0
    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])
示例#5
0
    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)
示例#6
0
 def test_empty_ctor(self):
     data = SensorData()
     self.assertEqual(data.id_sensor_data, None)