From 9e13b3f7f5191301256a8a4e657b1ec74d78f356 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Mon, 19 Dec 2022 15:53:28 +0100 Subject: Processing GazeMovement distance not only in Saccade. --- src/argaze/GazeFeatures.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py index f3fa45a..2b5cdde 100644 --- a/src/argaze/GazeFeatures.py +++ b/src/argaze/GazeFeatures.py @@ -139,6 +139,9 @@ class GazeMovement(): duration: float = field(init=False) """Inferred duration from first and last timestamps.""" + distance: float = field(init=False) + """Inferred distance from first and last positions.""" + def __post_init__(self): start_position_ts, start_position = self.positions.first @@ -147,6 +150,14 @@ class GazeMovement(): # Update frozen duration attribute object.__setattr__(self, 'duration', end_position_ts - start_position_ts) + _, start_position = self.positions.first + _, end_position = self.positions.last + + distance = numpy.linalg.norm( numpy.array(start_position.value) - numpy.array(end_position.value)) + + # Update frozen distance attribute + object.__setattr__(self, 'distance', distance) + def __str__(self) -> str: """String display""" @@ -168,21 +179,10 @@ class Fixation(GazeMovement): class Saccade(GazeMovement): """Define abstract saccade as gaze movement.""" - distance: float = field(init=False) - """Inferred distance from first and last positions.""" - def __post_init__(self): super().__post_init__() - _, start_position = self.positions.first - _, end_position = self.positions.last - - distance = numpy.linalg.norm( numpy.array(start_position.value) - numpy.array(end_position.value)) - - # Update frozen distance attribute - object.__setattr__(self, 'distance', distance) - TimeStampedGazeMovementsType = TypeVar('TimeStampedGazeMovements', bound="TimeStampedGazeMovements") # Type definition for type annotation convenience -- cgit v1.1