|
| 1 | +import os |
| 2 | + |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | +import pm4py |
| 6 | +from pm4py.statistics.attributes.pandas import get as attr_get |
| 7 | +from pm4py.visualization.graphs import visualizer |
| 8 | + |
| 9 | + |
| 10 | +def execute_script(): |
| 11 | + df = pd.read_csv(os.path.join("..", "tests", "input_data", "receipt.csv")) |
| 12 | + df = pm4py.format_dataframe(df) |
| 13 | + # plots the distribution of the events over the days of a month |
| 14 | + x0, y0 = attr_get.get_events_distribution(df, distr_type="days_month") |
| 15 | + gviz = visualizer.apply(x0, y0, variant=visualizer.Variants.BARPLOT, |
| 16 | + parameters={"format": "svg", "title": "Distribution of the Events over the Days of a Month", |
| 17 | + "x_axis": "Day of month", "y_axis": "Number of Events"}) |
| 18 | + visualizer.view(gviz) |
| 19 | + # plots the distribution of the events over the months |
| 20 | + x1, y1 = attr_get.get_events_distribution(df, distr_type="months") |
| 21 | + gviz = visualizer.apply(x1, y1, variant=visualizer.Variants.BARPLOT, |
| 22 | + parameters={"format": "svg", "title": "Distribution of the Events over the Months", |
| 23 | + "x_axis": "Month", "y_axis": "Number of Events"}) |
| 24 | + visualizer.view(gviz) |
| 25 | + # plots the distribution of the events over the years |
| 26 | + x2, y2 = attr_get.get_events_distribution(df, distr_type="years") |
| 27 | + gviz = visualizer.apply(x2, y2, variant=visualizer.Variants.BARPLOT, |
| 28 | + parameters={"format": "svg", "title": "Distribution of the Events over the Years", |
| 29 | + "x_axis": "Year", "y_axis": "Number of Events"}) |
| 30 | + visualizer.view(gviz) |
| 31 | + # plots the distribution of the events over the hours (of the day) |
| 32 | + x3, y3 = attr_get.get_events_distribution(df, distr_type="hours") |
| 33 | + gviz = visualizer.apply(x3, y3, variant=visualizer.Variants.BARPLOT, |
| 34 | + parameters={"format": "svg", "title": "Distribution of the Events over the Hours", |
| 35 | + "x_axis": "Hour (of day)", "y_axis": "Number of Events"}) |
| 36 | + visualizer.view(gviz) |
| 37 | + # plots the distribution of the events over the days of the week |
| 38 | + x4, y4 = attr_get.get_events_distribution(df, distr_type="days_week") |
| 39 | + gviz = visualizer.apply(x4, y4, variant=visualizer.Variants.BARPLOT, |
| 40 | + parameters={"format": "svg", "title": "Distribution of the Events over the Days of a Week", |
| 41 | + "x_axis": "Day of the Week", "y_axis": "Number of Events"}) |
| 42 | + visualizer.view(gviz) |
| 43 | + |
| 44 | + |
| 45 | +if __name__ == "__main__": |
| 46 | + execute_script() |
0 commit comments