aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/ExploitExploreRatio.py
blob: 0c55170e3e7518f660110ce33379f307f70b6c0d (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
#!/usr/bin/env python

"""Implementation of exploit vs explore ratio algorithm as described in:

    **Goldberg J. H., Kotval X. P. (1999).**  
    *Computer interface evaluation using eye movements: methods and constructs.*   
    International Journal of Industrial Ergonomics (631–645).  
    [https://doi.org/10.1016/S0169-8141(98)00068-7](https://doi.org/10.1016/S0169-8141\\(98\\)00068-7)  
        
    **Dehais F., Peysakhovich V., Scannella S., Fongue J., Gateau T. (2015).**  
    *Automation surprise in aviation: Real-time solutions.*  
    Proceedings of the 33rd annual ACM conference on Human Factors in Computing Systems (2525–2534).  
    [https://doi.org/10.1145/2702123.2702521](https://doi.org/10.1145/2702123.2702521)
"""

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

from dataclasses import dataclass, field

from argaze import GazeFeatures

import numpy

@dataclass
class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer):
    """
    Parameters:
        short_fixation_duration_threshold: time below which a fixation is considered to be short and so as exploratory.
    """

    short_fixation_duration_threshold: float = field(default=0.)
    
    def __post_init__(self):

        super().__init__()

        self.__exploit_explore_ratio = 0.

    def analyze(self, scan_path: GazeFeatures.ScanPathType):
        """Analyze scan path."""

        assert(len(scan_path) > 1)

        short_fixations_durations = []
        long_fixations_durations = []
        saccades_durations = []

        for scan_step in scan_path:

            if scan_step.first_fixation.duration > self.short_fixation_duration_threshold:

                long_fixations_durations.append(scan_step.first_fixation.duration)

            else:

                short_fixations_durations.append(scan_step.first_fixation.duration)

            saccades_durations.append(scan_step.last_saccade.duration)

        short_fixations_duration = numpy.array(short_fixations_durations).sum()
        long_fixations_duration = numpy.array(long_fixations_durations).sum()
        saccades_duration = numpy.array(saccades_durations).sum()

        assert(saccades_duration + short_fixations_duration > 0)

        self.__exploit_explore_ratio = long_fixations_duration / (saccades_duration + short_fixations_duration)

    @property
    def exploit_explore_ratio(self) -> float:
        
        return self.__exploit_explore_ratio