|
|
|
|
|
|
|
|
def score_opportunity(data): |
|
|
|
|
|
stage_weight = { |
|
|
"Prospecting": 10, |
|
|
"Qualified": 20, |
|
|
"Proposal": 30, |
|
|
"Proposal/Price Quote": 35, |
|
|
"Negotiation": 40, |
|
|
"Closed Won": 50, |
|
|
"Closed Lost": 0 |
|
|
} |
|
|
|
|
|
lead_score = data.get("lead_score", 0) |
|
|
email_score = min(10, data.get("emails_last_7_days", 0)) * 2 |
|
|
meeting_score = min(5, data.get("meetings_last_30_days", 0)) * 5 |
|
|
amount_score = min(data.get("amount", 0) / 1000, 25) |
|
|
stage_score = stage_weight.get(data.get("stage"), 0) |
|
|
|
|
|
|
|
|
total_score = lead_score * 0.25 + email_score + meeting_score + amount_score + stage_score |
|
|
total_score = round(min(total_score, 100)) |
|
|
|
|
|
|
|
|
confidence = round( |
|
|
min(1.0, ( |
|
|
(lead_score / 100) * 0.5 + |
|
|
min(1, data.get("emails_last_7_days", 0) / 10) * 0.25 + |
|
|
min(1, data.get("meetings_last_30_days", 0) / 5) * 0.25 |
|
|
)), |
|
|
2 |
|
|
) |
|
|
|
|
|
|
|
|
if total_score >= 80: |
|
|
risk = "Low" |
|
|
recommendation = "🔥 Strong lead. Schedule final meeting or send proposal." |
|
|
elif total_score >= 60: |
|
|
risk = "Medium" |
|
|
recommendation = "🗓️ Schedule another meeting before sending proposal." |
|
|
elif total_score >= 40: |
|
|
risk = "High" |
|
|
recommendation = "📞 Reconnect with lead. Increase engagement." |
|
|
else: |
|
|
risk = "Very High" |
|
|
recommendation = "⚠️ Low potential. Reassess or de-prioritize." |
|
|
|
|
|
return { |
|
|
"score": total_score, |
|
|
"confidence": confidence, |
|
|
"risk": risk, |
|
|
"recommendation": recommendation |
|
|
} |
|
|
|