def test_historic_ibi(self) -> None:
        db_session = next(deps.get_db())

        values = ProcessValue.get_historic_ibi(db_session, self.value_current.timestamp, self.rec_id, 2)

        self.assertEqual(2, len(values))
        self.assertEqual(190, values[0].timestamp)
        self.assertEqual(7, values[0].value1)
        self.assertEqual(180, values[1].timestamp)
        self.assertEqual(10, values[1].value1)
    def setUpClass(cls) -> None:

        cls.db_session = next(deps.get_db())
        recording = crud.recording.create_with_participant(db_session=cls.db_session,
                                                           obj_in=RecordingCreate(name="test"), participant_id=1)
        recording2 = crud.recording.create_with_participant(db_session=cls.db_session,
                                                            obj_in=RecordingCreate(name="test2"), participant_id=1)
        cls.recordings = [recording, recording2]
        cls.rec_id = recording.id

        cls.add_files(recording.id, recording2.id)
        cls.acc_values = cls.add_values(cls.file_acc.id)
        cls.eda_values = cls.add_values(cls.file_eda.id)
        cls.ibi_values = cls.add_values(cls.file_ibi.id)
Example #3
0
    def single_value(part_id: int, rec_id: int, run_id: int,
                     values: TimestampValues, spotify_username: str):
        db_session = next(deps.get_db())
        checker = StressChecker(db_settings=crud.setting.get(db_session),
                                db_session=db_session)
        data = ProcessValue.convert_to_data_for_time(db_session, values,
                                                     rec_id, run_id)

        action = checker.run(data)
        if action is not None:
            result = queue(db_session, data, action, part_id, spotify_username)
            crud.result.create_with_run(db_session=db_session,
                                        obj_in=result,
                                        run_id=run_id)
Example #4
0
    def start(part_id, rec_id, run_id, spotify_username):
        # The values for the different sensors are being stored in those lists.
        eda_data = []
        ibi_data = []
        acc_data = []
        temp_data = []
        bvp_data = []

        db_session = next(deps.get_db())
        checker = StressChecker(db_settings=crud.setting.get(db_session),
                                db_session=db_session)
        # Get the files from the recording.
        files = crud.file.get_multi_for_recording(db_session,
                                                  recording_id=rec_id)

        # Iterate over the files.
        for file in files:

            # Get the values out of the file
            values = crud.value.get_all_for_file(db_session, file_id=file.id)

            # Sort the values in the file so that they are sorted according to their timestamp.
            values.sort(key=lambda x: x.timestamp)

            # Store the file in the correct variable according to their sensor ID.
            if file.sensor.name.lower() == "TEMP".lower():
                temp_data = values
            elif file.sensor.name.lower() == "EDA".lower():
                eda_data = values
            elif file.sensor.name.lower() == "BVP".lower():
                bvp_data = values
            elif file.sensor.name.lower() == "ACC".lower():
                acc_data = values
            elif file.sensor.name.lower() == "IBI".lower():
                ibi_data = values

        # Iterate over the eda file with its values
        for value in eda_data:
            data_for_time_object = Stream.create_data_for_time_object(
                value, acc_data, bvp_data, eda_data, ibi_data, run_id,
                temp_data)
            action = checker.run(data_for_time_object)
            if is_queue_finished(db_session, run_id):
                result = queue(db_session, data_for_time_object, action,
                               part_id, spotify_username)
                crud.result.create_with_run(db_session=db_session,
                                            obj_in=result,
                                            run_id=run_id)
Example #5
0
    def test_majority_vote_stressed(self) -> None:
        db_session = next(deps.get_db())
        recording = crud.recording.create_with_participant(db_session=db_session,
                                                           obj_in=RecordingCreate(name="test"), participant_id=1)
        run = crud.run.create_with_recoding(db_session=db_session,
                                            obj_in=RunCreate(), recording_id=recording.id)

        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=100, eda=0, mean_rr=0, prr_20=0), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=110, eda=0, mean_rr=1, prr_20=2), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=120, eda=0, mean_rr=1, prr_20=2), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=130, eda=0, mean_rr=1, prr_20=2), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=140, eda=0, mean_rr=1, prr_20=2), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=150, eda=0, mean_rr=1, prr_20=2), run_id=run.id)
        crud.tendency.create_with_run(db_session=db_session,
                                      obj_in=TendencyCreate(timestamp=160, eda=0, mean_rr=2, prr_20=2), run_id=run.id)

        self.assertEqual(2, majority_vote(db_session=db_session, run_id=run.id))