Skip to content

Commit

Permalink
Merge branch 'ft-1261-business-hours-simplified-interface' into 'inte…
Browse files Browse the repository at this point in the history
…gration'

FT 1261 (requires !499 to be merged) updates simplified interface for business hours

See merge request pm4py/pm4py-core!501
  • Loading branch information
fit-sebastiaan-van-zelst committed Oct 15, 2021
2 parents 841e3e5 + 64b67ee commit 56fca73
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
14 changes: 12 additions & 2 deletions pm4py/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ def discover_directly_follows_graph(log: Union[EventLog, pd.DataFrame]) -> Tuple
return discover_dfg(log)


def discover_performance_dfg(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict, dict, dict]:
def discover_performance_dfg(log: Union[EventLog, pd.DataFrame], business_hours: bool = False, worktiming: List[int] = [7, 17], weekends: List[int] = [6, 7]) -> Tuple[dict, dict, dict]:
"""
Discovers a performance directly-follows graph from an event log
Parameters
---------------
log
Event log
business_hours
Enables/disables the computation based on the business hours (default: False)
worktiming
(If the business hours are enabled) The hour range in which the resources of the log are working (default: 7 to 17)
weekends
(If the business hours are enabled) The weekends days (default: Saturday (6), Sunday (7))
Returns
---------------
Expand All @@ -91,7 +97,8 @@ def discover_performance_dfg(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict,
activity_key = properties[constants.PARAMETER_CONSTANT_ACTIVITY_KEY] if constants.PARAMETER_CONSTANT_ACTIVITY_KEY in properties else xes_constants.DEFAULT_NAME_KEY
timestamp_key = properties[constants.PARAMETER_CONSTANT_TIMESTAMP_KEY] if constants.PARAMETER_CONSTANT_TIMESTAMP_KEY in properties else xes_constants.DEFAULT_TIMESTAMP_KEY
case_id_key = properties[constants.PARAMETER_CONSTANT_CASEID_KEY] if constants.PARAMETER_CONSTANT_CASEID_KEY in properties else constants.CASE_CONCEPT_NAME
dfg = get_dfg_graph(log, activity_key=activity_key, timestamp_key=timestamp_key, case_id_glue=case_id_key, measure="performance", perf_aggregation_key="all")
dfg = get_dfg_graph(log, activity_key=activity_key, timestamp_key=timestamp_key, case_id_glue=case_id_key, measure="performance", perf_aggregation_key="all",
business_hours=business_hours, worktiming=worktiming, weekends=weekends)
from pm4py.statistics.start_activities.pandas import get as start_activities_module
from pm4py.statistics.end_activities.pandas import get as end_activities_module
start_activities = start_activities_module.get_start_activities(log, parameters=properties)
Expand All @@ -100,6 +107,9 @@ def discover_performance_dfg(log: Union[EventLog, pd.DataFrame]) -> Tuple[dict,
from pm4py.algo.discovery.dfg.variants import performance as dfg_discovery
properties = get_properties(log)
properties[dfg_discovery.Parameters.AGGREGATION_MEASURE] = "all"
properties[dfg_discovery.Parameters.BUSINESS_HOURS] = business_hours
properties[dfg_discovery.Parameters.WORKTIMING] = worktiming
properties[dfg_discovery.Parameters.WEEKENDS] = weekends
dfg = dfg_discovery.apply(log, parameters=properties)
from pm4py.statistics.start_activities.log import get as start_activities_module
from pm4py.statistics.end_activities.log import get as end_activities_module
Expand Down
32 changes: 26 additions & 6 deletions pm4py/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,32 +387,42 @@ def get_cycle_time(log: Union[EventLog, pd.DataFrame]) -> float:
return cycle_time.apply(log, parameters=get_properties(log))


def get_all_case_durations(log: Union[EventLog, pd.DataFrame]) -> List[float]:
def get_all_case_durations(log: Union[EventLog, pd.DataFrame], business_hours: bool = False, worktiming: List[int] = [7, 17], weekends: List[int] = [6, 7]) -> List[float]:
"""
Gets the durations of the cases in the event log
Parameters
---------------
log
Event log
business_hours
Enables/disables the computation based on the business hours (default: False)
worktiming
(If the business hours are enabled) The hour range in which the resources of the log are working (default: 7 to 17)
weekends
(If the business hours are enabled) The weekends days (default: Saturday (6), Sunday (7))
Returns
---------------
durations
Case durations (as list)
"""
general_checks_classical_event_log(log)
properties = copy(get_properties(log))
properties["business_hours"] = business_hours
properties["worktiming"] = worktiming
properties["weekends"] = weekends
if check_is_pandas_dataframe(log):
check_pandas_dataframe_columns(log)
from pm4py.statistics.traces.generic.pandas import case_statistics
cd = case_statistics.get_cases_description(log, parameters=get_properties(log))
cd = case_statistics.get_cases_description(log, parameters=properties)
return sorted([x["caseDuration"] for x in cd.values()])
else:
from pm4py.statistics.traces.generic.log import case_statistics
return case_statistics.get_all_case_durations(log, parameters=get_properties(log))
return case_statistics.get_all_case_durations(log, parameters=properties)


def get_case_duration(log: Union[EventLog, pd.DataFrame], case_id: str) -> float:
def get_case_duration(log: Union[EventLog, pd.DataFrame], case_id: str, business_hours: bool = False, worktiming: List[int] = [7, 17], weekends: List[int] = [6, 7]) -> float:
"""
Gets the duration of a specific case
Expand All @@ -422,19 +432,29 @@ def get_case_duration(log: Union[EventLog, pd.DataFrame], case_id: str) -> float
Event log
case_id
Case identifier
business_hours
Enables/disables the computation based on the business hours (default: False)
worktiming
(If the business hours are enabled) The hour range in which the resources of the log are working (default: 7 to 17)
weekends
(If the business hours are enabled) The weekends days (default: Saturday (6), Sunday (7))
Returns
------------------
duration
Duration of the given case
"""
general_checks_classical_event_log(log)
properties = copy(get_properties(log))
properties["business_hours"] = business_hours
properties["worktiming"] = worktiming
properties["weekends"] = weekends
if check_is_pandas_dataframe(log):
check_pandas_dataframe_columns(log)
from pm4py.statistics.traces.generic.pandas import case_statistics
cd = case_statistics.get_cases_description(log)
cd = case_statistics.get_cases_description(log, parameters=properties)
return cd[case_id]["caseDuration"]
else:
from pm4py.statistics.traces.generic.log import case_statistics
cd = case_statistics.get_cases_description(log)
cd = case_statistics.get_cases_description(log, parameters=properties)
return cd[case_id]["caseDuration"]

0 comments on commit 56fca73

Please sign in to comment.