aboutsummaryrefslogtreecommitdiff
path: root/src/argaze.test/PupillAnalysis/WorkloadIndex.py
blob: ebb043a9cff4a71cb1f5b431423581b9a753aca3 (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
""" 

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 <https://www.gnu.org/licenses/>.
"""

__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "GPLv3"

import unittest
import math

from argaze import PupilFeatures
from argaze.PupilAnalysis import WorkloadIndex

class TestWorkloadIndexClass(unittest.TestCase):
    """Test WorkloadIndex class."""

    def test_analysis(self):
        """Test WorkloadIndex analysis."""

        ts_pupill_diameters = {
            0: PupillFeatures.PupillDiameter(1.),
            1: PupillFeatures.PupillDiameter(1.1),
            2: PupillFeatures.PupillDiameter(1.2),
            3: PupillFeatures.PupillDiameter(1.3),
            4: PupillFeatures.PupillDiameter(1.2),
            5: PupillFeatures.PupillDiameter(1.1),
            6: PupillFeatures.PupillDiameter(1.),
            7: PupillFeatures.PupillDiameter(0.9),
            8: PupillFeatures.PupillDiameter(0.8),
            9: PupillFeatures.PupillDiameter(0.7)
        }

        pupill_diameter_analyzer = WorkloadIndex.PupillDiameterAnalyzer(reference=PupillFeatures.PupillDiameter(1.), period=3)
        ts_analysis = pupill_diameter_analyzer.browse(PupillFeatures.TimeStampedPupillDiameters(ts_pupill_diameters))

        # Check result size
        self.assertEqual(len(ts_analysis), 3)

        # Check each workload index
        ts_1, analysis_1 = ts_analysis.pop_first()
        self.assertEqual(ts_1, 3)
        self.assertTrue(math.isclose(analysis_1, 0.1, abs_tol=1e-2))

        ts_2, analysis_2 = ts_analysis.pop_first()
        self.assertEqual(ts_2, 6)
        self.assertTrue(math.isclose(analysis_2, 0.2, abs_tol=1e-2))

        ts_3, analysis_3 = ts_analysis.pop_first()
        self.assertEqual(ts_3, 9)
        self.assertTrue(math.isclose(analysis_3, -0.1, abs_tol=1e-2))
    
if __name__ == '__main__':

    unittest.main()