Skip to content

Commit

Permalink
fixes #427 handle missing postal code
Browse files Browse the repository at this point in the history
  • Loading branch information
danmash committed Oct 26, 2022
1 parent ef582e6 commit fb46d5e
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/scoring/build_localised_acyclic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ def check_if_valid_postal_code(quiz_uuid):
result = con.execute(
"SELECT * FROM lrf_data WHERE lrf_data.postal_code=?",
(postal_code,),
)
exists_in_lrf_table = list(result.fetchone())
).fetchone()

if not result:
return None

db_postal_codes = list(result)
# Get the column names from the lrf_data table and create a list of names
columns = con.execute(
"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='lrf_data'"
Expand All @@ -80,12 +84,12 @@ def check_if_valid_postal_code(quiz_uuid):
for name in column_names:
column_names_list.append(name[0])

if exists_in_lrf_table:
if db_postal_codes:
# Create a dictionary of lrf data for the specific postal code where the lrf_data table column names
# (the postal code and the IRIs) are the keys matched to the lrf_data table values for that postal code.
short_IRIs = [get_iri(long_iri) for long_iri in column_names_list[1:]]

lrf_single_postcode_dict = dict(zip(short_IRIs, exists_in_lrf_table[1:]))
lrf_single_postcode_dict = dict(zip(short_IRIs, db_postal_codes[1:]))
return lrf_single_postcode_dict

else:
Expand Down

0 comments on commit fb46d5e

Please sign in to comment.