|
|
|
|
|
def score_opportunity(data): |
|
|
|
stage_weights = { |
|
"Prospecting": 0.1, |
|
"Qualified": 0.2, |
|
"Proposal/Price Quote": 0.3, |
|
"Proposal": 0.3, |
|
"Negotiation": 0.4, |
|
"Closed Won": 0.5, |
|
"Closed Lost": 0.0 |
|
} |
|
|
|
|
|
score = ( |
|
0.25 * (data.get('lead_score') or 0) + |
|
0.2 * (data.get('emails_last_7_days') or 0) * 5 + |
|
0.2 * (data.get('meetings_last_30_days') or 0) * 10 + |
|
0.15 * (data.get('amount') or 0) / 10000 + |
|
0.2 * stage_weights.get(data.get('stage'), 0) |
|
) |
|
|
|
score = min(100, round(score)) |
|
|
|
|
|
confidence = round( |
|
min(1.0, ( |
|
(data.get('lead_score') or 0) / 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 score >= 80: |
|
risk = "Low" |
|
recommendation = "🔥 Strong lead. Proceed with final proposal or close." |
|
elif score >= 60: |
|
risk = "Medium" |
|
recommendation = "🗓️ Schedule another meeting before sending proposal." |
|
else: |
|
risk = "High" |
|
recommendation = "⚠️ Low potential. Reassess or de-prioritize." |
|
|
|
return { |
|
"score": score, |
|
"confidence": confidence, |
|
"risk": risk, |
|
"recommendation": recommendation |
|
} |
|
|