diff --git a/django/api/constants/constants.py b/django/api/constants/constants.py index 28a0b442..cb6c5ea9 100644 --- a/django/api/constants/constants.py +++ b/django/api/constants/constants.py @@ -436,7 +436,8 @@ class CVPDataColumns(Enum): VEHICLE_CATEGORY = "Vehicle Category" DRIVE_TYPE = "Drive Type" VEHICLE_TYPE = "Vehicle Type" - PORTFOLIO = "Portfolio" + ROAD_CLASS = "Class" + USE_CASE = "Use Case" MAKE_AND_MODEL = "Vehicle Make and Model" ECONOMIC_REGION = "Economic Region" START_DATE = "Start Date" @@ -483,7 +484,8 @@ class CVPDataColumnMapping(Enum): vehicle_category = "Vehicle Category" drive_type = "Drive Type" vehicle_type = "Vehicle Type" - portfolio = "Portfolio" + road_class = "Class" + use_case = "Use Case" make_and_model = "Vehicle Make and Model" economic_region = "Economic Region" start_date = "Start Date" @@ -713,7 +715,8 @@ class CVPDataColumnMapping(Enum): "vehicle_category": str, "drive_type": str, "vehicle_type": str, - "portfolio": str, + "road_class": str, + "use_case": str, "make_and_model": str, "economic_region": str, "start_date": datetime.date, @@ -761,7 +764,7 @@ class CVPDataColumnMapping(Enum): "sheet_name": "ARC Data", "preparation_functions": [prepare_arc_project_tracking], "validation_functions": [ - {'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES}}, + {'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES, "delimiter": ","}}, {"function": region_checker, "columns": ['Economic Region'], "kwargs": {"indices_offset":2}}, ] }, @@ -825,7 +828,7 @@ class CVPDataColumnMapping(Enum): {"function": typo_checker, "columns": ["Applicant Name"], "kwargs": {"cutoff": 0.8, "indices_offset": 2}}, {"function": location_checker, "columns": ["City"], "kwargs": {"columns_to_features_map": {"City": LOCALITY_FEATURES_MAP}, "indices_offset":2}}, {"function": email_validator, "columns": ["Email"], "kwargs": {"indices_offset":2, "get_resolver": get_google_resolver}}, - {"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}}, + {"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES, "delimiter": ","}}, ] }, "CVP Data": { @@ -834,7 +837,7 @@ class CVPDataColumnMapping(Enum): "column_mapping": CVPDataColumnMapping, "sheet_name": "Data", "preparation_functions": [prepare_cvp_data], - "validation_functions": [{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": CVP_DATA_VALID_FIELD_VALUES}},] + "validation_functions": [{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": CVP_DATA_VALID_FIELD_VALUES, "delimiter": ","}},] }, } diff --git a/django/api/constants/misc.py b/django/api/constants/misc.py index 10dc15f5..c5cf5af8 100644 --- a/django/api/constants/misc.py +++ b/django/api/constants/misc.py @@ -94,9 +94,9 @@ 'Status': ['Approved', 'Completed', 'Terminated', 'Not Approved', 'Application Withdrawn'], 'Vehicles Deployed': ['Yes', 'No'], 'Vehicle Category': ['On-Road', 'Off-Road', 'Marine', 'Rail', 'Aviation'], - 'Portfolio': [ - 'Road - 8', 'Rail', 'Marine', 'Road - 8C', 'School Bus', - 'Loader', 'Road - 6', 'Fork Lift', 'Recreation' + 'Class': [ + 'Road - 3', 'Road - 4', 'Road - 5', 'Road - 6', 'Road - 7', + 'Road - 8', 'Road - 8C' ], 'Economic Region': [ 'Nechako', 'Northeast', 'North Coast', 'Cariboo', 'Vancouver Island/Coast', diff --git a/django/api/migrations/0039_auto_20241031_2123.py b/django/api/migrations/0039_auto_20241031_2123.py new file mode 100644 index 00000000..eb120c7f --- /dev/null +++ b/django/api/migrations/0039_auto_20241031_2123.py @@ -0,0 +1,27 @@ +# Generated by Django 3.2.25 on 2024-10-31 21:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0038_addregions'), + ] + + operations = [ + migrations.RemoveField( + model_name='cvpdata', + name='portfolio', + ), + migrations.AddField( + model_name='cvpdata', + name='road_class', + field=models.CharField(blank=True, max_length=100, null=True), + ), + migrations.AddField( + model_name='cvpdata', + name='use_case', + field=models.CharField(blank=True, max_length=100, null=True), + ), + ] diff --git a/django/api/models/cvp_data.py b/django/api/models/cvp_data.py index 06a007a8..9f5c8770 100644 --- a/django/api/models/cvp_data.py +++ b/django/api/models/cvp_data.py @@ -44,8 +44,12 @@ class CVPData(Auditable): blank=False, null=False, max_length=100 ) - portfolio = models.CharField( - blank=False, null=False, max_length=100 + road_class = models.CharField( + blank=True, null=True, max_length=100 + ) + + use_case = models.CharField( + blank=True, null=True, max_length=100 ) make_and_model = models.CharField( diff --git a/django/api/services/spreadsheet_uploader_prep.py b/django/api/services/spreadsheet_uploader_prep.py index 391a41b9..ed30de8d 100644 --- a/django/api/services/spreadsheet_uploader_prep.py +++ b/django/api/services/spreadsheet_uploader_prep.py @@ -353,22 +353,27 @@ def email_validator(df, *columns, **kwargs): } return result - - def validate_field_values(df, *columns, **kwargs): allowed_values = kwargs.get("fields_and_values") invalid_values = [] result = {} + delimiter = kwargs.get("delimiter") for column in df.columns: if column in allowed_values: indices = [] series = df[column] for index, value in series.items(): - if str(value).upper() not in (item.upper() for item in allowed_values[column]) and value != '' and value is not None and not pd.isna(value): - indices.append(index + kwargs.get("indices_offset", 0)) - if str(value) not in invalid_values: - invalid_values.append(str(value)) + if delimiter is not None: + items = [item.strip() for item in value.split(delimiter)] + + for item in items: + if str(item).upper() not in (valid.upper() for valid in allowed_values[column]) and item != '' and item is not None and not pd.isna(item): + if index + kwargs.get("indices_offset", 0) not in indices: + indices.append(index + kwargs.get("indices_offset", 0)) + if str(item) not in invalid_values: + invalid_values.append(str(item)) + if indices: result[column] = { ', '.join(invalid_values) + " - is not in the list of expected values": {