Business Hours

Business Hours module

Given an interval event log (an EventLog object where each event is characterised by two timestamps, a start timestamp usually contained in the start_timestamp attribute and a completion timestamp usually contained in the time:timestamp attribute), the “duration” of the event is the difference between the completion timestamp and the start timestamp. This may be inficiated by nights (where an activity is not actively worked), weekends (where the workers may not be at the workplace) and other kind of pauses. In PM4Py, a way to consider only the time in which the activity could actually be worked (so, excluding time outside of the working hours and weekends) is provided.

Given a start and end timestamp (expressed as UNIX timestamps), the business hours calculation method could be called as follows:

from pm4py.util.business_hours import BusinessHours
from datetime import datetime

st = datetime.fromtimestamp(100000000)
et = datetime.fromtimestamp(200000000)
bh_object = BusinessHours(st, et)
worked_time = bh_object.getseconds()

Obtaining 29736000 for the specific example.

To provide specific shifts and weekends (for example, always short weeks with 4 working days 🙂 and work days from 10 to 16) the following code could be used:

bh_object = BusinessHours(st, et, worktiming=[10, 16], weekends=[5, 6, 7])
worked_time = bh_object.getseconds()

The business hours duration method is called authomatically in the following parts of PM4Py:

  • Conversion of lifecycle log to interval log (in the case the business hours are explicitly required) (optional provision of worktiming and weekends parameters if they differ from the standard values)
  • Calculation of process cycle and lead time (optional provision of worktiming and weekends parameters if they differ from the standard values)

Calculation of the time passed from the previous activity

This calculation is simply based on the direct succession of events in a case, and does not take into account the concurrency between the activities

An utility has been provided in PM4Py to insert in each event of the log the passed time from the previous event (attribute @@passed_time_from_previous) and the approximated business time from the previous event (attribute @@approx_bh_passed_time_from_previous).

In the following example, we apply the utility

We start importing the receipt.xes log

import os
from pm4py.objects.log.importer.xes import factory as xes_importer
log = xes_importer.apply(os.path.join("tests", "input_data", "receipt.xes"))

Then, the time from the previous event is inserted into the log (inside the attributes that are written above):

from pm4py.objects.log.util import time_from_previous
log = time_from_previous.insert_time_from_previous(log)

Then, the log can be exported:

from pm4py.objects.log.exporter.xes import factory as xes_exporter
xes_exporter.apply(log, "receipt.xes")

If the log is open, you can see that the insertion has been successful.