def test_logfiltering_filtering1(self): # to avoid static method warnings in tests, # that by construction of the unittest package have to be expressed in such way self.dummy_variable = "dummy_value" input_log = os.path.join(INPUT_DATA_DIR, "running-example.xes") log = xes_importer.apply(input_log) log = attributes_filter.apply_auto_filter(log) log = variants_module.apply_auto_filter(log) log = start_activities_filter.apply_auto_filter(log) log = end_activities_filter.apply_auto_filter(log) log = paths_filter.apply_auto_filter(log) del log
def execute_script(): # import a log log = importer.apply( os.path.join("..", "tests", "input_data", "receipt.xes")) # found a filtered version of the log that is used to discover a process model filtered_log = variants_filter.apply_auto_filter(deepcopy(log)) # discover a process tree using inductive miner tree = inductive_miner.apply_tree(filtered_log) print(tree) # apply the conversion of a process tree into a Petri net net, im, fm = converter.apply(tree) # Footprints discovery: discover a list of footprints # for all the cases of the log fp_log = footprints_discovery.apply(log) # discover the footpritns from the process tree fp_tree = footprints_discovery.apply(tree) # discover the footpritns from the Petri net fp_net = footprints_discovery.apply(net, im) print(len(fp_tree["sequence"]), len(fp_tree["parallel"]), len(fp_net["sequence"]), len(fp_net["parallel"])) print(fp_tree["sequence"] == fp_net["sequence"] and fp_tree["parallel"] == fp_net["parallel"]) # apply the footprints conformance checking conf = footprints_conformance.apply(fp_log, fp_net) for trace_an in conf: if trace_an: # print the first anomalous trace (containing deviations # that are contained in the trace but not allowed by the model) print(trace_an) break # finds the footprints for the entire log (not case-by-case, but taking # the relations that appear inside the entire log) fp_log_entire = footprints_discovery.apply( log, variant=footprints_discovery.Variants.ENTIRE_EVENT_LOG) # visualize the footprint table gviz = fp_visualizer.apply(fp_log_entire, fp_net, parameters={"format": "svg"}) fp_visualizer.view(gviz)
def apply_auto_filter(log, parameters=None): """ Apply some filters in battery to the log in order to get a simplified log Parameters ---------- log Log parameters Eventual parameters applied to the algorithms: decreasingFactor -> Decreasing factor (provided to all algorithms) activity_key -> Activity key (must be specified if different from concept:name) Returns --------- filtered_log Filtered log """ # the following filters are applied: # - activity filter (keep only attributes with a reasonable number of occurrences) (if enabled) # - variant filter (keep only variants with a reasonable number of occurrences) (if enabled) # - start attributes filter (keep only variants that starts with a plausible start activity) (if enabled) # - end attributes filter (keep only variants that starts with a plausible end activity) (if enabled) if parameters is None: parameters = {} attribute_key = parameters[ PARAMETER_CONSTANT_ACTIVITY_KEY] if PARAMETER_CONSTANT_ACTIVITY_KEY in parameters else xes.DEFAULT_NAME_KEY decreasing_factor = parameters[ "decreasingFactor"] if "decreasingFactor" in parameters else filtering_constants.DECREASING_FACTOR parameters_child = { "decreasingFactor": decreasing_factor, constants.PARAMETER_CONSTANT_ACTIVITY_KEY: attribute_key, constants.PARAMETER_CONSTANT_ATTRIBUTE_KEY: attribute_key } enable_activities_filter = parameters[ "enable_activities_filter"] if "enable_activities_filter" in parameters else True enable_variants_filter = parameters[ "enable_variants_filter"] if "enable_variants_filter" in parameters else False enable_start_activities_filter = parameters[ "enable_start_activities_filter"] if "enable_start_activities_filter" in parameters else False enable_end_activities_filter = parameters[ "enable_end_activities_filter"] if "enable_end_activities_filter" in parameters else True variants = variants_module.get_variants(log, parameters=parameters_child) filtered_log = log if enable_activities_filter: filtered_log = attributes_filter.apply_auto_filter( log, variants=variants, parameters=parameters_child) variants = variants_module.get_variants(filtered_log, parameters=parameters_child) if enable_variants_filter: filtered_log = variants_module.apply_auto_filter( filtered_log, variants=variants, parameters=parameters_child) variants = variants_module.get_variants(filtered_log, parameters=parameters_child) if enable_start_activities_filter: filtered_log = start_activities_filter.apply_auto_filter( filtered_log, variants=variants, parameters=parameters_child) if enable_end_activities_filter: filtered_log = end_activities_filter.apply_auto_filter( filtered_log, variants=variants, parameters=parameters_child) return filtered_log
def apply_auto_filter(log, parameters=None): """ Apply some filters in battery to the log in order to get a simplified log Parameters ---------- log Log parameters Eventual parameters applied to the algorithms: Parameters.DECREASING_FACTOR -> Decreasing factor (provided to all algorithms) Parameters.ACTIVITY_KEY -> Activity key (must be specified if different from concept:name) Returns --------- filtered_log Filtered log """ # the following filters are applied: # - activity filter (keep only attributes with a reasonable number of occurrences) (if enabled) # - variant filter (keep only variants with a reasonable number of occurrences) (if enabled) # - start attributes filter (keep only variants that starts with a plausible start activity) (if enabled) # - end attributes filter (keep only variants that starts with a plausible end activity) (if enabled) if parameters is None: parameters = {} enable_activities_filter = exec_utils.get_param_value( Parameters.ENABLE_ACTIVITES_FILTER, parameters, True) enable_variants_filter = exec_utils.get_param_value( Parameters.ENABLE_VARIANTS_FILTER, parameters, False) enable_start_activities_filter = exec_utils.get_param_value( Parameters.ENABLE_START_ACTIVITIES_FILTER, parameters, False) enable_end_activities_filter = exec_utils.get_param_value( Parameters.ENABLE_END_ACTIVITIES_FILTER, parameters, True) attribute_key = exec_utils.get_param_value(Parameters.ATTRIBUTE_KEY, parameters, xes.DEFAULT_NAME_KEY) parameters[Parameters.ATTRIBUTE_KEY] = attribute_key parameters[Parameters.ACTIVITY_KEY] = attribute_key variants = variants_module.get_variants(log, parameters=parameters) filtered_log = log if enable_activities_filter: filtered_log = attributes_filter.apply_auto_filter( log, variants=variants, parameters=parameters) variants = variants_module.get_variants(filtered_log, parameters=parameters) if enable_variants_filter: filtered_log = variants_module.apply_auto_filter(filtered_log, variants=variants, parameters=parameters) variants = variants_module.get_variants(filtered_log, parameters=parameters) if enable_start_activities_filter: filtered_log = start_activities_filter.apply_auto_filter( filtered_log, variants=variants, parameters=parameters) if enable_end_activities_filter: filtered_log = end_activities_filter.apply_auto_filter( filtered_log, variants=variants, parameters=parameters) return filtered_log
def execute_script(): log = xes_importer.apply( os.path.join("..", "tests", "input_data", "receipt.xes")) throughput_time = case_statistics.get_median_caseduration(log) variants, variants_times = variants_filter.get_variants_along_with_case_durations( log) dfg = dfg_discovery.apply(log) filtered_log = variants_filter.apply_auto_filter(deepcopy(log)) # filtered_log = log tree = inductive_miner.apply_tree(filtered_log) fp_log = fp_discovery.apply(log, variant=fp_discovery.Variants.ENTIRE_EVENT_LOG) fp_model = fp_discovery.apply(tree) conf = fp_conformance.apply(fp_log, fp_model) conf_occ = sorted([(x, dfg[x]) for x in conf], key=lambda y: (y[1], y[0][0], y[0][1]), reverse=True) print( "source activity\t\ttarget activity\t\toccurrences\t\tthroughput time log\t\tthroughput time traces with path" ) for i in range(min(10, len(conf_occ))): path = conf_occ[i][0] occ = conf_occ[i][1] red_log = paths_filter.apply(log, [path]) red_throughput_time = case_statistics.get_median_caseduration(red_log) print("%s\t\t%s\t\t%d\t\t%s\t\t%s" % (path[0], path[1], occ, human_readable_stat(throughput_time), human_readable_stat(red_throughput_time))) variants_length = sorted([(x, len(variants[x])) for x in variants.keys()], key=lambda y: (y[1], y[0]), reverse=True) print( "\nvariant\t\toccurrences\t\tthroughput time log\t\tthroughput time traces with path" ) for i in range(min(10, len(variants_length))): var = variants_length[i][0] vark = str(var) if len(vark) > 10: vark = vark[:10] occ = variants_length[i][1] fp_log_var = fp_discovery.apply( variants[var], variant=fp_discovery.Variants.ENTIRE_EVENT_LOG) conf_var = fp_conformance.apply(fp_log_var, fp_model) is_fit = str(len(conf_var) == 0) var_throughput = case_statistics.get_median_caseduration(variants[var]) print("%s\t\t%d\t\t%s\t\t%s\t\t%s" % (vark, occ, is_fit, throughput_time, human_readable_stat(var_throughput))) # print(conf_occ) conf_colors = tree_visualization.apply(tree, conf) if True: gviz = pt_visualizer.apply( tree, parameters={ "format": "svg", pt_visualizer.Variants.WO_DECORATION.value.Parameters.COLOR_MAP: conf_colors, pt_visualizer.Variants.WO_DECORATION.value.Parameters.ENABLE_DEEPCOPY: False }) pt_visualizer.view(gviz)
def test_30(self): from pm4py.algo.filtering.log.variants import variants_filter log = self.load_running_example_xes() auto_filtered_log = variants_filter.apply_auto_filter(log)
parameters={ constants.PARAMETER_CONSTANT_ATTRIBUTE_KEY: "concept:name", "decreasingFactor": 0.6 }) activities = attributes_filter.get_attribute_values(log, "concept:name") auto_filtered_activities = attributes_filter.get_attribute_values( log, "concept:name") # Entire variants from pm4py.algo.filtering.log.variants import variants_filter variants = variants_filter.get_variants(log) log = variants_filter.apply_auto_filter(log) auto_variants = variants_filter.get_variants(auto_filtered_log) # Export the log from pm4py.objects.log.exporter.xes import factory as xes_exporter xes_exporter.export_log( log, "C:/Users/vince_000/Documents/BPI Challenge 2019/Exports/exportedLog_2.xes" ) log[0]