Skip to content

Commit

Permalink
Merge branch 'PM4PY-1563' into 'integration'
Browse files Browse the repository at this point in the history
PMPY-1563 Added "week of the year" option in get_events_distribution method

See merge request process-mining/pm4py/pm4py-core!598
  • Loading branch information
fit-sebastiaan-van-zelst committed Jan 25, 2022
2 parents 2200a0f + a6bcae9 commit c7c7ed5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pm4py/statistics/attributes/log/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def get_events_distribution(log: EventLog, distr_type: str = "days_month", param
elif distr_type == "days_week":
values = Counter(x.weekday() for x in timestamp_values)
all_values = Counter({i: 0 for i in range(0, 7)})
elif distr_type == "weeks":
values = Counter(x.isocalendar().week for x in timestamp_values)
all_values = Counter({i: 0 for i in range(0, 53)})

# make sure that all the possible values appear
for v in all_values:
Expand Down
5 changes: 5 additions & 0 deletions pm4py/statistics/attributes/pandas/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def get_events_distribution(df: pd.DataFrame, distr_type: str = "days_month", pa
- 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 => Distribution of the events among the weeks of a year (from 0 to 52)
parameters
Parameters of the algorithm, including:
- Parameters.TIMESTAMP_KEY
Expand Down Expand Up @@ -92,6 +93,10 @@ def get_events_distribution(df: pd.DataFrame, distr_type: str = "days_month", pa
serie = df[timestamp_key].dt.dayofweek
values = Counter(serie.value_counts().to_dict())
all_values = Counter({i: 0 for i in range(0, 7)})
elif distr_type == "weeks":
serie = df[timestamp_key].dt.isocalendar().week
values = Counter(serie.value_counts().to_dict())
all_values = Counter({i: 0 for i in range(0, 53)})

# make sure that all the possible values appear
for v in all_values:
Expand Down
5 changes: 5 additions & 0 deletions pm4py/vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ def __builds_events_distribution_graph(log: Union[EventLog, pd.DataFrame], distr
title = "Distribution of the Events over the Days of a Week";
x_axis = "Day of the Week";
y_axis = "Number of Events"
elif distr_type == "weeks":
title = "Distribution of the Events over the Weeks of a Year";
x_axis = "Week of the Year";
y_axis = "Number of Events"
else:
raise Exception("unsupported distribution specified.")

Expand Down Expand Up @@ -585,6 +589,7 @@ def view_events_distribution_graph(log: Union[EventLog, pd.DataFrame], distr_typ
- 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)
"""
Expand Down

0 comments on commit c7c7ed5

Please sign in to comment.