Update model.py
Browse files
model.py
CHANGED
|
@@ -1,33 +1,52 @@
|
|
| 1 |
# model.py
|
| 2 |
|
| 3 |
def score_opportunity(data):
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
0.
|
| 7 |
-
0.2
|
| 8 |
-
|
| 9 |
-
0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
)
|
| 11 |
-
# Extra points if at negotiation stage
|
| 12 |
-
if data['stage'] == "Negotiation":
|
| 13 |
-
raw_score += 10
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
# Risk
|
| 19 |
-
if
|
| 20 |
risk = "Low"
|
| 21 |
-
recommendation = "
|
| 22 |
-
elif
|
| 23 |
risk = "Medium"
|
| 24 |
-
recommendation = "
|
| 25 |
else:
|
| 26 |
risk = "High"
|
| 27 |
recommendation = "⚠️ Low potential. Reassess or de-prioritize."
|
| 28 |
|
| 29 |
return {
|
| 30 |
-
"score":
|
|
|
|
| 31 |
"risk": risk,
|
| 32 |
"recommendation": recommendation
|
| 33 |
}
|
|
|
|
| 1 |
# model.py
|
| 2 |
|
| 3 |
def score_opportunity(data):
|
| 4 |
+
# Stage weights
|
| 5 |
+
stage_weights = {
|
| 6 |
+
"Prospecting": 0.1,
|
| 7 |
+
"Qualified": 0.2,
|
| 8 |
+
"Proposal/Price Quote": 0.3,
|
| 9 |
+
"Proposal": 0.3,
|
| 10 |
+
"Negotiation": 0.4,
|
| 11 |
+
"Closed Won": 0.5,
|
| 12 |
+
"Closed Lost": 0.0
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
# Base scoring formula
|
| 16 |
+
score = (
|
| 17 |
+
0.25 * (data.get('lead_score') or 0) +
|
| 18 |
+
0.2 * (data.get('emails_last_7_days') or 0) * 5 +
|
| 19 |
+
0.2 * (data.get('meetings_last_30_days') or 0) * 10 +
|
| 20 |
+
0.15 * (data.get('amount') or 0) / 10000 +
|
| 21 |
+
0.2 * stage_weights.get(data.get('stage'), 0)
|
| 22 |
)
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
score = min(100, round(score))
|
| 25 |
+
|
| 26 |
+
# Confidence score between 0 and 1
|
| 27 |
+
confidence = round(
|
| 28 |
+
min(1.0, (
|
| 29 |
+
(data.get('lead_score') or 0) / 100 * 0.5 +
|
| 30 |
+
min(1, data.get('emails_last_7_days', 0) / 10) * 0.25 +
|
| 31 |
+
min(1, data.get('meetings_last_30_days', 0) / 5) * 0.25
|
| 32 |
+
)),
|
| 33 |
+
2
|
| 34 |
+
)
|
| 35 |
|
| 36 |
+
# Risk and recommendation
|
| 37 |
+
if score >= 80:
|
| 38 |
risk = "Low"
|
| 39 |
+
recommendation = "🔥 Strong lead. Proceed with final proposal or close."
|
| 40 |
+
elif score >= 60:
|
| 41 |
risk = "Medium"
|
| 42 |
+
recommendation = "🗓️ Schedule another meeting before sending proposal."
|
| 43 |
else:
|
| 44 |
risk = "High"
|
| 45 |
recommendation = "⚠️ Low potential. Reassess or de-prioritize."
|
| 46 |
|
| 47 |
return {
|
| 48 |
+
"score": score,
|
| 49 |
+
"confidence": confidence,
|
| 50 |
"risk": risk,
|
| 51 |
"recommendation": recommendation
|
| 52 |
}
|