def test_importExportCSVtoCSV(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"
     event_log = csv_importer.import_log(
         os.path.join(INPUT_DATA_DIR, "running-example.csv"))
     event_log = sorting.sort_timestamp(event_log)
     event_log = sampling.sample(event_log)
     event_log = index_attribute.insert_event_index_as_event_attribute(
         event_log)
     trace_log = log_transform.transform_event_log_to_trace_log(event_log)
     trace_log = sorting.sort_timestamp(trace_log)
     trace_log = sampling.sample(trace_log)
     trace_log = index_attribute.insert_trace_index_as_event_attribute(
         trace_log)
     event_log_transformed = log_transform.transform_trace_log_to_event_log(
         trace_log)
     csv_exporter.export_log(
         event_log_transformed,
         os.path.join(OUTPUT_DATA_DIR, "running-example-exported.csv"))
     event_log_imported_after_export = csv_importer.import_log(
         os.path.join(OUTPUT_DATA_DIR, "running-example-exported.csv"))
     trace_log_imported_after_export = log_transform.transform_event_log_to_trace_log(
         event_log_imported_after_export)
     self.assertEqual(len(trace_log), len(trace_log_imported_after_export))
     os.remove(os.path.join(OUTPUT_DATA_DIR,
                            "running-example-exported.csv"))
Exemple #2
0
 def test_csv1documentation(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"
     import os
     from pm4py.objects.log.importer.csv import factory as csv_importer
     event_log = csv_importer.import_log(
         os.path.join("input_data", "running-example.csv"))
     event_log_length = len(event_log)
     del event_log_length
     from pm4py.objects.log import transform
     trace_log = transform.transform_event_log_to_trace_log(
         event_log, case_glue="case:concept:name")
     del trace_log
     from pm4py.objects.log.importer.csv.versions import pandas_df_imp
     from pm4py.objects.log import transform
     dataframe = pandas_df_imp.import_dataframe_from_path(
         os.path.join("input_data", "running-example.csv"))
     event_log = pandas_df_imp.convert_dataframe_to_event_log(dataframe)
     trace_log = transform.transform_event_log_to_trace_log(
         event_log, case_glue="case:concept:name")
     from pm4py.objects.log.exporter.csv import factory as csv_exporter
     csv_exporter.export_log(event_log, "outputFile1.csv")
     os.remove("outputFile1.csv")
     from pm4py.objects.log.exporter.csv import factory as csv_exporter
     csv_exporter.export_log(trace_log, "outputFile2.csv")
     os.remove("outputFile2.csv")
Exemple #3
0
 def test_importExportXEStoCSV(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"
     trace_log = xes_importer.import_log(
         os.path.join(INPUT_DATA_DIR, "running-example.xes"))
     event_log = log_transform.transform_trace_log_to_event_log(trace_log)
     csv_exporter.export_log(
         event_log,
         os.path.join(OUTPUT_DATA_DIR, "running-example-exported.csv"))
     event_log_newimport = csv_importer.import_log(
         os.path.join(OUTPUT_DATA_DIR, "running-example-exported.csv"))
     trace_log_imported_after_export = log_transform.transform_event_log_to_trace_log(
         event_log_newimport)
     self.assertEqual(len(trace_log), len(trace_log_imported_after_export))
     os.remove(os.path.join(OUTPUT_DATA_DIR,
                            "running-example-exported.csv"))
Exemple #4
0
	def get_input_file(self):
        event_log_address = input("Event Log:")
        log_format = event_log_address.split('.')[-1]

        if str(log_format) == 'csv':
            event_log = pd.read_csv(event_log_address)

        elif str(log_format) == 'xes':
            xes_log = xes_importer.import_log(event_log_address)
            event_log = transform.transform_trace_log_to_event_log(xes_log)
            csv_exporter.export_log(event_log, "event_log.csv")
            event_log = pd.read_csv("event_log.csv")

        event_log_attributes = event_log.columns

        return event_log

    # Create DataFrame including 
	def create_matrix_resource(self, event_log):

        event_log['Complete Timestamp'] = pd.to_datetime(event_log['Complete Timestamp'])
        event_log['Start Timestamp'] = pd.to_datetime(event_log['Start Timestamp'])
        event_duration = abs(event_log['Complete Timestamp'] - event_log['Start Timestamp'])
        event_log['Event Duration'] = event_duration
      
		# create adjancy matrix of activities
        resource_matrix = pd.DataFrame(
            np.zeros(shape=(event_log['Resource'].nunique(), event_log['Resource'].nunique())),
            columns=event_log['Resource'].unique(), index=event_log['Resource'].unique())
        temp_log = event_log.sort_values(['Start Timestamp'], ascending=True).groupby('Case ID')
        trace = {}

        for case, casegroup in temp_log:
            trace.update({case: casegroup['Resource'].values})

        for key, val in trace.items():
            i = 0
            while i < (len(val) - 1):
                resource_matrix[val[i + 1]][val[i]] += 1
                i += 1

        return resource_matrix
	
	# Create Matrix of Activities (Adjancy Matrix for Directly Follows Graph) 
	# In: event log, Out: Adjancy Matrix of Activities
    def create_matrix(self, event_log):
        event_log['Complete Timestamp'] = pd.to_datetime(event_log['Complete Timestamp'])
        event_log['Start Timestamp'] = pd.to_datetime(event_log['Start Timestamp'])
        event_duration = abs(event_log['Complete Timestamp'] - event_log['Start Timestamp'])
        event_log['Event Duration'] = event_duration
        
		# create activity duration dictionary		
		act_dur_dict = {}
        temp_act_log = event_log.groupby(['Activity'])
        for kact, vact in temp_act_log:
            act_dur_dict[kact] = vact['Event Duration'].mean()
			
		# create adjancy matrix of activities
        matrix = pd.DataFrame(np.zeros(shape=(event_log['Activity'].nunique(), event_log['Activity'].nunique())),
                              columns=event_log['Activity'].unique(), index=event_log['Activity'].unique())
        temp_log = event_log.sort_values(['Start Timestamp'], ascending=True).groupby('Case ID')
        trace = {}

        for case, casegroup in temp_log:
            trace.update({case: casegroup['Activity'].values})

        for key, val in trace.items():
            i = 0
            while i < (len(val) - 1):
                matrix[val[i + 1]][val[i]] += 1
                i += 1
        return matrix,act_dur_dict