Spaces:
Running
Running
File size: 1,134 Bytes
f41fb66 d32f83a f41fb66 d32f83a f41fb66 d32f83a f41fb66 f230cf2 d32f83a f230cf2 d32f83a f230cf2 f41fb66 f230cf2 d32f83a f230cf2 d32f83a f230cf2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import pandas as pd
from database import get_all_leads, init_db
def get_analytics():
"""
Reads data from the SQLite database for the dashboard.
Returns:
A tuple of (DataFrame, dict) containing the data and statistics.
"""
# Ensure the database is initialized
init_db()
try:
df = get_all_leads()
if df is None or df.empty:
return None, None
stats = {
"total": len(df),
"success_rate": 0,
}
if "Outcome" in df.columns and not df.empty:
# Filter out non-success/fail outcomes for accurate rate calculation
relevant_outcomes = df[df["Outcome"].isin(["Success", "Fail"])]
if not relevant_outcomes.empty:
success_count = len(relevant_outcomes[relevant_outcomes["Outcome"] == "Success"])
stats["success_rate"] = round(success_count / len(relevant_outcomes) * 100, 1)
return df, stats
except Exception as e:
print(f"Error getting analytics from database: {e}")
return None, None
|