Spaces:
Running
Running
Update usage_logging.py
Browse files- usage_logging.py +3 -4
usage_logging.py
CHANGED
|
@@ -278,7 +278,7 @@ def rebuild_visits_rollup_from_event_files() -> str:
|
|
| 278 |
Rebuilds usage/visits.jsonl from immutable per-event JSON files in usage/events/.
|
| 279 |
ALSO writes an enriched rollup usage/visits_enriched.jsonl where:
|
| 280 |
- legacy rows (no session_id) keep their original country as final_country
|
| 281 |
-
- new click rows (with session_id) get final_country from the session's
|
| 282 |
"""
|
| 283 |
api = _hf_api()
|
| 284 |
if not api:
|
|
@@ -321,11 +321,10 @@ def rebuild_visits_rollup_from_event_files() -> str:
|
|
| 321 |
# 3) Sort by ts_utc
|
| 322 |
events.sort(key=lambda e: (e.get("ts_utc") or ""))
|
| 323 |
|
| 324 |
-
# 4) Build session → geo map from
|
| 325 |
-
# NOTE: you said you are using "usage_start" (not "session_start")
|
| 326 |
session_geo = {}
|
| 327 |
for e in events:
|
| 328 |
-
if e.get("event") == "
|
| 329 |
sid = (e.get("session_id") or "").strip()
|
| 330 |
if not sid:
|
| 331 |
continue # legacy usage_start rows won’t have session_id; ignore for mapping
|
|
|
|
| 278 |
Rebuilds usage/visits.jsonl from immutable per-event JSON files in usage/events/.
|
| 279 |
ALSO writes an enriched rollup usage/visits_enriched.jsonl where:
|
| 280 |
- legacy rows (no session_id) keep their original country as final_country
|
| 281 |
+
- new click rows (with session_id) get final_country from the session's session_start row when available
|
| 282 |
"""
|
| 283 |
api = _hf_api()
|
| 284 |
if not api:
|
|
|
|
| 321 |
# 3) Sort by ts_utc
|
| 322 |
events.sort(key=lambda e: (e.get("ts_utc") or ""))
|
| 323 |
|
| 324 |
+
# 4) Build session → geo map from session_start events (new schema)
|
|
|
|
| 325 |
session_geo = {}
|
| 326 |
for e in events:
|
| 327 |
+
if e.get("event") == "session_start":
|
| 328 |
sid = (e.get("session_id") or "").strip()
|
| 329 |
if not sid:
|
| 330 |
continue # legacy usage_start rows won’t have session_id; ignore for mapping
|