From 505c1cc2bf4e4c52bf02ad274de836c7e3824ee1 Mon Sep 17 00:00:00 2001 From: Alessandro Berti Date: Mon, 30 May 2022 08:06:50 +0200 Subject: [PATCH] feat(pm4py): Avoiding layouting in neato to increase significantly execution performance of dotted chart and performance spectrum --- .../dotted_chart/variants/classic.py | 15 ++++++++++----- .../performance_spectrum/variants/neato.py | 12 +++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pm4py/visualization/dotted_chart/variants/classic.py b/pm4py/visualization/dotted_chart/variants/classic.py index d7b61a5c8..7b1063437 100644 --- a/pm4py/visualization/dotted_chart/variants/classic.py +++ b/pm4py/visualization/dotted_chart/variants/classic.py @@ -12,6 +12,7 @@ class Parameters(Enum): FORMAT = "format" DOT_SIZE = "dot_size" + LAYOUT_EXT_MULTIPLIER = "layout_ext_multiplier" def __build_unique_values(points_list: List[Any]) -> List[Any]: @@ -128,6 +129,7 @@ def apply(points_list: List[Any], attributes: List[str], parameters: Optional[Di format = exec_utils.get_param_value(Parameters.FORMAT, parameters, "png") dot_size = exec_utils.get_param_value(Parameters.DOT_SIZE, parameters, 0.07) + layout_ext_multiplier = exec_utils.get_param_value(Parameters.LAYOUT_EXT_MULTIPLIER, parameters, 50) unique_values = __build_unique_values(points_list) corr_dict, attr_type = __build_corr_dict(unique_values) @@ -140,6 +142,9 @@ def apply(points_list: List[Any], attributes: List[str], parameters: Optional[Di if attr_type[1] == "str": y_length = max(y_length, len(unique_values[1]) * 0.75) + x_length *= layout_ext_multiplier + y_length *= layout_ext_multiplier + output_file_gv = tempfile.NamedTemporaryFile(suffix=".gv") output_file_gv.close() output_file_img = tempfile.NamedTemporaryFile(suffix="." + format) @@ -181,19 +186,19 @@ def apply(points_list: List[Any], attributes: List[str], parameters: Optional[Di if color_dict is not None: lines.append( - "Legend [label=\"legend (attribute: %s)\", shape=none, width=\"0px\", height=\"0px\", pos=\"0,-1!\"]" % ( - attributes[2])) + "Legend [label=\"legend (attribute: %s)\", shape=none, width=\"0px\", height=\"0px\", pos=\"0,-%d!\"]" % ( + attributes[2], 1*layout_ext_multiplier)) row = -1 for k, v in color_dict.items(): row -= 1 n_id = "n" + str(uuid.uuid4()).replace("-", "") + "e" lines.append( "%s [label=\"\", shape=circle, width=\"%.10fpx\", height=\"%.10fpx\", fontsize=\"6pt\", style=\"filled\", fillcolor=\"%s\", pos=\"0,%d!\"]" % ( - n_id, dot_size, dot_size, v, row)) + n_id, dot_size, dot_size, v, layout_ext_multiplier*row)) n_id = "n" + str(uuid.uuid4()).replace("-", "") + "e" lines.append( "%s [label=\"%s\", shape=none, width=\"0px\", height=\"0px\", pos=\"1.5,%d!\", fontsize=\"9pt\"];" % ( - n_id, str(k), row)) + n_id, str(k), layout_ext_multiplier*row)) lines.append("}") @@ -203,6 +208,6 @@ def apply(points_list: List[Any], attributes: List[str], parameters: Optional[Di F.write(lines) F.close() - os.system("neato -T" + format + " " + output_file_gv.name + " > " + output_file_img.name) + os.system("neato -n1 -T" + format + " " + output_file_gv.name + " > " + output_file_img.name) return output_file_img.name diff --git a/pm4py/visualization/performance_spectrum/variants/neato.py b/pm4py/visualization/performance_spectrum/variants/neato.py index d724c30bd..fd326f1ef 100644 --- a/pm4py/visualization/performance_spectrum/variants/neato.py +++ b/pm4py/visualization/performance_spectrum/variants/neato.py @@ -20,6 +20,7 @@ class Parameters(Enum): OVERALL_LENGTH_X = "overall_length_x" N_DIV_DATES = "n_div_dates" PERC_PATHS = "perc_paths" + LAYOUT_EXT_MULTIPLIER = "layout_ext_multiplier" def give_color_to_line(dir: float) -> str: @@ -81,6 +82,7 @@ def apply(perf_spectrum: Dict[str, Any], parameters: Optional[Dict[Union[str, Pa overall_length = exec_utils.get_param_value(Parameters.OVERALL_LENGTH_X, parameters, 10.0) n_div = exec_utils.get_param_value(Parameters.N_DIV_DATES, parameters, 2) perc_paths = exec_utils.get_param_value(Parameters.PERC_PATHS, parameters, 1.0) + layout_ext_multiplier = exec_utils.get_param_value(Parameters.LAYOUT_EXT_MULTIPLIER, parameters, 100) output_file_gv = tempfile.NamedTemporaryFile(suffix=".gv") output_file_gv.close() @@ -107,7 +109,7 @@ def apply(perf_spectrum: Dict[str, Any], parameters: Optional[Dict[Union[str, Pa first_coord = (p - min_x) / (max_x - min_x) * overall_length second_coord = act_divider * (len(perf_spectrum["list_activities"]) - i - 1) lines.append( - "%s [label=\"\", pos=\"%.10f,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % (p_id, first_coord, second_coord)) + "%s [label=\"\", pos=\"%.10f,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % (p_id, first_coord*layout_ext_multiplier, second_coord*layout_ext_multiplier)) this_pts.append(p_id) for i in range(len(this_pts) - 1): diff = polyline[i + 1] - polyline[i] @@ -118,9 +120,9 @@ def apply(perf_spectrum: Dict[str, Any], parameters: Optional[Dict[Union[str, Pa second_coord = act_divider * (len(perf_spectrum["list_activities"]) - i - 1) a_id = "n" + str(uuid.uuid4()).replace("-", "") + "e" lines.append("%s [label=\"%s\", pos=\"%.10f,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % ( - a_id, act, overall_length, second_coord)) + a_id, act, overall_length*layout_ext_multiplier, second_coord*layout_ext_multiplier)) s_id = "n" + str(uuid.uuid4()).replace("-", "") + "e" - lines.append("%s [label=\"\", pos=\"0,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % (s_id, second_coord)) + lines.append("%s [label=\"\", pos=\"0,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % (s_id, second_coord*layout_ext_multiplier)) lines.append("%s -- %s [ color=\"black\" ];" % (s_id, a_id)) if i == len(perf_spectrum["list_activities"]) - 1: for j in range(n_div + 1): @@ -129,7 +131,7 @@ def apply(perf_spectrum: Dict[str, Any], parameters: Optional[Dict[Union[str, Pa dt = datetime.fromtimestamp(tst) n_id = "n" + str(uuid.uuid4()).replace("-", "") + "e" lines.append("%s [label=\"%s\", pos=\"%.10f,%.10f!\", shape=none, width=\"0px\", height=\"0px\"];" % ( - n_id, str(dt), pos, second_coord - date_divider)) + n_id, str(dt), pos*layout_ext_multiplier, (second_coord - date_divider)*layout_ext_multiplier)) lines.append("}") lines = "\n".join(lines) @@ -138,6 +140,6 @@ def apply(perf_spectrum: Dict[str, Any], parameters: Optional[Dict[Union[str, Pa F.write(lines) F.close() - os.system("neato -T" + format + " " + output_file_gv.name + " > " + output_file_img.name) + os.system("neato -n1 -T" + format + " " + output_file_gv.name + " > " + output_file_img.name) return output_file_img.name