def test_11(self): from pm4py.algo.filtering.pandas.timestamp import timestamp_filter dataframe = self.load_running_example_df() df_timest_intersecting = timestamp_filter.filter_traces_intersecting(dataframe, "2011-03-09 00:00:00", "2012-01-18 23:59:59", parameters={ timestamp_filter.Parameters.CASE_ID_KEY: "case:concept:name", timestamp_filter.Parameters.TIMESTAMP_KEY: "time:timestamp"})
def average_case_duration( log: EventLog, t1: Union[datetime, str], t2: Union[datetime, str], r: str, parameters: Optional[Dict[Union[str, Parameters], Any]] = None) -> float: """ The average duration of cases completed during a given time slot in which a given resource was involved. Metric RBI 4.4 in Pika, Anastasiia, et al. "Mining resource profiles from event logs." ACM Transactions on Management Information Systems (TMIS) 8.1 (2017): 1-30. Parameters ----------------- log Event log t1 Left interval t2 Right interval r Resource Returns ---------------- metric Value of the metric """ if parameters is None: parameters = {} resource_key = exec_utils.get_param_value( Parameters.RESOURCE_KEY, parameters, xes_constants.DEFAULT_RESOURCE_KEY) from pm4py.algo.filtering.log.attributes import attributes_filter parameters_filter = { attributes_filter.Parameters.ATTRIBUTE_KEY: resource_key } log = attributes_filter.apply(log, [r], parameters=parameters_filter) from pm4py.algo.filtering.log.timestamp import timestamp_filter log = timestamp_filter.filter_traces_intersecting(log, t1, t2, parameters=parameters) from pm4py.statistics.traces.generic.log import case_statistics cd = case_statistics.get_cases_description(log, parameters=parameters).values() return mean(x["caseDuration"] for x in cd)
def filter_time_data(self, timestamps, time_weight): if not isinstance(time_weight, float): raise TypeError if time_weight > 1 or time_weight < 0: raise ValueError if timestamps is None or len(timestamps) == 0: return False event_size = len(timestamps) used = int(event_size * time_weight) filtered = event_size - used if event_size == 0 or used == 0: return None begin = int(filtered / 2) end = begin + used - 1 begin_time = timestamps[begin].strftime("%Y-%m-%d %H:%M:%S") end_time = timestamps[end].strftime("%Y-%m-%d %H:%M:%S") df_times_intersecting = timestamp_filter.filter_traces_intersecting( self.log, begin_time, end_time) return df_times_intersecting
def apply(log, filter, parameters=None): """ Apply a timestamp filter to the log Parameters ------------ log log where the filter should be applied filter Filter (two timestamps separated by @@@) parameters Parameters of the algorithm """ if parameters is None: parameters = {} dt1 = str(datetime.utcfromtimestamp(int(filter[1].split("@@@")[0]))) dt2 = str(datetime.utcfromtimestamp(int(filter[1].split("@@@")[1]))) return timestamp_filter.filter_traces_intersecting(log, dt1, dt2, parameters=parameters)
def test_10(self): from pm4py.algo.filtering.log.timestamp import timestamp_filter log = self.load_running_example_xes() filtered_log = timestamp_filter.filter_traces_intersecting(log, "2011-03-09 00:00:00", "2012-01-18 23:59:59")
from pm4py.objects.log.importer.xes import importer as xes_importer from pm4py.objects.log.util import func log = xes_importer.apply('E:/data/pm/running-example.xes') log = func.filter_(lambda t: len(t) > 2, log) log #filtering event data #logs type from pm4py.algo.filtering.log.timestamp import timestamp_filter filtered_log = timestamp_filter.filter_traces_contained (log, "2011-03-09 00:00:00", "2012-01-18 23:59:59") filtered_log from pm4py.algo.filtering.log.timestamp import timestamp_filter filtered_log = timestamp_filter.filter_traces_intersecting (log, "2011-03-09 00:00:00", "2012-01-18 23:59:59") filtered_log from pm4py.algo.filtering.log.cases import case_filter filtered_log = case_filter.filter_case_performance(log, 86400, 864000) filtered_log #on DF from pm4py.algo.filtering.pandas.timestamp import timestamp_filter df_timest_intersecting = timestamp_filter.filter_traces_intersecting (dataframe, "2011-03-09 00:00:00", "2012-01-18 23:59:59", parameters= {timestamp_filter.Parameters.CASE_ID_KEY: "case:concept:name", timestamp_filter.Parameters.TIMESTAMP_KEY: "time:timestamp"})