From d88095f0771af7bba30388b852678a0bfddcccc5 Mon Sep 17 00:00:00 2001 From: burnettk Date: Sun, 19 Jun 2022 22:57:57 -0400 Subject: [PATCH] update import scripts --- bin/import_tickets_for_command_line.py | 32 +++++++++++++++++--------- bin/import_tickets_for_script_task.py | 22 ++++++++++++------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/bin/import_tickets_for_command_line.py b/bin/import_tickets_for_command_line.py index 32ce1598..5da96400 100644 --- a/bin/import_tickets_for_command_line.py +++ b/bin/import_tickets_for_command_line.py @@ -30,19 +30,26 @@ def main(): with app.app_context(): process_model_identifier_ticket = "ticket" - bpmn_spec_dir = current_app.config["BPMN_SPEC_ABSOLUTE_DIR"] - print(f"bpmn_spec_dir: {bpmn_spec_dir}") db.session.query(ProcessInstanceModel).filter(ProcessInstanceModel.process_model_identifier == process_model_identifier_ticket).delete() db.session.commit() - print_process_instance_count(process_model_identifier_ticket) + + """Print process instance count.""" + process_instances = ProcessInstanceModel.query.filter_by(process_model_identifier=process_model_identifier_ticket).all() + process_instance_count = len(process_instances) + print(f"process_instance_count: {process_instance_count}") + process_model = ProcessModelService().get_process_model(process_model_identifier_ticket) - columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days"} + columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days", "Feature": "feature", "Priority": "priority"} columns_to_header_index_mappings = {} user = UserModel.query.filter_by(username='test_user1').first() with open("tests/files/tickets.csv") as infile: reader = csv.reader(infile, delimiter=",") + + # first row is garbage + next(reader) + header = next(reader) for column_name in columns_to_data_key_mappings: columns_to_header_index_mappings[column_name] = header.index(column_name) @@ -61,19 +68,22 @@ def main(): processor = ProcessInstanceProcessor(process_instance) processor.do_engine_steps() - processor.save() + # processor.save() for column_name, desired_data_key in columns_to_data_key_mappings.items(): appropriate_index = columns_to_header_index_mappings[column_name] - print(f"appropriate_index: {appropriate_index}") processor.bpmn_process_instance.data[desired_data_key] = row[appropriate_index] + + print(f"datas: {processor.bpmn_process_instance.data}") + if processor.bpmn_process_instance.data["month"] == "": + continue + + # you at least need a month, or else this row in the csv is considered garbage + # if processor.bpmn_process_instance.data["month"] is None: + # continue + processor.save() - process_instance_data = processor.get_data() - print(f"process_instance_data: {process_instance_data}") - - print(f"columns_to_header_index_mappings: {columns_to_header_index_mappings}") - print_process_instance_count(process_model_identifier_ticket) # if __name__ == "__main__": diff --git a/bin/import_tickets_for_script_task.py b/bin/import_tickets_for_script_task.py index 49372c98..a70753ef 100644 --- a/bin/import_tickets_for_script_task.py +++ b/bin/import_tickets_for_script_task.py @@ -24,15 +24,17 @@ process_instance_count = len(process_instances) print(f"process_instance_count: {process_instance_count}") process_model = ProcessModelService().get_process_model(process_model_identifier_ticket) -columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days"} +columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days", "Feature": "feature", "Priority": "priority"} columns_to_header_index_mappings = {} user = UserModel.query.filter_by(username='test_user1').first() -a = 1 -with open("tickets.csv") as infile: - b = 2 +with open("tests/files/tickets.csv") as infile: reader = csv.reader(infile, delimiter=",") + + # first row is garbage + next(reader) + header = next(reader) for column_name in columns_to_data_key_mappings: columns_to_header_index_mappings[column_name] = header.index(column_name) @@ -51,15 +53,21 @@ with open("tickets.csv") as infile: processor = ProcessInstanceProcessor(process_instance) processor.do_engine_steps() - processor.save() + # processor.save() for column_name, desired_data_key in columns_to_data_key_mappings.items(): appropriate_index = columns_to_header_index_mappings[column_name] print(f"appropriate_index: {appropriate_index}") processor.bpmn_process_instance.data[desired_data_key] = row[appropriate_index] + + # you at least need a month, or else this row in the csv is considered garbage + month_value = processor.bpmn_process_instance.data["month"] + if month_value == "" or month_value is None: + db.delete(process_instance) + db.session.commit() + continue + processor.save() process_instance_data = processor.get_data() print(f"process_instance_data: {process_instance_data}") - -print(f"columns_to_header_index_mappings: {columns_to_header_index_mappings}")