Update model.py
Browse files
model.py
CHANGED
@@ -1,54 +1,31 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
def score_opportunity(data):
|
4 |
-
#
|
5 |
-
|
6 |
-
"
|
7 |
-
"
|
8 |
-
"
|
9 |
-
|
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 |
-
#
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
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 |
-
|
36 |
-
if
|
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":
|
51 |
-
"confidence": confidence
|
52 |
-
"risk": risk,
|
53 |
-
"recommendation": recommendation
|
54 |
}
|
|
|
1 |
+
import random
|
2 |
+
from datetime import datetime
|
3 |
|
4 |
def score_opportunity(data):
|
5 |
+
# Simple scoring logic (replace with ML model in real app)
|
6 |
+
score = (
|
7 |
+
data["lead_score"] * 0.5 +
|
8 |
+
data["emails_last_7_days"] * 3 +
|
9 |
+
data["meetings_last_30_days"] * 5
|
10 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Reduce score for long closing gap
|
13 |
+
today = datetime.today()
|
14 |
+
try:
|
15 |
+
close_date = datetime.strptime(data["close_date"], "%Y-%m-%d")
|
16 |
+
days_to_close = (close_date - today).days
|
17 |
+
except:
|
18 |
+
days_to_close = 30
|
19 |
|
20 |
+
if days_to_close > 30:
|
21 |
+
score -= 10
|
22 |
+
elif days_to_close < 5:
|
23 |
+
score += 5
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
score = max(0, min(100, round(score)))
|
26 |
+
confidence = round(random.uniform(0.7, 0.95) if score >= 60 else random.uniform(0.4, 0.7), 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
return {
|
29 |
+
"score": score,
|
30 |
+
"confidence": confidence
|
|
|
|
|
31 |
}
|