Skip to content

Commit

Permalink
cthub 405: small change (#411)
Browse files Browse the repository at this point in the history
  • Loading branch information
tim738745 authored Nov 12, 2024
1 parent 3e68241 commit dba29f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions django/api/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,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, "delimiter": ","}},
{'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES}},
{"function": region_checker, "columns": ['Economic Region'], "kwargs": {"indices_offset":2}},
]
},
Expand Down Expand Up @@ -828,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, "delimiter": ","}},
{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}},
]
},
"CVP Data": {
Expand Down
21 changes: 12 additions & 9 deletions django/api/services/spreadsheet_uploader_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,15 +364,18 @@ def validate_field_values(df, *columns, **kwargs):
indices = []
series = df[column]
for index, value in series.items():
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 value is not None and pd.notna(value):
str_value = str(value)
items = [str_value.strip()]
if delimiter is not None:
items = [item.strip() for item in str_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] = {
Expand Down

0 comments on commit dba29f3

Please sign in to comment.