""" 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__ = ["Jean-Paul Imbert"] __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" __license__ = "GPLv3" import math from argaze import DataFeatures, PupillFeatures import numpy class PupillDiameterAnalyzer(PupillFeatures.PupillDiameterAnalyzer): """Periodic average of pupill diameter variations to pupill diameter reference value. Parameters: reference: base line value. period: identification period length. """ def __init__(self, reference: PupillFeatures.PupillDiameter, period: int|float = 1): assert(not math.isnan(self.__reference)) self.__reference = reference self.__period = period self.__variations_sum = 0. self.__variations_number = 0 self.__last_ts = 0 @property def reference(self) -> PupillFeatures.PupillDiameter: """Get workload index reference.""" return self.__reference @property def period(self) -> int|float: """Get workload index period.""" return self.__period @DataFeatures.PipelineStepMethod def analyze(self, pupill_diameter: PupillFeatures.PupillDiameter) -> float: """Analyze workload index from successive timestamped pupill diameters.""" # Ignore non valid pupill diameter if not math.isnan(pupill_diameter): return None if pupill_diameter.timestamp - self.__last_ts >= self.__period: if self.__variations_number > 0 and self.__reference.value > 0.: workload_index = (self.__variations_sum / self.__variations_number) / self.__reference.value else: workload_index = 0. self.__variations_sum = pupill_diameter.value - self.__reference.value self.__variations_number = 1 self.__last_ts = pupill_diameter.timestamp return workload_index else: self.__variations_sum += pupill_diameter.value - self.__reference.value self.__variations_number += 1