Example #1
0
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)
Example #2
0
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)
Example #3
0
    def test_dfDateAttribute(self):
        # to avoid static method warnings in tests,
        # that by construction of the unittest package have to be expressed in such way
        self.dummy_variable = "dummy_value"

        df = csv_import_adapter.import_dataframe_from_path(
            os.path.join("input_data", "receipt.csv"))
        x, y = pd_attributes_filter.get_kde_date_attribute(df)
        json = pd_attributes_filter.get_kde_date_attribute_json(df)
        del json
Example #4
0
    def test_dfDateAttribute(self):
        # to avoid static method warnings in tests,
        # that by construction of the unittest package have to be expressed in such way
        self.dummy_variable = "dummy_value"

        df = pd.read_csv(os.path.join("input_data",
                                      "roadtraffic100traces.csv"))
        df = dataframe_utils.convert_timestamp_columns_in_df(df)

        x, y = pd_attributes_filter.get_kde_date_attribute(df)
        json = pd_attributes_filter.get_kde_date_attribute_json(df)
        del json
Example #5
0
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)
Example #6
0
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)
Example #7
0
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)
Example #8
0
 def test_get_attributes(self):
     from pm4py.statistics.attributes.pandas import get
     df = self.get_dataframe()
     get.get_attribute_values(df, "concept:name")
     get.get_kde_date_attribute(df, "time:timestamp")
     get.get_kde_numeric_attribute(df, "amount")
Example #9
0
    if ENABLE_TESTS:
        # TEST 7: discover variants from dataframe
        t0 = time.time()
        pd_case_statistics.get_variants_df(roadtraffic_df)
        t1 = time.time()
        T7[0] = (t1 - t0)
        T7[2] = math.ceil(T7[1] / (T7[0] + 0.00000001) * 1000.0)
        print(
            "TEST 7 - Discover variants from Pandas dataframe - %.5f s (test score: %d)"
            % (T7[0], T7[2]))

    if ENABLE_TESTS:
        # TEST 8: discover timeframe KDE rom dataframe
        t0 = time.time()
        pd_attributes_get.get_kde_date_attribute(roadtraffic_df,
                                                 "time:timestamp")
        t1 = time.time()
        T8[0] = (t1 - t0)
        T8[2] = math.ceil(T8[1] / (T8[0] + 0.00000001) * 1000.0)
        print(
            "TEST 8 - Discover timeframe KDE from dataframe - %.5f s (test score: %d)"
            % (T8[0], T8[2]))

    if ENABLE_TESTS:
        # TEST 9: discover performance spectrum from dataframe
        t0 = time.time()
        pspectrum.apply(roadtraffic_df, ["Create Fine", "Send Fine"])
        t1 = time.time()
        T9[0] = (t1 - t0)
        T9[2] = math.ceil(T9[1] / (T9[0] + 0.00000001) * 1000.0)
        print(