19arjun89 commited on
Commit
0d143ed
·
verified ·
1 Parent(s): 596b6ec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -109,16 +109,19 @@ def build_report():
109
  missing_country += 1
110
  continue
111
 
 
 
 
112
  iso3 = iso2_to_iso3(row.get("final_country_code"))
113
  if not iso3:
114
  invalid_country_code += 1
115
  continue
116
-
117
- # Count it
118
- country_counts[country] += 1
119
  iso3_counts[iso3] += 1
120
  iso3_to_name.setdefault(iso3, country)
121
 
 
122
  # Build table dataframe
123
  table_df = (
124
  pd.DataFrame([{"country": k, "usage events": v} for k, v in country_counts.items()])
@@ -144,6 +147,7 @@ def build_report():
144
  # Reconciliation
145
  rows_mappable = int(map_df["usage events"].sum()) # note: this is TOTAL events, not rows
146
  mappable_rows_count = int(sum(iso3_counts.values())) # count of rows after filters (events counted)
 
147
  accounted = skipped_session_start + missing_country + invalid_country_code + mappable_rows_count
148
 
149
  # If you want “Rows mappable” to mean “rows that made it to map”, use mappable_rows_count
@@ -155,6 +159,8 @@ def build_report():
155
  fig.update_layout(height=740, margin=dict(l=0, r=0, t=40, b=0))
156
  summary = (
157
  f"Rows scanned: {scanned:,}\n"
 
 
158
  f"- Session starts skipped: {skipped_session_start:,}\n"
159
  f"- Missing country: {missing_country:,}\n"
160
  f"- Invalid country code: {invalid_country_code:,}\n\n"
 
109
  missing_country += 1
110
  continue
111
 
112
+ # Count it for the table FIRST (all usage events with a valid country name)
113
+ country_counts[country] += 1
114
+
115
  iso3 = iso2_to_iso3(row.get("final_country_code"))
116
  if not iso3:
117
  invalid_country_code += 1
118
  continue
119
+
120
+ # Count it for the map only (requires ISO3)
 
121
  iso3_counts[iso3] += 1
122
  iso3_to_name.setdefault(iso3, country)
123
 
124
+
125
  # Build table dataframe
126
  table_df = (
127
  pd.DataFrame([{"country": k, "usage events": v} for k, v in country_counts.items()])
 
147
  # Reconciliation
148
  rows_mappable = int(map_df["usage events"].sum()) # note: this is TOTAL events, not rows
149
  mappable_rows_count = int(sum(iso3_counts.values())) # count of rows after filters (events counted)
150
+ table_rows_counted = int(sum(country_counts.values()))
151
  accounted = skipped_session_start + missing_country + invalid_country_code + mappable_rows_count
152
 
153
  # If you want “Rows mappable” to mean “rows that made it to map”, use mappable_rows_count
 
159
  fig.update_layout(height=740, margin=dict(l=0, r=0, t=40, b=0))
160
  summary = (
161
  f"Rows scanned: {scanned:,}\n"
162
+ f"- Rows counted in table: {table_rows_counted:,}\n"
163
+ f"- Rows mapped: {mappable_rows_count:,}\n"
164
  f"- Session starts skipped: {skipped_session_start:,}\n"
165
  f"- Missing country: {missing_country:,}\n"
166
  f"- Invalid country code: {invalid_country_code:,}\n\n"