Sanjayraju30 commited on
Commit
6f63a9a
·
verified ·
1 Parent(s): 2a09313

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +23 -46
model.py CHANGED
@@ -1,54 +1,31 @@
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
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
  }