SuhasGholkar commited on
Commit
78addfa
·
verified ·
1 Parent(s): f7492ee

Update src/mis.py

Browse files
Files changed (1) hide show
  1. src/mis.py +12 -2
src/mis.py CHANGED
@@ -274,6 +274,15 @@ def _apply_filters_base_query_user(
274
  where.append(f"ch.intent IN ({q})"); params.extend(chosen_intents)
275
  return " WHERE " + " AND ".join(where) + " ", params
276
 
 
 
 
 
 
 
 
 
 
277
  def _plot_resolution_rate_by_day(df, height_in=2.5):
278
  """
279
  Plot daily resolution rate = (# resolved / total) per day.
@@ -408,8 +417,9 @@ def render_mis_user(conn, user_id: int):
408
 
409
  # D) Resolution by day (industry-favorite view)
410
  with cD:
411
- st.markdown('<div class="mini-chart"><b>My resolution rate by day</b></div>', unsafe_allow_html=True)
412
- _plot_resolution_rate_by_day(df, height_in=2.0)
 
413
 
414
  # ---------- Filtered table (username, not ID) ----------
415
  with st.expander("My filtered chats (first 50)", expanded=False):
 
274
  where.append(f"ch.intent IN ({q})"); params.extend(chosen_intents)
275
  return " WHERE " + " AND ".join(where) + " ", params
276
 
277
+ def kpi_avg_delivery_days(conn: sqlite3.Connection):
278
+ avg_days = _one_val("""
279
+ SELECT AVG(julianday(order_delivered_customer_date) - julianday(order_purchase_timestamp))
280
+ FROM orders
281
+ WHERE order_delivered_customer_date IS NOT NULL
282
+ AND order_purchase_timestamp >= date('now','-30 day')
283
+ """, conn)
284
+ st.metric("Avg delivery time (30d)", f"{(avg_days or 0):.2f} days")
285
+
286
  def _plot_resolution_rate_by_day(df, height_in=2.5):
287
  """
288
  Plot daily resolution rate = (# resolved / total) per day.
 
417
 
418
  # D) Resolution by day (industry-favorite view)
419
  with cD:
420
+ st.markdown('<div class="mini-chart"><b>Average Delivery Time in Days (Last 30 days)</b></div>', unsafe_allow_html=True)
421
+ #_plot_resolution_rate_by_day(df, height_in=2.0)
422
+ kpi_avg_delivery_days(conn)
423
 
424
  # ---------- Filtered table (username, not ID) ----------
425
  with st.expander("My filtered chats (first 50)", expanded=False):