aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/KCoefficient.py
blob: 9e2f3179cfd9dbcd04aaf0dbd26bff39fe2506f8 (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
137
138
"""K coefficient and K-modified coefficient 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 <https://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):
    """Implementation of the K coefficient algorithm as described in:

        **Krejtz K., Duchowski A., Krejtz I., Szarkowska A., & Kopacz A. (2016).**  
        *Discerning ambient/focal attention with coefficient K.*  
        ACM Transactions on Applied Perception (TAP, 1–20).  
        [https://doi.org/10.1145/2896452](https://doi.org/10.1145/2896452)
    """

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

        # Init ScanPathAnalyzer class
        super().__init__()

        self.__K = 0

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

        assert(len(scan_path) > 1)

        durations = []
        amplitudes = []

        for scan_step in scan_path:

            durations.append(scan_step.duration)
            amplitudes.append(scan_step.last_saccade.amplitude)

        durations = numpy.array(durations)
        amplitudes = numpy.array(amplitudes)

        duration_mean = numpy.mean(durations)
        amplitude_mean = numpy.mean(amplitudes)

        duration_std = numpy.std(durations)
        amplitude_std = numpy.std(amplitudes)

        if duration_std > 0. and amplitude_std > 0.:

            Ks = []
            for scan_step in scan_path:

                Ks.append((abs(scan_step.duration - duration_mean) / duration_std) - (abs(scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std))

            self.__K = numpy.array(Ks).mean()

        else:

            self.__K = 0.

    @property
    def K(self) -> float:
        """K coefficient."""

        return self.__K

class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer):
    """Implementation of the K-modified coefficient algorithm as described in:

        **Lounis, C. A., Hassoumi, A., Lefrancois, O., Peysakhovich, V., & Causse, M. (2020, June).**  
        *Detecting ambient/focal visual attention in professional airline pilots with a modified Coefficient K: a full flight simulator study.*  
        ACM Symposium on Eye Tracking Research and Applications (ETRA'20, 1-6).  
        [https://doi.org/10.1145/3379157.3391412](https://doi.org/10.1145/3379157.3391412)
    """

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

        # Init AOIScanPathAnalyzer class
        super().__init__()

        self.__K = 0

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

        assert(len(aoi_scan_path) > 1)

        durations = []
        amplitudes = []

        for aoi_scan_step in aoi_scan_path:

            durations.append(aoi_scan_step.duration)
            amplitudes.append(aoi_scan_step.last_saccade.amplitude)

        durations = numpy.array(durations)
        amplitudes = numpy.array(amplitudes)

        duration_mean = numpy.mean(durations)
        amplitude_mean = numpy.mean(amplitudes)

        duration_std = numpy.std(durations)
        amplitude_std = numpy.std(amplitudes)

        if duration_std > 0. and amplitude_std > 0.:

            Ks = []
            for aoi_scan_step in aoi_scan_path:

                Ks.append((abs(aoi_scan_step.duration - duration_mean) / duration_std) - (abs(aoi_scan_step.last_saccade.amplitude - amplitude_mean) / amplitude_std))

            self.__K = numpy.array(Ks).mean()

        else:

            self.__K = 0.

    @property
    def K(self) -> float:
        """K coefficient."""

        return self.__K