Ejemplo n.º 1
0
    def test_get_all_sensors(self):

        manager = DBManager(filename='openimu.db', overwrite=True)

        # Sensor information
        id_sensor_type = SensorType.ACCELEROMETER
        name = 'Accelerometer'
        hw_name = 'OpenIMU-HW'
        location = 'wrist'
        sampling_rate = 30.0
        data_rate = 1
        count = 10

        sensors = []

        for i in range(0, count):
            # Make sure sensor name changes...
            sensors.append(
                manager.add_sensor(id_sensor_type, name + str(i), hw_name,
                                   location, sampling_rate, data_rate))

        all_sensors = manager.get_all_sensors()
        self.assertEqual(len(all_sensors), len(sensors))

        # Wrong type
        self.assertEqual(0, len(manager.get_all_sensors(SensorType.BATTERY)))

        # Compare content
        for i in range(0, count):
            self.assertEqual(sensors[i], all_sensors[i])

        manager.close()
Ejemplo n.º 2
0
    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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 5
0
        # Load content of the file to the database
        data_results = importer.load('../../resources/samples/test.gt3x')
        importer.import_to_database(data_results)

    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)