diff options
-rw-r--r-- | src/argaze/GazeFeatures.py | 22 |
1 files changed, 11 insertions, 11 deletions
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 |