annikwag commited on
Commit
e25a980
·
verified ·
1 Parent(s): 7fe45cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -1
app.py CHANGED
@@ -195,6 +195,18 @@ def filter_results(results, country_filter, region_filter, end_year_range, crs_f
195
  c_list = []
196
  else:
197
  c_list = [clean_country_code(country)]
 
 
 
 
 
 
 
 
 
 
 
 
198
  crs_key = metadata.get("crs_key", "").strip()
199
  # Convert crs_key to a string and remove trailing ".0"
200
  crs_key_clean = re.sub(r'\.0$', '', str(crs_key))
@@ -218,7 +230,7 @@ def filter_results(results, country_filter, region_filter, end_year_range, crs_f
218
 
219
  year_ok = True if end_year_val == 0 else (end_year_range[0] <= end_year_val <= end_year_range[1])
220
 
221
- if ((country_filter == "All/Not allocated" or (selected_iso_code and selected_iso_code in c_list))
222
  and (region_filter == "All/Not allocated" or country_in_region)
223
  and year_ok):
224
  filtered.append(r)
 
195
  c_list = []
196
  else:
197
  c_list = [clean_country_code(country)]
198
+
199
+ # After obtaining and cleaning the country codes into c_list:
200
+ resolved_names = [get_country_name(code, region_df) for code in c_list]
201
+
202
+ # And similarly for regions, if you have a mapping (e.g., iso_code_to_sub_region),
203
+ # check if any of the codes in c_list has a matching region:
204
+ country_in_region = any(
205
+ iso_code_to_sub_region.get(code, "Not allocated") == region_filter
206
+ for code in c_list
207
+ )
208
+
209
+
210
  crs_key = metadata.get("crs_key", "").strip()
211
  # Convert crs_key to a string and remove trailing ".0"
212
  crs_key_clean = re.sub(r'\.0$', '', str(crs_key))
 
230
 
231
  year_ok = True if end_year_val == 0 else (end_year_range[0] <= end_year_val <= end_year_range[1])
232
 
233
+ if ((country_filter == "All/Not allocated" or (country_filter in resolved_names))
234
  and (region_filter == "All/Not allocated" or country_in_region)
235
  and year_ok):
236
  filtered.append(r)