Skip to content

Commit

Permalink
Adding function to check if values in fields are valid (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianForeman authored Jul 11, 2024
1 parent 9c94c12 commit fd15645
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
7 changes: 5 additions & 2 deletions django/api/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
validate_phone_numbers,
typo_checker,
location_checker,
email_validator
email_validator,
validate_field_values
)
from api.services.resolvers import get_google_resolver
from api.constants.misc import GER_VALID_FIELD_VALUES


class ARCProjectTrackingColumns(Enum):
Expand Down Expand Up @@ -656,7 +658,8 @@ class GoElectricRebatesColumnMapping(Enum):
{"error_type": "Phone Error", "function": validate_phone_numbers, "columns": ["Phone Number"], "kwargs": {"indices_offset": 2}},
{"error_type": "Potential Typo", "function": typo_checker, "columns": ["Applicant Name"], "kwargs": {"cutoff": 0.8, "indices_offset": 2}},
{"error_type": "Location Not Found", "function": location_checker, "columns": ["City"], "kwargs": {"indices_offset":2}},
{"error_type": "Invalid Email", "function": email_validator, "columns": ["Email"], "kwargs": {"indices_offset":2, "get_resolver": get_google_resolver}}
{"error_type": "Invalid Email", "function": email_validator, "columns": ["Email"], "kwargs": {"indices_offset":2, "get_resolver": get_google_resolver}},
{"error_type": "Invalid Value", "function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}}
]
},
}
12 changes: 11 additions & 1 deletion django/api/constants/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
867,
]


RELEVANT_FEATURES = [
"Canadian Forces Base",
"Canadian Forces Station",
Expand All @@ -77,3 +76,14 @@
"Village (1)",
"Town",
]

GER_VALID_FIELD_VALUES = {
'Approvals': ['Approved', 'Approved Fraudulent'],
'Category': [
'Forklift', 'Low Speed', 'Motorcycle', 'Medium & Heavy Duty',
'Airport & Port Specialty Vehicle', 'Cargo E-Bike', 'Utility Vehicle'
],
'Fleet/Individuals': ['Fleet', 'Individual'],
'Rebate adjustment (discount)': ['Yes'],
'Class': ['2B', '3', '4', '5', '6', '7', '8']
}
17 changes: 17 additions & 0 deletions django/api/services/spreadsheet_uploader_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,21 @@ def email_validator(df, *columns, **kwargs):
indices.append(index + kwargs.get("indices_offset", 0))
if indices:
result[column] = indices
return result

def validate_field_values(df, *columns, **kwargs):

allowed_values = kwargs.get("fields_and_values")

result = {}
for column in df.columns:
if column in allowed_values:
indices = []
series = df[column]
for index, value in series.items():
if str(value) not in allowed_values[column]:
indices.append(index + kwargs.get("indices_offset", 0))
if indices:
result[column] = indices

return result

0 comments on commit fd15645

Please sign in to comment.