Skip to content

Commit

Permalink
Merge branch 'PM4PY-1552' into 'integration'
Browse files Browse the repository at this point in the history
PMPY-1552 Rebase functionality (wrapper)

See merge request process-mining/pm4py/pm4py-core!593
  • Loading branch information
fit-sebastiaan-van-zelst committed Jan 25, 2022
2 parents f9ad1a4 + a1dd53e commit 7359807
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pm4py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
get_case_arrival_average, get_rework_cases_per_activity, get_case_overlap, get_cycle_time, \
get_all_case_durations, get_case_duration, get_activity_position_summary
from pm4py.utils import format_dataframe, parse_process_tree, serialize, deserialize, set_classifier, parse_event_log_string, project_on_event_attribute, \
sample_cases, sample_events
sample_cases, sample_events, rebase
from pm4py.vis import view_petri_net, save_vis_petri_net, view_dfg, save_vis_dfg, view_process_tree, \
save_vis_process_tree, \
view_ocdfg, save_vis_ocdfg, view_heuristics_net, save_vis_heuristics_net, view_bpmn, save_vis_bpmn, view_sna, save_vis_sna,\
Expand Down
42 changes: 42 additions & 0 deletions pm4py/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,48 @@ def format_dataframe(df: pd.DataFrame, case_id: str = constants.CASE_CONCEPT_NAM
return df


def rebase(log_obj: Union[EventLog, EventStream, pd.DataFrame], case_id: str = constants.CASE_CONCEPT_NAME,
activity_key: str = xes_constants.DEFAULT_NAME_KEY,
timestamp_key: str = xes_constants.DEFAULT_TIMESTAMP_KEY,
start_timestamp_key: str = xes_constants.DEFAULT_START_TIMESTAMP_KEY):
"""
Re-base the log object, changing the case ID, activity and timestamp attributes.
Parameters
-----------------
log_obj
Log object
case_id
Case identifier
activity_key
Activity
timestamp_key
Timestamp
start_timestamp_key
Start timestamp
Returns
-----------------
rebased_log_obj
Rebased log object
"""
import pm4py

if isinstance(log_obj, pd.DataFrame):
return format_dataframe(log_obj, case_id=case_id, activity_key=activity_key, timestamp_key=timestamp_key,
start_timestamp_key=start_timestamp_key)
elif isinstance(log_obj, EventLog):
log_obj = pm4py.convert_to_dataframe(log_obj)
log_obj = format_dataframe(log_obj, case_id=case_id, activity_key=activity_key, timestamp_key=timestamp_key,
start_timestamp_key=start_timestamp_key)
return pm4py.convert_to_event_log(log_obj)
elif isinstance(log_obj, EventStream):
log_obj = pm4py.convert_to_dataframe(log_obj)
log_obj = format_dataframe(log_obj, case_id=case_id, activity_key=activity_key, timestamp_key=timestamp_key,
start_timestamp_key=start_timestamp_key)
return pm4py.convert_to_event_stream(log_obj)


def parse_process_tree(tree_string: str) -> ProcessTree:
"""
Parse a process tree from a string
Expand Down

0 comments on commit 7359807

Please sign in to comment.