Beispiel #1
0
    def test_get_all_channels(self):
        manager = DBManager(filename='openimu.db', overwrite=True)

        # Create sensor in DB
        sensor = manager.add_sensor(SensorType.ACCELEROMETER, 'Sensor Name',
                                    'Hardware Name', 'Wrist', 30.0, 1)
        channelx = manager.add_channel(sensor, Units.GRAVITY_G,
                                       DataFormat.FLOAT32, 'Accelerometer_X')
        channely = manager.add_channel(sensor, Units.GRAVITY_G,
                                       DataFormat.FLOAT32, 'Accelerometer_Y')
        channelz = manager.add_channel(sensor, Units.GRAVITY_G,
                                       DataFormat.FLOAT32, 'Accelerometer_Z')

        # Get all channels (from all sensor)
        channels = manager.get_all_channels()
        self.assertEqual(len(channels), 3)

        # Get all channels (from valid sensor)
        channels = manager.get_all_channels(sensor=sensor)
        self.assertEqual(len(channels), 3)

        # Get all channels (from invalid sensor)
        channels = manager.get_all_channels(sensor=Sensor())
        self.assertEqual(len(channels), 0)

        manager.close()
    def test_loading(self):

        manager = DBManager('test.db', overwrite=True)
        participant = Participant(name='My Participant',
                                  description='Participant Description')
        manager.update_participant(participant)

        # Import to database
        importer = ActigraphImporter(manager, participant)
        results = importer.load('../../../resources/samples/test.gt3x')

        samples = 0
        for activity in results[1]['activity']:
            samples += 3 * len(activity[1])

        print('samples imported (each channels)', samples)

        importer.import_to_database(results)

        # Reload from database
        manager = DBManager('test.db')

        recordsets = manager.get_all_recordsets()
        self.assertGreater(len(recordsets), 0)

        loaded_samples = 0

        for record in recordsets:
            # Get all sensors in record
            sensors = manager.get_all_sensors()
            for sensor in sensors:
                if sensor.id_sensor_type == SensorType.ACCELEROMETER:
                    channels = manager.get_all_channels(sensor=sensor)
                    for channel in channels:
                        print('processing channel: ', channel)
                        self.assertEqual(channel.id_sensor, sensor.id_sensor,
                                         "id_sensor test for channel")
                        # Will get all data (converted to floats)
                        channel_data = manager.get_all_sensor_data(
                            recordset=record, convert=True, channel=channel)
                        print('channel_data_length', len(channel_data))

                        for sensor_data in channel_data:
                            self.assertEqual(sensor_data.id_channel,
                                             channel.id_channel,
                                             "id_channel test for data")
                            self.assertEqual(sensor_data.id_sensor,
                                             sensor.id_sensor,
                                             "id_sensor test data")
                            loaded_samples += len(sensor_data.data)

        self.assertEqual(samples, loaded_samples)
Beispiel #3
0
    def calculate(self, manager: DBManager, recordsets: list):
        results = []

        for record in recordsets:
            # Get all sensors in record
            sensors = manager.get_all_sensors(
                id_sensor_type=SensorType.ACCELEROMETER)

            for sensor in sensors:
                # print('Found Accelerometer')
                channels = manager.get_all_channels(sensor=sensor)
                samples_num = 0
                # print('Found channels: ', channels)
                all_channels_data = {
                    'Accelerometer_X': [],
                    'Accelerometer_Y': [],
                    'Accelerometer_Z': []
                }
                for channel_index, channel in enumerate(channels):
                    # if channel.label == 'Accelerometer_Y':
                    # print('Processing Channel :', channel)
                    # Will get all data (converted to floats)
                    channel_data = manager.get_all_sensor_data(
                        recordset=record,
                        convert=True,
                        sensor=sensor,
                        channel=channel)
                    if len(channel_data) > 0:
                        for data in channel_data:
                            all_channels_data[channel.label].append(data)
                            if channel_index == 0:  # Compute number of samples total, if we are at the first channel
                                samples_num += len(data.data)

                if len(all_channels_data['Accelerometer_X']) > 0:
                    # Process all sensor data
                    result = {
                        'id_recordset':
                        record.id_recordset,
                        'result_name':
                        record.name + ' (' + sensor.location + '/' +
                        sensor.name + ')',
                        'id_sensor':
                        sensor.id_sensor,
                        'result':
                        self.do_calculation(all_channels_data,
                                            sensor.sampling_rate, samples_num)
                    }
                    results.append(result)

        # Return an array with results for each recordset
        return results
Beispiel #4
0
    def calculate(self, manager: DBManager, recordsets: list):
        print('FreedsonAdult1998.calculate')
        print('Using recordsets', recordsets)

        results = []

        for record in recordsets:
            # Get all sensors in record
            sensors = manager.get_all_sensors(
                id_sensor_type=SensorType.ACCELEROMETER)

            for sensor in sensors:
                # print('Found Accelerometer')
                channels = manager.get_all_channels(sensor=sensor)
                # print('Found channels: ', channels)
                for channel in channels:
                    if channel.label == 'Accelerometer_Y':
                        # print('Processing Channel :', channel)
                        # Will get all data (converted to floats)
                        channel_data = manager.get_all_sensor_data(
                            recordset=record,
                            convert=True,
                            sensor=sensor,
                            channel=channel)
                        if len(channel_data) > 0:
                            # Process all sensor data
                            result = {
                                'id_recordset':
                                record.id_recordset,
                                'result_name':
                                record.name + ' (' + sensor.location + '/' +
                                sensor.name + ')',
                                'id_sensor':
                                sensor.id_sensor,
                                'result':
                                freedson_adult_1998(channel_data,
                                                    sensor.sampling_rate)
                            }
                            results.append(result)

        # Return an array with results for each recordset
        return results
Beispiel #5
0
    if not os.path.isfile(db_filename):
        print('importing actigraph data')
        import_data()

    manager = DBManager(db_filename)

    # Get recordsets
    recordsets = manager.get_all_recordsets()

    for record in recordsets:
        # Get all sensors in record
        sensors = manager.get_all_sensors()
        for sensor in sensors:
            if sensor.id_sensor_type == SensorType.ACCELEROMETER:
                print('Found Accelerometer')
                channels = manager.get_all_channels(sensor=sensor)
                for channel in channels:

                    if channel.label == 'Accelerometer_Y':
                        print('Processing Channel :', channel)
                        # Will get all data (converted to floats)
                        channel_data = manager.get_all_sensor_data(
                            recordset=record,
                            convert=True,
                            sensor=sensor,
                            channel=channel)

                        # Process all sensor data
                        results = freedson_adult_1998(channel_data,
                                                      sensor.sampling_rate)