Пример #1
0
    def add_recordset(self,
                      participant: Participant,
                      name,
                      start_timestamp,
                      end_timestamp,
                      force=False):

        if not force:  # Check if we already have a recordset for that period
            query = self.session.query(
                Recordset).filter((Recordset.participant == participant)
                                  & (Recordset.name == name))
            if query.first():
                # Update start and end times, if needed.
                current_record = query.first()
                # print("Recordset found: " + current_record.name)
                new_starttime = current_record.start_timestamp
                if start_timestamp < new_starttime:
                    new_starttime = start_timestamp
                new_endtime = current_record.end_timestamp
                if end_timestamp > new_endtime:
                    new_endtime = end_timestamp
                current_record.start_timestamp = new_starttime
                current_record.end_timestamp = new_endtime
                self.commit()
                return current_record

        # Create object
        record = Recordset(participant=participant,
                           name=name,
                           start_timestamp=start_timestamp,
                           end_timestamp=end_timestamp)
        self.session.add(record)
        self.commit()
        return record
Пример #2
0
 def test_empty(self):
     record = Recordset()
     print(record)
     self.assertEqual(record.id_recordset, None)
     self.assertEqual(record.participant, None)
     self.assertEqual(record.name, None)
     self.assertEqual(record.start_timestamp, None)
     self.assertEqual(record.end_timestamp, None)
Пример #3
0
    def add_recordset(self, participant: Participant, name, start_timestamp, end_timestamp):

        # Create object
        record = Recordset(participant=participant, name=name, start_timestamp=start_timestamp,
                           end_timestamp=end_timestamp)
        self.session.add(record)
        self.commit()
        return record
Пример #4
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)
Пример #5
0
    def test_properties(self):
        record = Recordset()
        record.id_recordset = 3
        participant = Participant()
        record.participant = participant
        record.name = 'Record Name'
        record.start_timestamp = 22
        record.end_timestamp = 33

        self.assertEqual(record.id_recordset, 3)
        self.assertEqual(record.participant, participant)
        self.assertEqual(record.name, 'Record Name')
        self.assertEqual(record.start_timestamp, 22)
        self.assertEqual(record.end_timestamp, 33)
Пример #6
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])
Пример #7
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)