diff options
author | Théo de la Hogue | 2022-11-24 09:18:43 +0100 |
---|---|---|
committer | Théo de la Hogue | 2022-11-24 09:18:43 +0100 |
commit | 1c79530b7a1e0f8cf9bb83586f0a6e2067c2ed72 (patch) | |
tree | 031480c87c3b73ebf8da6ca8ab0feb86f0b75bb3 | |
parent | b16e123a4ac0504dabf99ec466816645ce4d19c9 (diff) | |
download | argaze-1c79530b7a1e0f8cf9bb83586f0a6e2067c2ed72.zip argaze-1c79530b7a1e0f8cf9bb83586f0a6e2067c2ed72.tar.gz argaze-1c79530b7a1e0f8cf9bb83586f0a6e2067c2ed72.tar.bz2 argaze-1c79530b7a1e0f8cf9bb83586f0a6e2067c2ed72.tar.xz |
testing identification with non valid positions.
-rw-r--r-- | src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py | 52 |
1 files changed, 43 insertions, 9 deletions
diff --git a/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py b/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py index 55f075c..01b2aad 100644 --- a/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py +++ b/src/argaze.test/GazeAnalysis/DispersionBasedGazeMovementIdentifier.py @@ -9,7 +9,7 @@ from argaze.GazeAnalysis import DispersionBasedGazeMovementIdentifier import numpy -def build_gaze_fixation(size: int, center: tuple, dispersion: float, start_time: float, min_time: float, max_time: float): +def build_gaze_fixation(size: int, center: tuple, dispersion: float, start_time: float, min_time: float, max_time: float, validity: list = []): """ Generate N TimeStampedGazePsoitions dispersed around a center point for testing purpose. Timestamps are current time after random sleep (second). GazePositions are random values. @@ -18,16 +18,26 @@ def build_gaze_fixation(size: int, center: tuple, dispersion: float, start_time: for i in range(0, size): - # Edit gaze position - random_x = center[0] + dispersion * (random.random() - 0.5) - random_y = center[1] + dispersion * (random.random() - 0.5) - random_gaze_position = GazeFeatures.GazePosition((random_x, random_y)) + # Check position validity + valid = True + if len(validity) > i: + + valid = validity[i] + + if valid: + + # Edit gaze position + random_x = center[0] + dispersion * (random.random() - 0.5) + random_y = center[1] + dispersion * (random.random() - 0.5) + gaze_position = GazeFeatures.GazePosition((random_x, random_y)) + + else: + + gaze_position = GazeFeatures.UnvalidGazePosition() # Store gaze position ts = time.time() - start_time - ts_gaze_positions[ts] = random_gaze_position - - #print(ts, random_x, random_y) + ts_gaze_positions[ts] = gaze_position # Sleep a random time sleep_time = random.random() * (max_time - min_time) + min_time @@ -115,7 +125,31 @@ class TestDispersionBasedGazeMovementIdentifierClass(unittest.TestCase): def test_invalid_gaze_position(self): """Test DispersionBasedGazeMovementIdentifier fixation and saccade identification with invalid gaze position.""" - pass + size = 10 + center = (0, 0) + dispersion = 10 + start_time = time.time() + min_time = 0.01 + max_time = 0.1 + validity = [True, True, True, True, False, False, True, True, True, True] + + ts_gaze_positions = build_gaze_fixation(size, center, dispersion, start_time, min_time, max_time, validity) + + gaze_movement_identifier = DispersionBasedGazeMovementIdentifier.GazeMovementIdentifier(dispersion_threshold=dispersion, duration_threshold=min_time*2) + ts_fixations, ts_saccades, ts_status = gaze_movement_identifier.identify(ts_gaze_positions) + + # Check result size + self.assertEqual(len(ts_fixations), 1) + self.assertEqual(len(ts_saccades), 0) + self.assertEqual(len(ts_status), size-2) + + # Check fixation + ts, fixation = ts_fixations.pop_first() + + self.assertEqual(len(fixation.positions.keys()), size-2) + self.assertLessEqual(fixation.dispersion, dispersion) + self.assertGreaterEqual(fixation.duration, size * min_time) + self.assertLessEqual(fixation.duration, size * max_time) if __name__ == '__main__': |