def median(self, collection): try: self.allTimers = collection self.stat = median(collection) except StatisticsError: self.stat = 0 return self.stat
def apply(log, parameters=None): """ Measure performance between couples of attributes in the DFG graph Parameters ---------- log Log parameters Possible parameters passed to the algorithms: aggregationMeasure -> performance aggregation measure (min, max, mean, median) activity_key -> Attribute to use as activity timestamp_key -> Attribute to use as timestamp Returns ------- dfg DFG graph """ if parameters is None: parameters = {} activity_key = parameters[ PARAMETER_CONSTANT_ACTIVITY_KEY] if PARAMETER_CONSTANT_ACTIVITY_KEY in parameters else DEFAULT_NAME_KEY timestamp_key = parameters[ PARAMETER_CONSTANT_TIMESTAMP_KEY] if PARAMETER_CONSTANT_TIMESTAMP_KEY in parameters else DEFAULT_TIMESTAMP_KEY aggregation_measure = parameters[ "aggregationMeasure"] if "aggregationMeasure" in parameters else "mean" dfgs0 = map((lambda t: [( (t[i - 1][activity_key], t[i][activity_key]), (t[i][timestamp_key] - t[i - 1][timestamp_key]).total_seconds()) for i in range(1, len(t))]), log) ret0 = {} for el in dfgs0: for couple in el: if not couple[0] in ret0: ret0[couple[0]] = [] ret0[couple[0]].append(couple[1]) ret = Counter() for key in ret0: if aggregation_measure == "median": ret[key] = median(ret0[key]) elif aggregation_measure == "min": ret[key] = min(ret0[key]) elif aggregation_measure == "max": ret[key] = max(ret0[key]) elif aggregation_measure == "stdev": ret[key] = stdev(ret0[key]) elif aggregation_measure == "sum": ret[key] = sum(ret0[key]) else: ret[key] = mean(ret0[key]) return ret
def get_median_case_duration(list_cases, timestamp_key=xes.DEFAULT_TIMESTAMP_KEY): """ Gets the median case duration of a list of cases Parameters ------------- list_cases List of cases timestamp_key Attribute of the event to use as timestamp Returns ------------- median_case_duration Median case duration """ durations = [] for trace in list_cases: durations.append(get_case_duration(trace, timestamp_key=timestamp_key)) return median(durations)