def test_case_statistics(self):
     from pm4py.statistics.traces.log import case_statistics
     log = self.get_log()
     case_statistics.get_kde_caseduration(log)
     case_statistics.get_events(log, "N77802")
     case_statistics.get_variant_statistics(log)
     case_statistics.get_cases_description(log)
     case_statistics.get_all_casedurations(log)
     case_statistics.get_first_quartile_caseduration(log)
     case_statistics.get_median_caseduration(log)
Exemple #2
0
    def get_case_statistics(self, parameters=None):
        """
        Gets the statistics on cases

        Parameters
        -------------
        parameters
            Possible parameters of the algorithm

        Returns
        -------------
        list_cases
            List of cases
        """
        if parameters is None:
            parameters = {}
        parameters[
            constants.PARAMETER_CONSTANT_ACTIVITY_KEY] = self.activity_key
        parameters[
            constants.PARAMETER_CONSTANT_ATTRIBUTE_KEY] = self.activity_key
        #parameters["max_ret_cases"] = ws_constants.MAX_NO_CASES_TO_RETURN
        parameters["sort_by_index"] = parameters[
            "sort_by_index"] if "sort_by_index" in parameters else 0
        parameters["sort_ascending"] = parameters[
            "sort_ascending"] if "sort_ascending" in parameters else False
        parameters["variants"] = self.variants
        if "variant" in parameters:
            var_to_filter = parameters["variant"]
            # TODO: TECHNICAL DEBT
            # quick turnaround for bug
            var_to_filter = var_to_filter.replace(" start", "+start")
            var_to_filter = var_to_filter.replace(" START", "+START")
            var_to_filter = var_to_filter.replace(" complete", "+complete")
            var_to_filter = var_to_filter.replace(" COMPLETE", "+COMPLETE")
            filtered_log = variants_filter.apply(self.log, [var_to_filter],
                                                 parameters=parameters)
            return [
                casestats.include_key_in_value_list(
                    case_statistics.get_cases_description(
                        filtered_log, parameters=parameters))
            ] + [self.get_log_summary_dictio()]
        else:
            return [
                casestats.include_key_in_value_list(
                    case_statistics.get_cases_description(
                        self.log, parameters=parameters))
            ] + [self.get_log_summary_dictio()]
Exemple #3
0
def average_case_duration(
        log: EventLog,
        t1: Union[datetime, str],
        t2: Union[datetime, str],
        r: str,
        parameters: Optional[Dict[str, 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.log import case_statistics
    cd = case_statistics.get_cases_description(log,
                                               parameters=parameters).values()
    return mean(x["caseDuration"] for x in cd)