예제 #1
0
    def get_all_sensor_data(self, **kwargs):

        # Initialize from kwargs (and default values)
        convert = kwargs.get('convert', False)
        sensor = kwargs.get('sensor', None)
        channel = kwargs.get('channel', None)
        recordset = kwargs.get('recordset', None)
        start_time = kwargs.get('start_time', None)
        end_time = kwargs.get('end_time', None)

        # Get all sensor data
        query = self.session.query(SensorData)

        if recordset is not None:
            query = query.filter(
                SensorData.id_recordset == recordset.id_recordset)

        if sensor is not None:
            # print('Should filter sensor id', sensor.id_sensor)
            query = query.filter(SensorData.id_sensor == sensor.id_sensor)

        if channel is not None:
            # print('Should filter channel', channel.id_channel)
            query = query.filter(SensorData.id_channel == channel.id_channel)

        if start_time is not None:
            query = query.filter(
                or_(
                    SensorData.timestamps.has(
                        SensorTimestamps.start_timestamp >= start_time),
                    and_(
                        SensorData.timestamps.has(
                            SensorTimestamps.start_timestamp <= start_time),
                        SensorData.timestamps.has(
                            SensorTimestamps.end_timestamp >= start_time))))

        if end_time is not None:
            query = query.filter(
                or_(
                    SensorData.timestamps.has(
                        SensorTimestamps.end_timestamp <= end_time),
                    and_(
                        SensorData.timestamps.has(
                            SensorTimestamps.start_timestamp <= end_time),
                        SensorData.timestamps.has(
                            SensorTimestamps.end_timestamp >= end_time))))

        # print(query)

        if not convert:
            return query.all()
        else:
            # Read result, data will be bytes array
            result = query.all()

            # Convert to the right format
            for sensor_data in result:
                # print('data len:', len(sensor_data.data))
                sensor_data.data = DataFormat.from_bytes(
                    sensor_data.data, sensor_data.channel.id_data_format)

            return result
예제 #2
0
 def to_ndarray(self):
     if isinstance(self.data, bytes):
         return DataFormat.from_bytes(self.data,
                                      self.channel.id_data_format)
     else:
         return self.data
예제 #3
0
 def to_ndarray(self):
     if type(self.data) is bytes:
         return DataFormat.from_bytes(self.data, self.channel.id_data_format)
     else:
         return self.data