Sanjayraju30 commited on
Commit
449011e
·
verified ·
1 Parent(s): 51983a1

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +30 -28
model.py CHANGED
@@ -1,51 +1,53 @@
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
 
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