def _execute_metrics(self): # Iterate over input GUI design files for input_gui_design_file in self.input_gui_design_files[ len(self.results):]: logger.info("Evaluating {}...".format(input_gui_design_file.name)) # Start total timer start_time_total: float = time.time() # Initialize GUI design results row results_row = {} results_row["filename"] = input_gui_design_file.name results_row["evaluation_date"] = date.today().isoformat() # Read GUI design image (PNG) start_time: float = time.time() gui_image_png_base64: str = utils.read_image(input_gui_design_file) end_time: float = time.time() results_row["read_image_time"] = round(end_time - start_time, 4) # Iterate over AIM metrics for metric in self._METRICS: # Import metric module metric_module = importlib.import_module("aim.metrics." + metric) # Execute metric start_time: float = time.time() metric_results: Optional[ List[Any]] = metric_module.Metric.execute_metric( gui_image_png_base64) end_time: float = time.time() results_row[metric.partition("_")[0] + "_time"] = round( end_time - start_time, 4) # Iterate over metrics results for index, metric_result in enumerate(metric_results): if type(metric_result) is float: results_row[metric.partition("_")[0] + "_result_" + str(index + 1)] = round(metric_result, 4) else: results_row[metric.partition("_")[0] + "_result_" + str(index + 1)] = metric_result # End total timer end_time_total: float = time.time() results_row["total_evaluation_time"] = round( end_time_total - start_time_total, 4) # Append results self.results.append(results_row) # Precaution against crashes: save results after each GUI design # evaluation instead of after completing all of them self._save_results()
def test_contour_density_desktop(input_value: str, expected_result: List[Any]) -> None: """ Test contour density (desktop GUIs). Args: input_value: GUI image file name expected_result: Expected result (list of measures) """ # Build GUI image file path gui_image_filepath: pathlib.Path = (pathlib.Path(DATA_TESTS_DIR) / input_value) # Read GUI image (PNG) gui_image_png_base64: str = aim_utils.read_image(gui_image_filepath) # Execute metric result: Optional[List[Any]] = Metric4.execute_metric(gui_image_png_base64) # Test result if result is not None: assert result[0] == expected_result[0]