From ab858678c7e16f5ca38afe53525e3b3e87aa7f76 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Thu, 10 Aug 2023 09:02:16 +0200 Subject: Allowing to load plugins from other package. Renaming times in execution_times, aoi_matcher in aoi_fixation_matcher. --- src/argaze/ArFeatures.py | 99 ++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 53 deletions(-) diff --git a/src/argaze/ArFeatures.py b/src/argaze/ArFeatures.py index 476e413..0b53034 100644 --- a/src/argaze/ArFeatures.py +++ b/src/argaze/ArFeatures.py @@ -33,15 +33,6 @@ ArSceneType = TypeVar('ArScene', bound="ArScene") ArFrameType = TypeVar('ArFrame', bound="ArFrame") # Type definition for type annotation convenience -class EnvironmentJSONLoadingFailed(Exception): - """ - Exception raised by ArEnvironment when JSON loading fails. - """ - - def __init__(self, message): - - super().__init__(message) - class PoseEstimationFailed(Exception): """ Exception raised by ArScene estimate_pose method when the pose can't be estimated due to unconsistencies. @@ -62,6 +53,15 @@ class SceneProjectionFailed(Exception): super().__init__(message) +class JSONLoadingFailed(Exception): + """ + Exception raised when JSON loading fails. + """ + + def __init__(self, message): + + super().__init__(message) + @dataclass class ArFrame(): """ @@ -223,8 +223,6 @@ class ArFrame(): for scan_path_analyzer_module_path, scan_path_analyzer_parameters in new_scan_path_analyzers_value.items(): - print(scan_path_analyzer_module_path) - # Prepend argaze.GazeAnalysis path when a single name is provided if len(scan_path_analyzer_module_path.split('.')) == 1: scan_path_analyzer_module_path = f'argaze.GazeAnalysis.{scan_path_analyzer_module_path}' @@ -240,21 +238,17 @@ class ArFrame(): for parameter, parameter_type in member[1].items(): - # Check if parameter is part of argaze.GazeAnalysis module - parameter_module_path = parameter_type.__module__.split('.') - - if len(parameter_module_path) == 3: + # Check if parameter is part of a package + if len(parameter_type.__module__.split('.')) > 1: - if parameter_module_path[0] == 'argaze' and parameter_module_path[1] == 'GazeAnalysis': + # Try get existing analyzer instance to append as parameter + try: - # Try get existing analyzer instance to append as parameter - try: + scan_path_analyzer_parameters[parameter] = new_scan_path_analyzers[parameter_type.__module__] - scan_path_analyzer_parameters[parameter] = new_scan_path_analyzers[parameter_module_path[2]] + except KeyError: - except KeyError: - - raise EnvironmentJSONLoadingFailed(f'{scan_path_analyzer_module_path} scan path analyzer loading fails because {parameter_module_path[2]} scan path analyzer is missing.') + raise JSONLoadingFailed(f'{scan_path_analyzer_module_path} scan path analyzer loading fails because {parameter_type.__module__} scan path analyzer is missing.') scan_path_analyzer = scan_path_analyzer_module.ScanPathAnalyzer(**scan_path_analyzer_parameters) @@ -309,18 +303,17 @@ class ArFrame(): # Check if parameter is part of argaze.GazeAnalysis module parameter_module_path = parameter_type.__module__.split('.') - if len(parameter_module_path) == 3: - - if parameter_module_path[0] == 'argaze' and parameter_module_path[1] == 'GazeAnalysis': + # Check if parameter is part of a package + if len(parameter_type.__module__.split('.')) > 1: - # Try get existing analyzer instance to append as parameter - try: + # Try get existing analyzer instance to append as parameter + try: - aoi_scan_path_analyzer_parameters[parameter] = new_aoi_scan_path_analyzers[parameter_module_path[2]] + aoi_scan_path_analyzer_parameters[parameter] = new_aoi_scan_path_analyzers[parameter_type.__module__] - except KeyError: + except KeyError: - raise EnvironmentJSONLoadingFailed(f'{aoi_scan_path_analyzer_module_path} aoi scan path analyzer loading fails because {parameter_module_path[2]} aoi scan path analyzer is missing.') + raise JSONLoadingFailed(f'{aoi_scan_path_analyzer_module_path} aoi scan path analyzer loading fails because {parameter_type.__module__} aoi scan path analyzer is missing.') aoi_scan_path_analyzer = aoi_scan_path_analyzer_module.AOIScanPathAnalyzer(**aoi_scan_path_analyzer_parameters) @@ -511,10 +504,10 @@ class ArFrame(): scan_step_analysis = {} aoi_scan_step_analysis = {} - # Assess look processing times - times = { + # Assess pipeline execution times + execution_times = { 'gaze_movement_identifier': None, - 'aoi_matcher': None, + 'aoi_fixation_matcher': None, 'scan_step_analyzers':{}, 'aoi_scan_step_analyzers': {}, 'heatmap': None @@ -535,7 +528,7 @@ class ArFrame(): temp_gaze_movement = self.gaze_movement_identifier.identify(timestamp, self.__gaze_position) # Assess movement identification time in ms - times['gaze_movement_identifier'] = (time.perf_counter() - identification_start) * 1e3 + execution_times['gaze_movement_identifier'] = (time.perf_counter() - identification_start) * 1e3 # Use given identified gaze movement else: @@ -554,7 +547,7 @@ class ArFrame(): self.__update_looked_aoi_data(temp_gaze_movement) # Assess aoi matching time in ms - times['aoi_matcher'] = (time.perf_counter() - matching_start) * 1e3 + execution_times['aoi_fixation_matcher'] = (time.perf_counter() - matching_start) * 1e3 # Append fixation to scan path if self.scan_path != None: @@ -578,7 +571,7 @@ class ArFrame(): aoi_scan_path_analyzer.analyze(self.aoi_scan_path) # Assess aoi scan step analysis time in ms - times['aoi_scan_step_analyzers'][aoi_scan_path_analyzer_module_path] = (time.perf_counter() - aoi_scan_step_analysis_start) * 1e3 + execution_times['aoi_scan_step_analyzers'][aoi_scan_path_analyzer_module_path] = (time.perf_counter() - aoi_scan_step_analysis_start) * 1e3 # Store analysis aoi_scan_step_analysis[aoi_scan_path_analyzer_module_path] = aoi_scan_path_analyzer.analysis @@ -605,7 +598,7 @@ class ArFrame(): scan_path_analyzer.analyze(self.scan_path) # Assess scan step analysis time in ms - times['scan_step_analyzers'][scan_path_analyzer_module_path] = (time.perf_counter() - scan_step_analysis_start) * 1e3 + execution_times['scan_step_analyzers'][scan_path_analyzer_module_path] = (time.perf_counter() - scan_step_analysis_start) * 1e3 # Store analysis scan_step_analysis[scan_path_analyzer_module_path] = scan_path_analyzer.analysis @@ -631,7 +624,7 @@ class ArFrame(): self.__update_looked_aoi_data(current_fixation) # Assess aoi matching time in ms - times['aoi_matcher'] = (time.perf_counter() - matching_start) * 1e3 + execution_times['aoi_fixation_matcher'] = (time.perf_counter() - matching_start) * 1e3 # Update heatmap if self.heatmap: @@ -646,7 +639,7 @@ class ArFrame(): self.heatmap.update(self.__gaze_position.value * scale) # Assess heatmap time in ms - times['heatmap'] = (time.perf_counter() - heatmap_start) * 1e3 + execution_times['heatmap'] = (time.perf_counter() - heatmap_start) * 1e3 except Exception as e: @@ -660,33 +653,33 @@ class ArFrame(): # Unlock frame exploitation self.__look_lock.release() - # Sum all times - total_time = 0 + # Sum all execution times + total_execution_time = 0 - if times['gaze_movement_identifier']: + if execution_times['gaze_movement_identifier']: - total_time += times['gaze_movement_identifier'] + total_execution_time += execution_times['gaze_movement_identifier'] - if times['aoi_matcher']: + if execution_times['aoi_fixation_matcher']: - total_time += times['aoi_matcher'] + total_execution_time += execution_times['aoi_fixation_matcher'] - for _, scan_step_analysis_time in times['scan_step_analyzers'].items(): + for _, scan_step_analysis_time in execution_times['scan_step_analyzers'].items(): - total_time += scan_step_analysis_time + total_execution_time += scan_step_analysis_time - for _, aoi_scan_step_analysis_time in times['aoi_scan_step_analyzers'].items(): + for _, aoi_scan_step_analysis_time in execution_times['aoi_scan_step_analyzers'].items(): - total_time += aoi_scan_step_analysis_time + total_execution_time += aoi_scan_step_analysis_time - if times['heatmap']: + if execution_times['heatmap']: - total_time += times['heatmap'] + total_execution_time += execution_times['heatmap'] - times['total'] = total_time + execution_times['total'] = total_execution_time # Return look data - return temp_gaze_movement, scan_step_analysis, aoi_scan_step_analysis, times, exception + return temp_gaze_movement, scan_step_analysis, aoi_scan_step_analysis, execution_times, exception def draw(self, image:numpy.array, aoi_color=(0, 0, 0)) -> Exception: """ -- cgit v1.1