annikwag commited on
Commit
4345f0f
·
verified ·
1 Parent(s): e01ddd2

Update appStore/prep_data.py

Browse files
Files changed (1) hide show
  1. appStore/prep_data.py +20 -0
appStore/prep_data.py CHANGED
@@ -191,4 +191,24 @@ def get_max_end_year(_client, collection_name):
191
  # fallback if no valid end years found
192
  return 2030
193
  return int(max(years))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
 
191
  # fallback if no valid end years found
192
  return 2030
193
  return int(max(years))
194
+
195
+ # Helper: safe formatting of project IDs
196
+ def safe_format_project_id(pid):
197
+ """
198
+ Safely format a project ID:
199
+ - If the ID is a float ending with ".0", remove it.
200
+ - If the value is "nan" (case insensitive) or empty, return an empty string.
201
+ - Otherwise, format it in the typical GIZ format if it has enough digits.
202
+ """
203
+ s = str(pid)
204
+ # Remove trailing ".0" if present
205
+ if s.endswith(".0"):
206
+ s = s[:-2]
207
+ # If the value is 'nan' or empty after stripping, return empty string
208
+ if s.lower() == "nan" or s.strip() == "":
209
+ return ""
210
+ # Format if the string has enough digits
211
+ if len(s) > 5:
212
+ return s[:4] + "." + s[4:-1] + "." + s[-1]
213
+ return s
214