blob: 1f3c586570359aeb69fcc29116a4a3d46dba9a35 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#!/usr/bin/env python
""" """
__author__ = "Théo de la Hogue"
__credits__ = ["Jean-Paul Imbert"]
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from typing import TypeVar
from dataclasses import dataclass, field
import math
from argaze import PupillFeatures
import numpy
@dataclass
class PupillDiameterAnalyzer(PupillFeatures.PupillDiameterAnalyzer):
"""Periodic average of pupill diameter variations to pupill diameter reference value."""
reference: PupillFeatures.PupillDiameter
""" """
period: int | float = field(default=1)
"""Identification period length."""
def __post_init__(self):
assert(self.reference.valid)
self.__variations_sum = 0.
self.__variations_number = 0
self.__last_ts = 0
@DataFeatures.PipelineStepMethod
def analyze(self, ts: int|float, pupill_diameter) -> float:
"""Analyze workload index from successive timestamped pupill diameters."""
# Ignore non valid pupill diameter
if not pupill_diameter.valid:
return None
if ts - 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 = ts
return workload_index
else:
self.__variations_sum += pupill_diameter.value - self.reference.value
self.__variations_number += 1
|