aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThéo de la Hogue2023-07-10 15:03:45 +0200
committerThéo de la Hogue2023-07-10 15:03:45 +0200
commit26f4046baa96ea50185d9d7905bd23ab5591b983 (patch)
treed37edb4f184f3139a978c281748df3e9777264c0 /src
parente47d877022a1cb583d914690018a18958dff99ad (diff)
downloadargaze-26f4046baa96ea50185d9d7905bd23ab5591b983.zip
argaze-26f4046baa96ea50185d9d7905bd23ab5591b983.tar.gz
argaze-26f4046baa96ea50185d9d7905bd23ab5591b983.tar.bz2
argaze-26f4046baa96ea50185d9d7905bd23ab5591b983.tar.xz
Refinning time tests.
Diffstat (limited to 'src')
-rw-r--r--src/argaze.test/GazeAnalysis/DispersionThresholdIdentification.py89
1 files changed, 59 insertions, 30 deletions
diff --git a/src/argaze.test/GazeAnalysis/DispersionThresholdIdentification.py b/src/argaze.test/GazeAnalysis/DispersionThresholdIdentification.py
index 09eb58b..42b1675 100644
--- a/src/argaze.test/GazeAnalysis/DispersionThresholdIdentification.py
+++ b/src/argaze.test/GazeAnalysis/DispersionThresholdIdentification.py
@@ -10,6 +10,7 @@ __license__ = "BSD"
import unittest
import random
import time
+import math
from argaze import GazeFeatures
from argaze.GazeAnalysis import DispersionThresholdIdentification
@@ -40,8 +41,8 @@ def build_gaze_fixation(size: int, center: tuple, deviation_max: float, min_time
if valid:
# Edit gaze position
- random_x = center[0] + deviation_max * (random.random() - 0.5)
- random_y = center[1] + deviation_max * (random.random() - 0.5)
+ random_x = center[0] + deviation_max * (random.random() - 0.5) / math.sqrt(2)
+ random_y = center[1] + deviation_max * (random.random() - 0.5) / math.sqrt(2)
gaze_position = GazeFeatures.GazePosition((random_x, random_y))
else:
@@ -118,8 +119,8 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
self.assertEqual(len(fixation.positions.keys()), size)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertGreaterEqual(fixation.duration, (size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
def test_fixation_and_direct_saccade_identification(self):
@@ -143,15 +144,15 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
# Check result size
self.assertEqual(len(ts_fixations), 2)
self.assertEqual(len(ts_saccades), 1)
- self.assertEqual(len(ts_status), size*2)
+ self.assertEqual(len(ts_status), size * 2)
# Check first fixation
ts, fixation = ts_fixations.pop_first()
self.assertEqual(len(fixation.positions.keys()), size)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertGreaterEqual(fixation.duration, (size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
# Check first saccade
@@ -159,18 +160,32 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
self.assertEqual(len(saccade.positions.keys()), 2)
self.assertGreaterEqual(saccade.duration, min_time)
- self.assertLessEqual(saccade.duration, max_time + 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)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ 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 DispersionThresholdIdentification fixation and saccade identification."""
@@ -195,34 +210,48 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
# Check result size
self.assertEqual(len(ts_fixations), 2)
self.assertEqual(len(ts_saccades), 1)
- self.assertEqual(len(ts_status), size*2 + move)
+ self.assertEqual(len(ts_status), size * 2 + move)
# Check first fixation
ts, fixation = ts_fixations.pop_first()
self.assertEqual(len(fixation.positions.keys()), size)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ self.assertGreaterEqual(fixation.duration, (size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
# Check first saccade
ts, saccade = ts_saccades.pop_first()
self.assertEqual(len(saccade.positions.keys()), move + 2)
- self.assertGreaterEqual(saccade.duration, min_time)
- self.assertLessEqual(saccade.duration, max_time + 2 * min_time)
+ 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)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, size * min_time)
- self.assertLessEqual(fixation.duration, size * max_time)
+ 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 DispersionThresholdIdentification fixation and saccade identification with invalid gaze position."""
@@ -248,8 +277,8 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
self.assertEqual(len(fixation.positions.keys()), 7)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, 7 * min_time)
- self.assertLessEqual(fixation.duration, 7 * max_time)
+ self.assertGreaterEqual(fixation.duration, 6 * min_time)
+ self.assertLessEqual(fixation.duration, 6 * max_time)
self.assertLessEqual(fixation.finished, True)
# Check second fixation
@@ -257,8 +286,8 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
self.assertEqual(len(fixation.positions.keys()), 5)
self.assertLessEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, 5 * min_time)
- self.assertLessEqual(fixation.duration, 5 * max_time)
+ self.assertGreaterEqual(fixation.duration, 4 * min_time)
+ self.assertLessEqual(fixation.duration, 4 * max_time)
self.assertLessEqual(fixation.finished, True)
def test_fixation_overlapping(self):
@@ -268,7 +297,7 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
center_A = (0, 0)
center_B = (50, 50)
center_C = (55, 55)
- deviation_max = 10
+ deviation_max = 15
min_time = 0.01
max_time = 0.1
@@ -315,10 +344,10 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
# Check unique fixation
ts, fixation = ts_fixations.pop_first()
- self.assertEqual(len(fixation.positions.keys()), size*2)
+ self.assertEqual(len(fixation.positions.keys()), size * 2)
#self.assertGreaterEqual(fixation.deviation_max, deviation_max)
- self.assertGreaterEqual(fixation.duration, 2 * size * min_time)
- self.assertLessEqual(fixation.duration, 2 * size * max_time)
+ self.assertGreaterEqual(fixation.duration, (2 * size - 1) * min_time)
+ self.assertLessEqual(fixation.duration, (2 * size - 1) * max_time)
self.assertLessEqual(fixation.finished, True)
def test_identification_browsing(self):
@@ -350,15 +379,15 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
self.assertEqual(len(finished_gaze_movement.positions.keys()), size)
self.assertLessEqual(finished_gaze_movement.deviation_max, deviation_max)
- self.assertGreaterEqual(finished_gaze_movement.duration, size * min_time)
- self.assertLessEqual(finished_gaze_movement.duration, size * max_time)
+ self.assertGreaterEqual(finished_gaze_movement.duration, (size-1) * min_time)
+ self.assertLessEqual(finished_gaze_movement.duration, (size-1) * max_time)
self.assertLessEqual(finished_gaze_movement.finished, True)
elif GazeFeatures.is_saccade(finished_gaze_movement):
self.assertEqual(len(finished_gaze_movement.positions.keys()), 2)
self.assertGreaterEqual(finished_gaze_movement.duration, min_time)
- self.assertLessEqual(finished_gaze_movement.duration, max_time + min_time)
+ self.assertLessEqual(finished_gaze_movement.duration, max_time)
self.assertLessEqual(finished_gaze_movement.finished, True)
# Check that last gaze position date is not equal to given gaze position date
@@ -409,8 +438,8 @@ class TestDispersionThresholdIdentificationClass(unittest.TestCase):
elif GazeFeatures.is_saccade(finished_gaze_movement):
self.assertEqual(len(finished_gaze_movement.positions.keys()), 2)
- self.assertGreaterEqual(finished_gaze_movement.duration, min_time)
- self.assertLessEqual(finished_gaze_movement.duration, max_time + min_time)
+ self.assertGreaterEqual(finished_gaze_movement.duration, 2 * min_time)
+ self.assertLessEqual(finished_gaze_movement.duration, 2 * max_time)
self.assertLessEqual(finished_gaze_movement.finished, True)
if __name__ == '__main__':