示例#1
0
    def test_load_cropped(self, mock_get_cropped_file_path, mock_load):
        subject_id = 'subjectB'
        mock_get_cropped_file_path.return_value = returned_cropped_path = 'path/to/file'
        mock_load.return_value = data = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
        expected_heart_rate_collection = HeartRateCollection(
            subject_id=subject_id, data=data)

        returned_heart_rate_collection = HeartRateService.load_cropped(
            subject_id)

        TestHelper.assert_models_equal(self, expected_heart_rate_collection,
                                       returned_heart_rate_collection)
        mock_get_cropped_file_path.assert_called_once_with(subject_id)
        mock_load.assert_called_once_with(returned_cropped_path)
示例#2
0
    def get_valid_epochs(subject_id):

        psg_collection = PSGService.load_cropped(subject_id)
        motion_collection = MotionService.load_cropped(subject_id)
        heart_rate_collection = HeartRateService.load_cropped(subject_id)

        start_time = psg_collection.data[0].epoch.timestamp
        motion_epoch_dictionary = RawDataProcessor.get_valid_epoch_dictionary(
            motion_collection.timestamps, start_time)
        hr_epoch_dictionary = RawDataProcessor.get_valid_epoch_dictionary(
            heart_rate_collection.timestamps, start_time)

        valid_epochs = []
        for stage_item in psg_collection.data:
            epoch = stage_item.epoch

            if epoch.timestamp in motion_epoch_dictionary and epoch.timestamp in hr_epoch_dictionary \
                    and stage_item.stage != SleepStage.unscored:
                valid_epochs.append(epoch)

        return valid_epochs
 def build(subject_id, valid_epochs):
     heart_rate_collection = HeartRateService.load_cropped(subject_id)
     return HeartRateFeatureService.build_from_collection(
         heart_rate_collection, valid_epochs)