19arjun89 commited on
Commit
f0fe416
·
verified ·
1 Parent(s): 91db5a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -75,26 +75,38 @@ def build_report():
75
 
76
  scanned = 0
77
  mappable = 0
 
 
 
78
 
79
  for row in load_rows_streaming():
80
  scanned += 1
 
 
81
  event_type = str(row.get("event", "") or "").strip().lower()
82
  if event_type == "session_start":
 
83
  continue
 
 
84
  country = normalize_country_name(row.get("final_country"))
85
  if not country:
 
86
  continue
87
-
88
- country_counts[country] += 1
89
-
90
  iso3 = iso2_to_iso3(row.get("final_country_code"))
91
  if not iso3:
 
92
  continue
93
 
 
 
94
  iso3_counts[iso3] += 1
95
  iso3_to_name.setdefault(iso3, country)
96
  mappable += 1
97
 
 
98
  # Table dataframe (country name + usage events)
99
  table_df = (
100
  pd.DataFrame([{"country": k, "usage events": v} for k, v in country_counts.items()])
@@ -205,9 +217,22 @@ def build_report():
205
  font=dict(size=20),
206
  )
207
 
 
 
 
 
 
 
 
208
  summary = (
209
- f"Rows scanned: {scanned:,} • Rows mappable: {mappable:,} • "
210
- f"Countries (table): {len(table_df):,} • Countries (map): {len(map_df):,}"
 
 
 
 
 
 
211
  f"Total usage events: {int(table_df['usage events'].sum()) if len(table_df) else 0:,}"
212
  )
213
 
 
75
 
76
  scanned = 0
77
  mappable = 0
78
+ skipped_session_start = 0
79
+ missing_country = 0
80
+ invalid_country_code = 0
81
 
82
  for row in load_rows_streaming():
83
  scanned += 1
84
+
85
+ # 1) Skip session starts
86
  event_type = str(row.get("event", "") or "").strip().lower()
87
  if event_type == "session_start":
88
+ skipped_session_start += 1
89
  continue
90
+
91
+ # 2) Missing country
92
  country = normalize_country_name(row.get("final_country"))
93
  if not country:
94
+ missing_country += 1
95
  continue
96
+
97
+ # 3) Invalid / missing country code
 
98
  iso3 = iso2_to_iso3(row.get("final_country_code"))
99
  if not iso3:
100
+ invalid_country_code += 1
101
  continue
102
 
103
+ country_counts[country] += 1
104
+
105
  iso3_counts[iso3] += 1
106
  iso3_to_name.setdefault(iso3, country)
107
  mappable += 1
108
 
109
+
110
  # Table dataframe (country name + usage events)
111
  table_df = (
112
  pd.DataFrame([{"country": k, "usage events": v} for k, v in country_counts.items()])
 
217
  font=dict(size=20),
218
  )
219
 
220
+ accounted = (
221
+ skipped_session_start
222
+ + missing_country
223
+ + invalid_country_code
224
+ + mappable
225
+ )
226
+
227
  summary = (
228
+ f"Rows scanned: {scanned:,}\n"
229
+ f"- Session starts skipped: {skipped_session_start:,}\n"
230
+ f"- Missing country: {missing_country:,}\n"
231
+ f"- Invalid country code: {invalid_country_code:,}\n"
232
+ f"- Rows mappable: {mappable:,}\n\n"
233
+ f"Accounted rows: {accounted:,} / {scanned:,}\n"
234
+ f"Countries (table): {len(table_df):,}\n"
235
+ f"Countries (map): {len(map_df):,}\n"
236
  f"Total usage events: {int(table_df['usage events'].sum()) if len(table_df) else 0:,}"
237
  )
238