""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ __author__ = "Théo de la Hogue" __credits__ = [] __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" __license__ = "GPLv3" import json import math from argaze import DataFeatures class PupillDiameter(float, DataFeatures.TimestampedObject): """Define pupill diameter as a single float value. Parameters: value: pupill diameter value. """ def __new__(cls, value: float = math.nan, **kwargs): return float.__new__(cls, value) def __init__(self, value: float = math.nan, **kwargs): super().__init__(**kwargs) @property def value(self): """Get pupill diameter value.""" return float(self) class TimeStampedPupillDiameters(DataFeatures.TimestampedObjectsList): """Handle timestamped pupill diamters into a list.""" def __init__(self, pupill_diameters: list = []): DataFeatures.TimestampedObjectsList.__init__(self, PupillDiameter, pupill_diameters) class PupillDiameterAnalyzer(DataFeatures.PipelineStepObject): """Abstract class to define what should provide a pupill diameter analyser.""" @DataFeatures.PipelineStepMethod def analyze(self, pupill_diameter: PupillDiameter) -> any: """Analyze pupill diameter from successive timestamped pupill diameters.""" raise NotImplementedError('analyze() method not implemented') def browse(self, ts_pupill_diameters: TimeStampedPupillDiameters) -> list: """Analyze by browsing timestamped pupill diameters. Parameters: ts_pupill_diameters: list of timestamped pupill diameters. Returns: ts_analysis: list of (timestamp, analysis). """ assert(type(ts_pupill_diameters) == TimeStampedPupillDiameters) # TODO: Have TimestampedDataDictionary and TimestampedDataDictionaryList classes? ts_analyzis = [] # Iterate on pupill diameters for pupill_diameter in ts_pupill_diameters: analysis = self.analyze(pupill_diameter.timestamp, pupill_diameter) if analysis is not None: ts_analyzis.append((pupill_diameter.timestamp, analysis)) return ts_analyzis