Skip to content

Commit

Permalink
Merge branch 'ft-1380-adding-timestamp-artificial-start-end' into 'in…
Browse files Browse the repository at this point in the history
…tegration'

FT 1380 Adding timestamp for artificial start/end when possible

See merge request pm4py/pm4py-core!527
  • Loading branch information
fit-sebastiaan-van-zelst committed Nov 12, 2021
2 parents 783af17 + 5f4b131 commit 43a076c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pm4py/objects/log/util/artificial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
from pm4py.util import constants
from pm4py.util import exec_utils
from pm4py.util import xes_constants
import datetime


class Parameters(Enum):
ACTIVITY_KEY = constants.PARAMETER_CONSTANT_ACTIVITY_KEY
TIMESTAMP_KEY = constants.PARAMETER_CONSTANT_TIMESTAMP_KEY
PARAM_ARTIFICIAL_START_ACTIVITY = constants.PARAM_ARTIFICIAL_START_ACTIVITY
PARAM_ARTIFICIAL_END_ACTIVITY = constants.PARAM_ARTIFICIAL_END_ACTIVITY

Expand All @@ -25,6 +27,7 @@ def insert_artificial_start_end(log: EventLog, parameters: Optional[Dict[Any, An
parameters
Parameters of the algorithm, including:
- Parameters.ACTIVITY_KEY: the activity
- Parameters.TIMESTAMP_KEY: the timestamp
Returns
------------------
Expand All @@ -35,13 +38,22 @@ def insert_artificial_start_end(log: EventLog, parameters: Optional[Dict[Any, An
parameters = {}

activity_key = exec_utils.get_param_value(Parameters.ACTIVITY_KEY, parameters, xes_constants.DEFAULT_NAME_KEY)
timestamp_key = exec_utils.get_param_value(Parameters.TIMESTAMP_KEY, parameters, xes_constants.DEFAULT_TIMESTAMP_KEY)

artificial_start_activity = exec_utils.get_param_value(Parameters.PARAM_ARTIFICIAL_START_ACTIVITY, parameters,
constants.DEFAULT_ARTIFICIAL_START_ACTIVITY)
artificial_end_activity = exec_utils.get_param_value(Parameters.PARAM_ARTIFICIAL_END_ACTIVITY, parameters,
constants.DEFAULT_ARTIFICIAL_END_ACTIVITY)

for trace in log:
trace.insert(0, Event({activity_key: artificial_start_activity}))
trace.append(Event({activity_key: artificial_end_activity}))
start_event = Event({activity_key: artificial_start_activity})
end_event = Event({activity_key: artificial_end_activity})
if trace:
if timestamp_key in trace[0]:
start_event[timestamp_key] = trace[0][timestamp_key] - datetime.timedelta(seconds=1)
if timestamp_key in trace[-1]:
end_event[timestamp_key] = trace[-1][timestamp_key] + datetime.timedelta(seconds=1)
trace.insert(0, start_event)
trace.append(end_event)

return log

0 comments on commit 43a076c

Please sign in to comment.