19arjun89 commited on
Commit
400e185
·
verified ·
1 Parent(s): de84dbc

Update usage_logging.py

Browse files
Files changed (1) hide show
  1. usage_logging.py +10 -3
usage_logging.py CHANGED
@@ -273,6 +273,15 @@ def _expand_country_code(code: str) -> str:
273
  return "Unknown"
274
 
275
 
 
 
 
 
 
 
 
 
 
276
  def rebuild_visits_rollup_from_event_files() -> str:
277
  """
278
  Rebuilds usage/visits.jsonl from immutable per-event JSON files in usage/events/.
@@ -363,9 +372,7 @@ def rebuild_visits_rollup_from_event_files() -> str:
363
 
364
  # Determine final_country / final_country_code
365
  if sid:
366
- # New schema row: prefer existing event country if it’s meaningful,
367
- # else fall back to session geo.
368
- if evt_country and evt_country.lower() != "unknown":
369
  enriched["final_country"] = evt_country
370
  enriched["final_country_code"] = evt_cc
371
  enriched["final_country_source"] = evt.get("country_source") or "unknown"
 
273
  return "Unknown"
274
 
275
 
276
+ def _is_meaningful_country(val: str) -> bool:
277
+ v = (val or "").strip().lower()
278
+ if not v:
279
+ return False
280
+ if v in {"unknown", "na", "n/a", "none", "null", "undefined"}:
281
+ return False
282
+ return True
283
+
284
+
285
  def rebuild_visits_rollup_from_event_files() -> str:
286
  """
287
  Rebuilds usage/visits.jsonl from immutable per-event JSON files in usage/events/.
 
372
 
373
  # Determine final_country / final_country_code
374
  if sid:
375
+ if _is_meaningful_country(evt_country):
 
 
376
  enriched["final_country"] = evt_country
377
  enriched["final_country_code"] = evt_cc
378
  enriched["final_country_source"] = evt.get("country_source") or "unknown"