CCockrum commited on
Commit
3e7988d
Β·
verified Β·
1 Parent(s): 8d3265d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -217,22 +217,34 @@ if fetch_data:
217
  def is_incomplete(value):
218
  return pd.isna(value) or value in ["", "N/A", "null", None]
219
 
220
- # New way to calculate incomplete record mask
221
- incomplete_mask = metadata_df.apply(lambda row: row.map(is_incomplete), axis=1).any(axis=1)
222
- incomplete_count = incomplete_mask.sum()
223
-
224
- # Display Quick Stats right after dropdown
225
  if not metadata_df.empty:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
  stats_html = f"""
227
  <div class="sidebar-stats">
228
  <h3 style="color: lightgray;">πŸ“Š Quick Stats</h3>
229
  <p style="color:lightgray;">Total Records: <b>{len(metadata_df)}</b></p>
230
  <p style="color:lightgray;">Incomplete Records: <b>{incomplete_count}</b></p>
 
231
  </div>
232
  """
233
  stats_placeholder.markdown(stats_html, unsafe_allow_html=True)
234
-
235
-
 
 
236
 
237
  # Utility functions for deeper metadata quality analysis
238
  def is_incomplete(value):
 
217
  def is_incomplete(value):
218
  return pd.isna(value) or value in ["", "N/A", "null", None]
219
 
 
 
 
 
 
220
  if not metadata_df.empty:
221
+ # Incomplete record detection
222
+ incomplete_mask = metadata_df.apply(lambda row: row.map(is_incomplete), axis=1).any(axis=1)
223
+ incomplete_count = incomplete_mask.sum()
224
+
225
+ # Overall completeness
226
+ total_fields = metadata_df.size
227
+ filled_fields = metadata_df.apply(lambda row: row.map(lambda x: not is_incomplete(x)), axis=1).sum().sum()
228
+ overall_percent = (filled_fields / total_fields) * 100
229
+
230
+ # Field-by-field completeness
231
+ completeness = metadata_df.applymap(lambda x: not is_incomplete(x)).mean() * 100
232
+ completeness_table = completeness.round(1).to_frame(name="Completeness (%)")
233
+
234
+ # Render stats summary in sidebar
235
  stats_html = f"""
236
  <div class="sidebar-stats">
237
  <h3 style="color: lightgray;">πŸ“Š Quick Stats</h3>
238
  <p style="color:lightgray;">Total Records: <b>{len(metadata_df)}</b></p>
239
  <p style="color:lightgray;">Incomplete Records: <b>{incomplete_count}</b></p>
240
+ <p style="color:lightgray;">Overall Metadata Completeness: <b>{overall_percent:.1f}%</b></p>
241
  </div>
242
  """
243
  stats_placeholder.markdown(stats_html, unsafe_allow_html=True)
244
+
245
+ # Render field-level completeness table in sidebar
246
+ with st.sidebar.expander("πŸ§ͺ Field Completeness Breakdown", expanded=False):
247
+ st.dataframe(completeness_table.style.background_gradient(cmap="Greens").format("{:.1f}%"))
248
 
249
  # Utility functions for deeper metadata quality analysis
250
  def is_incomplete(value):