aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/GazeAnalysis
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze.test/GazeAnalysis')
-rw-r--r--src/argaze.test/GazeAnalysis/VelocityThresholdIdentification.py112
1 files changed, 70 insertions, 42 deletions
diff --git a/src/argaze.test/GazeAnalysis/VelocityThresholdIdentification.py b/src/argaze.test/GazeAnalysis/VelocityThresholdIdentification.py
index 71a8daf..239bf45 100644
--- a/src/argaze.test/GazeAnalysis/VelocityThresholdIdentification.py
+++ b/src/argaze.test/GazeAnalysis/VelocityThresholdIdentification.py
@@ -30,6 +30,10 @@ def build_gaze_fixation(size: int, start_position: tuple, deviation_max: float,
for i in range(0, size):
+ # Sleep a random time
+ sleep_time = random.random() * (max_time - min_time) + min_time
+ time.sleep(sleep_time)
+
# Check position validity
valid = True
if len(validity) > i:
@@ -39,8 +43,8 @@ def build_gaze_fixation(size: int, start_position: tuple, deviation_max: float,
if valid:
# Edit gaze position
- random_x = last_valid_position[0] + deviation_max * (random.random() - 0.5)
- random_y = last_valid_position[1] + deviation_max * (random.random() - 0.5)
+ random_x = last_valid_position[0] + deviation_max * (random.random() - 0.5) / math.sqrt(2)
+ random_y = last_valid_position[1] + deviation_max * (random.random() - 0.5) / math.sqrt(2)
gaze_position = GazeFeatures.GazePosition((random_x, random_y))
@@ -55,10 +59,6 @@ def build_gaze_fixation(size: int, start_position: tuple, deviation_max: float,
ts = time.time() - start_time + start_ts
ts_gaze_positions[ts] = gaze_position
- # Sleep a random time
- sleep_time = random.random() * (max_time - min_time) + min_time
- time.sleep(sleep_time)
-
return ts_gaze_positions
def build_gaze_saccade(size: int, center_A: tuple, center_B: tuple, min_time: float, max_time: float, start_ts: float = 0., validity: list = []):
@@ -72,6 +72,10 @@ def build_gaze_saccade(size: int, center_A: tuple, center_B: tuple, min_time: fl
for i in range(0, size):
+ # Sleep a random time
+ sleep_time = random.random() * (max_time - min_time) + min_time
+ time.sleep(sleep_time)
+
# Check position validity
valid = True
if len(validity) > i:
@@ -93,10 +97,6 @@ def build_gaze_saccade(size: int, center_A: tuple, center_B: tuple, min_time: fl
ts = time.time() - start_time + start_ts
ts_gaze_positions[ts] = gaze_position
- # Sleep a random time
- sleep_time = random.random() * (max_time - min_time) + min_time
- time.sleep(sleep_time)
-
return ts_gaze_positions
class TestVelocityThresholdIdentificationClass(unittest.TestCase):
@@ -119,16 +119,16 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
# Check result size
self.assertEqual(len(ts_fixations), 1)
self.assertEqual(len(ts_saccades), 0)
- self.assertEqual(len(ts_status), size-1)
+ self.assertEqual(len(ts_status), size - 1)
# Check fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size-1)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertEqual(len(fixation.positions.keys()), size - 1)
+ self.assertGreaterEqual(fixation.duration, (size - 2) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 2) * max_time)
self.assertLessEqual(fixation.finished, True)
-
+
def test_fixation_and_direct_saccade_identification(self):
"""Test VelocityThresholdIdentification fixation and saccade identification."""
@@ -138,7 +138,7 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
deviation_max = 10
min_time = 0.05
max_time = 0.1
- velocity_max = math.sqrt(2) * deviation_max / min_time
+ velocity_max = deviation_max / min_time
ts_gaze_positions_A = build_gaze_fixation(size, center_A, deviation_max, min_time, max_time)
ts_gaze_positions_B = build_gaze_fixation(size, center_B, deviation_max, min_time, max_time, start_ts=ts_gaze_positions_A.last[0])
@@ -151,32 +151,46 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
# Check result size
self.assertEqual(len(ts_fixations), 2)
self.assertEqual(len(ts_saccades), 1)
- self.assertEqual(len(ts_status), size*2 - 1)
+ self.assertEqual(len(ts_status), size * 2 - 1)
# Check first fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size-1)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertEqual(len(fixation.positions.keys()), size - 1)
+ self.assertGreaterEqual(fixation.duration, (size - 2) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 2) * max_time)
self.assertLessEqual(fixation.finished, True)
# Check first saccade
ts, saccade = ts_saccades.pop_first()
- self.assertEqual(len(saccade.positions.keys()), 1)
- self.assertGreaterEqual(saccade.duration, 0.)
- self.assertLessEqual(saccade.duration, 0.)
+ self.assertEqual(len(saccade.positions.keys()), 2)
+ self.assertGreaterEqual(saccade.duration, min_time)
+ self.assertLessEqual(saccade.duration, max_time)
self.assertLessEqual(saccade.finished, True)
+ # Check that last position of a movement is equal to first position of next movement
+ last_ts, last_position = fixation.positions.last
+ first_ts, first_position = saccade.positions.first
+
+ self.assertEqual(last_ts, first_ts)
+ self.assertEqual(last_position.value, first_position.value)
+
# Check second fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size-1)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertEqual(len(fixation.positions.keys()), size)
+ self.assertGreaterEqual(fixation.duration, (size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
-
+
+ # Check that last position of a movement is equal to first position of next movement
+ last_ts, last_position = saccade.positions.last
+ first_ts, first_position = fixation.positions.first
+
+ self.assertEqual(last_ts, first_ts)
+ self.assertEqual(last_position.value, first_position.value)
+
def test_fixation_and_short_saccade_identification(self):
"""Test VelocityThresholdIdentification fixation and saccade identification."""
@@ -188,7 +202,7 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
deviation_max = 10
min_time = 0.05
max_time = 0.1
- velocity_max = math.sqrt(2) * deviation_max / min_time
+ velocity_max = deviation_max / min_time
ts_gaze_positions_A = build_gaze_fixation(size, center_A, deviation_max, min_time, max_time)
ts_move_positions = build_gaze_saccade(move, out_A, center_B, min_time, min_time, start_ts=ts_gaze_positions_A.last[0])
@@ -202,32 +216,46 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
# Check result size
self.assertEqual(len(ts_fixations), 2)
self.assertEqual(len(ts_saccades), 1)
- self.assertEqual(len(ts_status), 2 * size - 1 + move)
+ self.assertEqual(len(ts_status), 2 * size + move - 1)
# Check first fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size-1)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertEqual(len(fixation.positions.keys()), size - 1)
+ self.assertGreaterEqual(fixation.duration, (size - 2) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 2) * max_time)
self.assertLessEqual(fixation.finished, True)
# Check first saccade
ts, saccade = ts_saccades.pop_first()
- self.assertEqual(len(saccade.positions.keys()), move+1)
- self.assertGreaterEqual(saccade.duration, min_time)
- self.assertLessEqual(saccade.duration, max_time)
+ self.assertEqual(len(saccade.positions.keys()), move + 2)
+ self.assertGreaterEqual(saccade.duration, (move + 1) * min_time)
+ self.assertLessEqual(saccade.duration, (move + 1) * max_time)
self.assertLessEqual(saccade.finished, True)
+ # Check that last position of a movement is equal to first position of next movement
+ last_ts, last_position = fixation.positions.last
+ first_ts, first_position = saccade.positions.first
+
+ self.assertEqual(last_ts, first_ts)
+ self.assertEqual(last_position.value, first_position.value)
+
# Check second fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size-1)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertEqual(len(fixation.positions.keys()), size)
+ self.assertGreaterEqual(fixation.duration, (size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
+ # Check that last position of a movement is equal to first position of next movement
+ last_ts, last_position = saccade.positions.last
+ first_ts, first_position = fixation.positions.first
+
+ self.assertEqual(last_ts, first_ts)
+ self.assertEqual(last_position.value, first_position.value)
+
def test_invalid_gaze_position(self):
"""Test VelocityThresholdIdentification fixation and saccade identification with invalid gaze position."""
@@ -253,16 +281,16 @@ class TestVelocityThresholdIdentificationClass(unittest.TestCase):
ts, fixation = ts_fixations.pop_first()
self.assertEqual(len(fixation.positions.keys()), 6)
- self.assertGreaterEqual(fixation.duration, 6 * min_time)
- self.assertLessEqual(fixation.duration, 6 * max_time)
+ self.assertGreaterEqual(fixation.duration, 5 * min_time)
+ self.assertLessEqual(fixation.duration, 5 * max_time)
self.assertLessEqual(fixation.finished, True)
# Check second fixation
ts, fixation = ts_fixations.pop_first()
self.assertEqual(len(fixation.positions.keys()), 4)
- self.assertGreaterEqual(fixation.duration, 4 * min_time)
- self.assertLessEqual(fixation.duration, 4 * max_time)
+ self.assertGreaterEqual(fixation.duration, 3 * min_time)
+ self.assertLessEqual(fixation.duration, 3 * max_time)
self.assertLessEqual(fixation.finished, True)
if __name__ == '__main__':