def save_vis_events_per_time_graph(log: Union[EventLog, pd.DataFrame], file_path: str): """ Saves the events per time graph in the specified path Parameters ---------------- log Log object file_path Destination path """ if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception( "the method can be applied only to a traditional event log!") if check_is_pandas_dataframe(log): check_pandas_dataframe_columns(log) from pm4py.statistics.attributes.pandas import get as attributes_get graph = attributes_get.get_kde_date_attribute( log, parameters=get_properties(log)) else: from pm4py.statistics.attributes.log import get as attributes_get graph = attributes_get.get_kde_date_attribute( log, parameters=get_properties(log)) format = os.path.splitext(file_path)[1][1:] from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply( graph[0], graph[1], variant=graphs_visualizer.Variants.DATES, parameters={"format": format}) graphs_visualizer.save(graph_vis, file_path)
def execute_script(): log = pm4py.read_xes("../tests/input_data/running-example.xes") dfg, sa, ea = pm4py.discover_dfg(log) tree = pm4py.discover_process_tree_inductive(log) heu_net = pm4py.discover_heuristics_net(log) net, im, fm = pm4py.discover_petri_net_alpha(log) bpmn = pm4py.convert_to_bpmn(tree) ts = ts_discovery.apply(log) x_cases, y_cases = case_statistics.get_kde_caseduration(log) gviz1 = dfg_visualizer.apply(dfg) gviz2 = tree_visualizer.apply(tree) gviz3 = hn_visualizer.apply(heu_net) gviz4 = pn_visualizer.apply(net, im, fm) gviz5 = bpmn_visualizer.apply(bpmn) gviz6 = ts_visualizer.apply(ts) gviz7 = graphs_visualizer.apply(x_cases, y_cases, variant=graphs_visualizer.Variants.CASES, parameters={graphs_visualizer.Variants.CASES.value.Parameters.FORMAT: "svg"}) print("1", len(dfg_visualizer.serialize_dot(gviz1))) print("1", len(dfg_visualizer.serialize(gviz1))) print("2", len(tree_visualizer.serialize_dot(gviz2))) print("2", len(tree_visualizer.serialize(gviz2))) print("3", len(hn_visualizer.serialize(gviz3))) print("4", len(pn_visualizer.serialize_dot(gviz4))) print("4", len(pn_visualizer.serialize(gviz4))) print("5", len(bpmn_visualizer.serialize_dot(gviz5))) print("5", len(bpmn_visualizer.serialize(gviz5))) print("6", len(ts_visualizer.serialize_dot(gviz6))) print("6", len(ts_visualizer.serialize(gviz6))) print("7", len(graphs_visualizer.serialize(gviz7)))
def view_events_per_time_graph(log: Union[EventLog, pd.DataFrame], format: str = "png"): """ Visualizes the events per time graph Parameters ----------------- log Log object format Format of the visualization (png, svg, ...) """ if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception( "the method can be applied only to a traditional event log!") if check_is_pandas_dataframe(log): check_pandas_dataframe_columns(log) from pm4py.statistics.attributes.pandas import get as attributes_get graph = attributes_get.get_kde_date_attribute( log, parameters=get_properties(log)) else: from pm4py.statistics.attributes.log import get as attributes_get graph = attributes_get.get_kde_date_attribute( log, parameters=get_properties(log)) from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply( graph[0], graph[1], variant=graphs_visualizer.Variants.DATES, parameters={"format": format}) graphs_visualizer.view(graph_vis)
def execute_script(): log = pm4py.read_xes( os.path.join("..", "tests", "input_data", "receipt.xes")) # calculates the graph: # values of y more distant from 0 signal executions that differ from the mainstream behavior x, y = locally_linear_embedding.apply(log) gviz = visualizer.apply(x, y, variant=visualizer.Variants.DATES, parameters={ "title": "Locally Linear Embedding", "format": "svg", "y_axis": "Intensity" }) visualizer.view(gviz)
def view_events_per_time_graph(log: Union[EventLog, pd.DataFrame], format: str = "png"): """ Visualizes the events per time graph Parameters ----------------- log Log object format Format of the visualization (png, svg, ...) """ if check_is_dataframe(log): check_dataframe_columns(log) from pm4py.statistics.attributes.pandas import get as attributes_get graph = attributes_get.get_kde_date_attribute(log) else: from pm4py.statistics.attributes.log import get as attributes_get graph = attributes_get.get_kde_date_attribute(log) from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply(graph[0], graph[1], variant=graphs_visualizer.Variants.DATES, parameters={"format": format}) graphs_visualizer.view(graph_vis)
def view_case_duration_graph(log: Union[EventLog, pd.DataFrame], format: str = "png"): """ Visualizes the case duration graph Parameters ----------------- log Log object format Format of the visualization (png, svg, ...) """ if check_is_dataframe(log): check_dataframe_columns(log) from pm4py.statistics.traces.pandas import case_statistics graph = case_statistics.get_kde_caseduration(log) else: from pm4py.statistics.traces.log import case_statistics graph = case_statistics.get_kde_caseduration(log) from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply(graph[0], graph[1], variant=graphs_visualizer.Variants.CASES, parameters={"format": format}) graphs_visualizer.view(graph_vis)
def save_vis_events_distribution_graph(log: Union[EventLog, pd.DataFrame], file_path: str, distr_type: str = "days_week"): """ Saves the distribution of the events in a picture file Parameters ---------------- log Event log file_path Destination path (including the extension) distr_type Type of distribution (default: days_week): - days_month => Gets the distribution of the events among the days of a month (from 1 to 31) - months => Gets the distribution of the events among the months (from 1 to 12) - years => Gets the distribution of the events among the years of the event log - hours => Gets the distribution of the events among the hours of a day (from 0 to 23) - days_week => Gets the distribution of the events among the days of a week (from Monday to Sunday) """ if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception( "the method can be applied only to a traditional event log!") format = os.path.splitext(file_path)[1][1:] title, x_axis, y_axis, x, y = __builds_events_distribution_graph( log, distr_type) parameters = copy(get_properties(log)) parameters["title"] = title parameters["x_axis"] = x_axis parameters["y_axis"] = y_axis parameters["format"] = format from pm4py.visualization.graphs import visualizer as graphs_visualizer gviz = graphs_visualizer.apply(x, y, variant=graphs_visualizer.Variants.BARPLOT, parameters=parameters) graphs_visualizer.save(gviz, file_path)
def view_events_distribution_graph(log: Union[EventLog, pd.DataFrame], distr_type: str = "days_week", format="png"): """ Shows the distribution of the events in the specified dimension Parameters ---------------- log Event log distr_type Type of distribution (default: days_week): - days_month => Gets the distribution of the events among the days of a month (from 1 to 31) - months => Gets the distribution of the events among the months (from 1 to 12) - years => Gets the distribution of the events among the years of the event log - hours => Gets the distribution of the events among the hours of a day (from 0 to 23) - days_week => Gets the distribution of the events among the days of a week (from Monday to Sunday) - weeks => Gets the distribution of the events among the weeks of a year (from 0 to 52) format Format of the visualization (default: png) """ if type(log) not in [pd.DataFrame, EventLog, EventStream]: raise Exception( "the method can be applied only to a traditional event log!") title, x_axis, y_axis, x, y = __builds_events_distribution_graph( log, distr_type) parameters = copy(get_properties(log)) parameters["title"] = title parameters["x_axis"] = x_axis parameters["y_axis"] = y_axis parameters["format"] = format from pm4py.visualization.graphs import visualizer as graphs_visualizer gviz = graphs_visualizer.apply(x, y, variant=graphs_visualizer.Variants.BARPLOT, parameters=parameters) graphs_visualizer.view(gviz)
def save_vis_events_per_time_graph(log: Union[EventLog, pd.DataFrame], file_path: str): """ Saves the events per time graph in the specified path Parameters ---------------- log Log object file_path Destination path """ if check_is_dataframe(log): check_dataframe_columns(log) from pm4py.statistics.attributes.pandas import get as attributes_get graph = attributes_get.get_kde_date_attribute(log) else: from pm4py.statistics.attributes.log import get as attributes_get graph = attributes_get.get_kde_date_attribute(log) format = file_path[file_path.index(".") + 1:].lower() from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply(graph[0], graph[1], variant=graphs_visualizer.Variants.DATES, parameters={"format": format}) graphs_visualizer.save(graph_vis, file_path)
def save_vis_case_duration_graph(log: Union[EventLog, pd.DataFrame], file_path: str): """ Saves the case duration graph in the specified path Parameters ---------------- log Log object file_path Destination path """ if check_is_dataframe(log): check_dataframe_columns(log) from pm4py.statistics.traces.pandas import case_statistics graph = case_statistics.get_kde_caseduration(log) else: from pm4py.statistics.traces.log import case_statistics graph = case_statistics.get_kde_caseduration(log) format = file_path[file_path.index(".") + 1:].lower() from pm4py.visualization.graphs import visualizer as graphs_visualizer graph_vis = graphs_visualizer.apply(graph[0], graph[1], variant=graphs_visualizer.Variants.CASES, parameters={"format": format}) graphs_visualizer.save(graph_vis, file_path)
if True: # ignore this part in true PowerBI executions import os import pandas as pd from pm4py.objects.log.util import dataframe_utils log_path = os.path.join("..", "..", "tests", "input_data", "running-example.csv") dataset = pd.read_csv(log_path) dataset = dataframe_utils.convert_timestamp_columns_in_df(dataset) import pandas as pd # this part is required because the dataframe provided by PowerBI has strings dataset["time:timestamp"] = pd.to_datetime(dataset["time:timestamp"]) dataset = dataset.sort_values("time:timestamp") from pm4py.statistics.traces.generic.pandas import case_statistics from pm4py.visualization.graphs import visualizer as graphs_visualizer x_cases, y_cases = case_statistics.get_kde_caseduration(dataset) graph_cases = graphs_visualizer.apply(x_cases, y_cases, variant=graphs_visualizer.Variants.CASES, parameters={graphs_visualizer.Variants.CASES.value.Parameters.FORMAT: "png"}) graphs_visualizer.matplotlib_view(graph_cases)
if True: # ignore this part in true PowerBI executions from pm4py.objects.log.adapters.pandas import csv_import_adapter dataset = csv_import_adapter.import_dataframe_from_path( "C:/running-example.csv") import pandas as pd # this part is required because the dataframe provided by PowerBI has strings dataset["time:timestamp"] = pd.to_datetime(dataset["time:timestamp"]) from pm4py.statistics.attributes.pandas import get as attributes_filter from pm4py.visualization.graphs import visualizer as graphs_visualizer # visualize events over time graph x_dates, y_dates = attributes_filter.get_kde_date_attribute(dataset) graph_dates = graphs_visualizer.apply( x_dates, y_dates, variant=graphs_visualizer.Variants.DATES, parameters={ graphs_visualizer.Variants.DATES.value.Parameters.FORMAT: "png" }) graphs_visualizer.matplotlib_view(graph_dates)