Skip to content

Commit

Permalink
Merge branch 'PMPY-1718' into 'integration'
Browse files Browse the repository at this point in the history
PMPY-1718 Avoiding layouting in neato to increase significantly execution performance of dotted chart and performance spectrum

Closes PMPY-1718

See merge request process-mining/pm4py/pm4py-core!677
  • Loading branch information
fit-alessandro-berti committed May 30, 2022
2 parents cab38bd + 505c1cc commit ab196c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 10 additions & 5 deletions pm4py/visualization/dotted_chart/variants/classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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("}")

Expand All @@ -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
12 changes: 7 additions & 5 deletions pm4py/visualization/performance_spectrum/variants/neato.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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]
Expand All @@ -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):
Expand All @@ -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)
Expand All @@ -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

0 comments on commit ab196c5

Please sign in to comment.