def extract_data(self, timestamp, data, offset): """Extract the data from the feature's raw data. Args: timestamp (int): Data's timestamp. data (str): The data read from the feature. offset (int): Offset where to start reading data. Returns: :class:`blue_st_sdk.feature.ExtractedData`: Container of the number of bytes read and the extracted data. Raises: :exc:`blue_st_sdk.utils.blue_st_exceptions.BlueSTInvalidDataException` if the data array has not enough data to read. """ if len(data) - offset < self.DATA_LENGTH_BYTES: raise BlueSTInvalidDataException( 'There is no %s byte available to read.' \ % (self.DATA_LENGTH_BYTES)) if len(data) - offset == self.DATA_LENGTH_BYTES: # Extract the activity from the feature's raw data. sample = Sample( [NumberConversion.byte_to_uint8(data, offset), datetime.now()], self.get_fields_description(), timestamp) return ExtractedData(sample, self.DATA_LENGTH_BYTES) else: # Extract the activity and the algorithm from the feature's raw data. sample = Sample([ NumberConversion.byte_to_uint8(data, offset), datetime.now(), NumberConversion.byte_to_uint8(data, offset + 1) ], self.get_fields_description(), timestamp) return ExtractedData(sample, self.DATA_LENGTH_BYTES + 1)
def extract_data(self, timestamp, data, offset): """Extract the data from the feature's raw data. Args: timestamp (int): Data's timestamp. data (str): The data read from the feature. offset (int): Offset where to start reading data. Returns: :class:`blue_st_sdk.feature.ExtractedData`: Container of the number of bytes read and the extracted data. Raises: :exc:`Exception` if the data array has not enough data to read. """ if len(data) - offset < self.DATA_LENGTH_BYTES: raise Exception('There are no %d bytes available to read.' \ % (self.DATA_LENGTH_BYTES)) sample = Sample([NumberConversion.byteToUInt8(data, offset)], self.get_fields_description(), timestamp) return ExtractedData(sample, self.DATA_LENGTH_BYTES)