From c898884a2e4af5d46157eec6719d622b41e1aab7 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Mon, 3 Jul 2023 14:32:49 +0200 Subject: Looking for AOI/ScanPathAnalyzer properties to prepare analysis propery output. Initializing super class. --- src/argaze/GazeAnalysis/Basic.py | 16 +++++++---- src/argaze/GazeAnalysis/Entropy.py | 2 ++ src/argaze/GazeAnalysis/ExploitExploreRatio.py | 2 ++ src/argaze/GazeAnalysis/KCoefficient.py | 4 +++ src/argaze/GazeAnalysis/LempelZivComplexity.py | 2 ++ src/argaze/GazeAnalysis/NGram.py | 18 ++++++++---- src/argaze/GazeAnalysis/NearestNeighborIndex.py | 2 ++ src/argaze/GazeAnalysis/TransitionMatrix.py | 2 ++ src/argaze/GazeFeatures.py | 37 ++++++++++++++++++++++++- 9 files changed, 73 insertions(+), 12 deletions(-) diff --git a/src/argaze/GazeAnalysis/Basic.py b/src/argaze/GazeAnalysis/Basic.py index 69e5793..d6a8ca1 100644 --- a/src/argaze/GazeAnalysis/Basic.py +++ b/src/argaze/GazeAnalysis/Basic.py @@ -20,17 +20,19 @@ class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): def __post_init__(self): - self.__lenght = 0 + super().__init__() + + self.__length = 0 def analyze(self, scan_path: GazeFeatures.ScanPathType): """Analyze scan path.""" - self.__lenght = len(scan_path) + self.__length = len(scan_path) @property def length(self) -> float: - return self.__lenght + return self.__length @dataclass class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): @@ -38,14 +40,16 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): def __post_init__(self): - self.__lenght = 0 + super().__init__() + + self.__length = 0 def analyze(self, scan_path: GazeFeatures.ScanPathType): """Analyze scan path.""" - self.__lenght = len(scan_path) + self.__length = len(scan_path) @property def length(self) -> float: - return self.__lenght \ No newline at end of file + return self.__length \ No newline at end of file diff --git a/src/argaze/GazeAnalysis/Entropy.py b/src/argaze/GazeAnalysis/Entropy.py index 56f78d9..ba1c17c 100644 --- a/src/argaze/GazeAnalysis/Entropy.py +++ b/src/argaze/GazeAnalysis/Entropy.py @@ -33,6 +33,8 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__stationary_entropy = -1 self.__transition_entropy = -1 diff --git a/src/argaze/GazeAnalysis/ExploitExploreRatio.py b/src/argaze/GazeAnalysis/ExploitExploreRatio.py index a1a2e6b..0c55170 100644 --- a/src/argaze/GazeAnalysis/ExploitExploreRatio.py +++ b/src/argaze/GazeAnalysis/ExploitExploreRatio.py @@ -35,6 +35,8 @@ class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__exploit_explore_ratio = 0. def analyze(self, scan_path: GazeFeatures.ScanPathType): diff --git a/src/argaze/GazeAnalysis/KCoefficient.py b/src/argaze/GazeAnalysis/KCoefficient.py index d384a05..46ecca3 100644 --- a/src/argaze/GazeAnalysis/KCoefficient.py +++ b/src/argaze/GazeAnalysis/KCoefficient.py @@ -26,6 +26,8 @@ class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__K = 0 def analyze(self, scan_path: GazeFeatures.ScanPathType): @@ -75,6 +77,8 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__K = 0 def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType) -> float: diff --git a/src/argaze/GazeAnalysis/LempelZivComplexity.py b/src/argaze/GazeAnalysis/LempelZivComplexity.py index 64a309f..c836235 100644 --- a/src/argaze/GazeAnalysis/LempelZivComplexity.py +++ b/src/argaze/GazeAnalysis/LempelZivComplexity.py @@ -24,6 +24,8 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__lempel_ziv_complexity = 0 def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType): diff --git a/src/argaze/GazeAnalysis/NGram.py b/src/argaze/GazeAnalysis/NGram.py index 1ae8a07..662060e 100644 --- a/src/argaze/GazeAnalysis/NGram.py +++ b/src/argaze/GazeAnalysis/NGram.py @@ -22,13 +22,17 @@ from argaze import GazeFeatures class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): """ Parameters: - n: lenght of grams to search. + n_min: minimal grams length to search. + n_max: maximal grams length to search. """ - n: int = field(default=2) + n_min: int = field(default=2) + n_max: int = field(default=2) def __post_init__(self): + super().__init__() + self.__ngrams_count = {} def analyze(self, aoi_scan_path: GazeFeatures.AOIScanPathType): @@ -38,10 +42,14 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): sequence = str(aoi_scan_path) - ngrams = zip(*[sequence[i:] for i in range(self.n)]) - ngrams = [ngram for ngram in ngrams] + self.__ngrams_count = {} + + for n in range(self.n_min, self.n_max + 1): + + ngrams = zip(*[sequence[i:] for i in range(n)]) + ngrams = [ngram for ngram in ngrams] - self.__ngrams_count = {tuple([aoi_scan_path.get_letter_aoi(l) for l in ngram]) : ngrams.count(ngram) for ngram in ngrams} + self.__ngrams_count[n] = {tuple([aoi_scan_path.get_letter_aoi(l) for l in ngram]) : ngrams.count(ngram) for ngram in ngrams} @property def ngrams_count(self) -> dict: diff --git a/src/argaze/GazeAnalysis/NearestNeighborIndex.py b/src/argaze/GazeAnalysis/NearestNeighborIndex.py index cf29169..33b3333 100644 --- a/src/argaze/GazeAnalysis/NearestNeighborIndex.py +++ b/src/argaze/GazeAnalysis/NearestNeighborIndex.py @@ -33,6 +33,8 @@ class ScanPathAnalyzer(GazeFeatures.ScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__nearest_neighbor_index = 0 def analyze(self, scan_path: GazeFeatures.ScanPathType): diff --git a/src/argaze/GazeAnalysis/TransitionMatrix.py b/src/argaze/GazeAnalysis/TransitionMatrix.py index 6d7451d..ab10989 100644 --- a/src/argaze/GazeAnalysis/TransitionMatrix.py +++ b/src/argaze/GazeAnalysis/TransitionMatrix.py @@ -26,6 +26,8 @@ class AOIScanPathAnalyzer(GazeFeatures.AOIScanPathAnalyzer): def __post_init__(self): + super().__init__() + self.__transition_matrix_probabilities = pandas.DataFrame() self.__transition_matrix_density = 0. diff --git a/src/argaze/GazeFeatures.py b/src/argaze/GazeFeatures.py index 620903a..f26a3ed 100644 --- a/src/argaze/GazeFeatures.py +++ b/src/argaze/GazeFeatures.py @@ -19,6 +19,7 @@ from dataclasses import dataclass, field import math import ast import json +from inspect import getmembers from argaze import DataStructures @@ -562,7 +563,24 @@ class ScanPath(list): class ScanPathAnalyzer(): """Abstract class to define what should provide a scan path analyzer.""" - def analyze(self, scan_path: ScanPathType) -> Any: + def __init__(self): + + self.__properties = [name for (name, value) in getmembers(type(self), lambda v: isinstance(v, property))] + + @property + def analysis(self) -> dict: + + analysis = {} + + for p in self.__properties: + + if p != 'analysis': + + analysis[p] = getattr(self, p) + + return analysis + + def analyze(self, scan_path: ScanPathType): """Analyze scan path.""" raise NotImplementedError('analyze() method not implemented') @@ -784,6 +802,23 @@ class AOIScanPath(list): class AOIScanPathAnalyzer(): """Abstract class to define what should provide a aoi scan path analyzer.""" + def __init__(self): + + self.__properties = [name for (name, value) in getmembers(type(self), lambda v: isinstance(v, property))] + + @property + def analysis(self) -> dict: + + analysis = {} + + for p in self.__properties: + + if p != 'analysis': + + analysis[p] = getattr(self, p) + + return analysis + def analyze(self, aoi_scan_path: AOIScanPathType): """Analyze aoi scan path.""" -- cgit v1.1