From 7f7f489ae5fd27b9bcbe8f3f2a96f80f61e150f5 Mon Sep 17 00:00:00 2001 From: Caleb Rutan Date: Wed, 14 Aug 2024 22:10:55 +0000 Subject: [PATCH 1/3] add code to enable client to read the isOmitted field in the CSV file, if present, and to pass it to the backend --- pyseed/seed_client.py | 8 +++++--- pyseed/utils.py | 21 ++++++++++++--------- tests/test_utils.py | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pyseed/seed_client.py b/pyseed/seed_client.py index 0b368e6..5e592d5 100644 --- a/pyseed/seed_client.py +++ b/pyseed/seed_client.py @@ -924,6 +924,7 @@ def create_or_update_column_mapping_profile( "from_units": null, "to_table_name": "PropertyState" "to_field": "address_line_1", + "isOmitted": False }, { "from_field": "address1", @@ -934,6 +935,7 @@ def create_or_update_column_mapping_profile( ... ] + The isOmitted mapping may be absent - it is treated as False if it is not present. Returns: dict: { 'id': 1 @@ -972,9 +974,9 @@ def create_or_update_column_mapping_profile_from_file( ) -> dict: """creates or updates a mapping profile. The format of the mapping file is a CSV with the following format: - Raw Columns, units, SEED Table, SEED Columns\n - PM Property ID, , PropertyState, pm_property_id\n - Building ID, , PropertyState, custom_id_1\n + Raw Columns, units, SEED Table, SEED Columns, Omit\n + PM Property ID, , PropertyState, pm_property_id, False\n + Building ID, , PropertyState, custom_id_1, False\n ...\n This only works for 'Normal' column mapping profiles, that is, it does not work for diff --git a/pyseed/utils.py b/pyseed/utils.py index e10fd59..c5e1643 100644 --- a/pyseed/utils.py +++ b/pyseed/utils.py @@ -113,15 +113,18 @@ def read_map_file(mapfile_path): # Open the mapping file and fill list maplist = list() - for rowitem in map_reader: - maplist.append( - { - 'from_field': rowitem[0], - 'from_units': rowitem[1], - 'to_table_name': rowitem[2], - 'to_field': rowitem[3], - } - ) + data = { + "from_field": rowitem[0], + "from_units": rowitem[1], + "to_table_name": rowitem[2], + "to_field": rowitem[3], + } + try: + data["isOmitted"] = True if rowitem[4].lower().strip() == "true" else False + except IndexError: + data["isOmitted"] = False + + maplist.append(data) return maplist diff --git a/tests/test_utils.py b/tests/test_utils.py index e7d1cc4..1b828e8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -22,5 +22,6 @@ def test_mapping_file(self): "from_units": "ft**2", "to_field": "gross_floor_area", "to_table_name": "PropertyState", + "isOmitted": False } assert mappings[5] == expected From e44d55a5be8a9453c6259d63ebdcebbaddeddc36 Mon Sep 17 00:00:00 2001 From: Caleb Rutan Date: Thu, 15 Aug 2024 13:45:08 +0000 Subject: [PATCH 2/3] isOmitted -> is_omitted --- pyseed/seed_client.py | 4 ++-- pyseed/utils.py | 4 ++-- tests/test_utils.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyseed/seed_client.py b/pyseed/seed_client.py index 5e592d5..6b7b0e4 100644 --- a/pyseed/seed_client.py +++ b/pyseed/seed_client.py @@ -924,7 +924,7 @@ def create_or_update_column_mapping_profile( "from_units": null, "to_table_name": "PropertyState" "to_field": "address_line_1", - "isOmitted": False + "is_omitted": False }, { "from_field": "address1", @@ -935,7 +935,7 @@ def create_or_update_column_mapping_profile( ... ] - The isOmitted mapping may be absent - it is treated as False if it is not present. + The is_omitted mapping may be absent - it is treated as False if it is not present. Returns: dict: { 'id': 1 diff --git a/pyseed/utils.py b/pyseed/utils.py index c5e1643..f4f4f0f 100644 --- a/pyseed/utils.py +++ b/pyseed/utils.py @@ -121,9 +121,9 @@ def read_map_file(mapfile_path): "to_field": rowitem[3], } try: - data["isOmitted"] = True if rowitem[4].lower().strip() == "true" else False + data["is_omitted"] = True if rowitem[4].lower().strip() == "true" else False except IndexError: - data["isOmitted"] = False + data["is_omitted"] = False maplist.append(data) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1b828e8..7e1fd71 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -22,6 +22,6 @@ def test_mapping_file(self): "from_units": "ft**2", "to_field": "gross_floor_area", "to_table_name": "PropertyState", - "isOmitted": False + "is_omitted": False } assert mappings[5] == expected From 8b8ec1fcca667649e3680e7071d0266aeb8f09af Mon Sep 17 00:00:00 2001 From: Caleb Rutan Date: Thu, 15 Aug 2024 14:27:13 +0000 Subject: [PATCH 3/3] linter --- pyseed/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyseed/utils.py b/pyseed/utils.py index f4f4f0f..ee09ef4 100644 --- a/pyseed/utils.py +++ b/pyseed/utils.py @@ -115,11 +115,11 @@ def read_map_file(mapfile_path): maplist = list() for rowitem in map_reader: data = { - "from_field": rowitem[0], - "from_units": rowitem[1], - "to_table_name": rowitem[2], - "to_field": rowitem[3], - } + "from_field": rowitem[0], + "from_units": rowitem[1], + "to_table_name": rowitem[2], + "to_field": rowitem[3], + } try: data["is_omitted"] = True if rowitem[4].lower().strip() == "true" else False except IndexError: