Update model.py
Browse files
model.py
CHANGED
@@ -1,51 +1,53 @@
|
|
1 |
# model.py
|
2 |
|
3 |
def score_opportunity(data):
|
4 |
-
# Stage weights
|
5 |
-
|
6 |
-
"Prospecting":
|
7 |
-
"Qualified":
|
8 |
-
"Proposal
|
9 |
-
"Proposal":
|
10 |
-
"Negotiation":
|
11 |
-
"Closed Won":
|
12 |
-
"Closed Lost": 0
|
13 |
}
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
0.15 * (data.get('amount') or 0) / 10000 +
|
21 |
-
0.2 * stage_weights.get(data.get('stage'), 0)
|
22 |
-
)
|
23 |
|
24 |
-
|
|
|
|
|
25 |
|
26 |
-
# Confidence
|
27 |
confidence = round(
|
28 |
min(1.0, (
|
29 |
-
(
|
30 |
-
min(1, data.get(
|
31 |
-
min(1, data.get(
|
32 |
)),
|
33 |
2
|
34 |
)
|
35 |
|
36 |
-
# Risk and recommendation
|
37 |
-
if
|
38 |
risk = "Low"
|
39 |
-
recommendation = "🔥 Strong lead.
|
40 |
-
elif
|
41 |
risk = "Medium"
|
42 |
recommendation = "🗓️ Schedule another meeting before sending proposal."
|
43 |
-
|
44 |
risk = "High"
|
|
|
|
|
|
|
45 |
recommendation = "⚠️ Low potential. Reassess or de-prioritize."
|
46 |
|
47 |
return {
|
48 |
-
"score":
|
49 |
"confidence": confidence,
|
50 |
"risk": risk,
|
51 |
"recommendation": recommendation
|
|
|
1 |
# model.py
|
2 |
|
3 |
def score_opportunity(data):
|
4 |
+
# Stage weights for scoring
|
5 |
+
stage_weight = {
|
6 |
+
"Prospecting": 10,
|
7 |
+
"Qualified": 20,
|
8 |
+
"Proposal": 30,
|
9 |
+
"Proposal/Price Quote": 35,
|
10 |
+
"Negotiation": 40,
|
11 |
+
"Closed Won": 50,
|
12 |
+
"Closed Lost": 0
|
13 |
}
|
14 |
|
15 |
+
lead_score = data.get("lead_score", 0)
|
16 |
+
email_score = min(10, data.get("emails_last_7_days", 0)) * 2 # up to 20
|
17 |
+
meeting_score = min(5, data.get("meetings_last_30_days", 0)) * 5 # up to 25
|
18 |
+
amount_score = min(data.get("amount", 0) / 1000, 25) # up to 25
|
19 |
+
stage_score = stage_weight.get(data.get("stage"), 0)
|
|
|
|
|
|
|
20 |
|
21 |
+
# Total Score Calculation
|
22 |
+
total_score = lead_score * 0.25 + email_score + meeting_score + amount_score + stage_score
|
23 |
+
total_score = round(min(total_score, 100))
|
24 |
|
25 |
+
# Confidence (0.0 to 1.0)
|
26 |
confidence = round(
|
27 |
min(1.0, (
|
28 |
+
(lead_score / 100) * 0.5 +
|
29 |
+
min(1, data.get("emails_last_7_days", 0) / 10) * 0.25 +
|
30 |
+
min(1, data.get("meetings_last_30_days", 0) / 5) * 0.25
|
31 |
)),
|
32 |
2
|
33 |
)
|
34 |
|
35 |
+
# Risk level and AI recommendation
|
36 |
+
if total_score >= 80:
|
37 |
risk = "Low"
|
38 |
+
recommendation = "🔥 Strong lead. Schedule final meeting or send proposal."
|
39 |
+
elif total_score >= 60:
|
40 |
risk = "Medium"
|
41 |
recommendation = "🗓️ Schedule another meeting before sending proposal."
|
42 |
+
elif total_score >= 40:
|
43 |
risk = "High"
|
44 |
+
recommendation = "📞 Reconnect with lead. Increase engagement."
|
45 |
+
else:
|
46 |
+
risk = "Very High"
|
47 |
recommendation = "⚠️ Low potential. Reassess or de-prioritize."
|
48 |
|
49 |
return {
|
50 |
+
"score": total_score,
|
51 |
"confidence": confidence,
|
52 |
"risk": risk,
|
53 |
"recommendation": recommendation
|