aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/Basic.py
blob: 063ee2b6dba8cf482577c296d7a55916bffb0b93 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
"""Basic analysis module.


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

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

from argaze import GazeFeatures, DataFeatures

import numpy

class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer):
    """Basic scan path analysis."""

    @DataFeatures.PipelineStepInit
    def __init__(self, **kwargs):

        # Init ScanPathAnalyzer class
        super().__init__()

        self.__path_duration = 0
        self.__steps_number = 0
        self.__step_fixation_durations_average = 0

    @DataFeatures.PipelineStepMethod
    def analyze(self, scan_path: GazeFeatures.ScanPath):

        self.__path_duration = scan_path.duration

        self.__steps_number = len(scan_path)

        sum_fixation_durations = 0

        for scan_step in scan_path:

            sum_fixation_durations += scan_step.fixation_duration

        self.__step_fixation_durations_average = sum_fixation_durations / self.__steps_number

    @property
    def path_duration(self) -> float:
        """Scan path duration."""

        return self.__path_duration

    @property
    def steps_number(self) -> float:
        """Scan path steps number."""

        return self.__steps_number

    @property
    def step_fixation_durations_average(self) -> float:
        """Scan path step fixation durations average."""

        return self.__step_fixation_durations_average
    
class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer):
    """Basic AOI scan path analysis."""

    @DataFeatures.PipelineStepInit
    def __init__(self, **kwargs):

        # Init AOIScanPathAnalyzer class
        super().__init__()

        self.__path_duration = 0
        self.__steps_number = 0
        self.__step_fixation_durations_average = 0
        self.__aoi_fixation_distribution = {}

    @DataFeatures.PipelineStepMethod
    def analyze(self, aoi_scan_path: GazeFeatures.ScanPath):

        self.__path_duration = aoi_scan_path.duration

        self.__steps_number = len(aoi_scan_path)

        sum_fixation_durations = 0
        self.__sum_aoi_fixation_durations = {}

        for aoi_scan_step in aoi_scan_path:

            sum_fixation_durations += aoi_scan_step.fixation_duration

            try:

                self.__sum_aoi_fixation_durations[aoi_scan_step.aoi] = self.__sum_aoi_fixation_durations[aoi_scan_step.aoi] + aoi_scan_step.fixation_duration

            except KeyError:

                self.__sum_aoi_fixation_durations[aoi_scan_step.aoi] = aoi_scan_step.fixation_duration

        self.__step_fixation_durations_average = sum_fixation_durations / self.__steps_number

        self.__aoi_fixation_distribution = {}

        for aoi_name, sum_aoi_fixation_duration in self.__sum_aoi_fixation_durations.items():

            self.__aoi_fixation_distribution[aoi_name] = sum_aoi_fixation_duration / sum_fixation_durations
        
    @property
    def path_duration(self) -> float:
        """AOI scan path duration."""

        return self.__path_duration

    @property
    def steps_number(self) -> float:
        """AOI scan path steps number."""

        return self.__steps_number

    @property
    def step_fixation_durations_average(self) -> float:
        """AOI scan path step fixation durations average."""

        return self.__step_fixation_durations_average

    @property
    def aoi_fixation_distribution(self) -> dict:
        """percentage of time spent on each AOI."""

        return self.__aoi_fixation_distribution