Sanjayraju30 commited on
Commit
21c0a92
·
verified ·
1 Parent(s): d2fb148

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +36 -17
model.py CHANGED
@@ -1,33 +1,52 @@
1
  # model.py
2
 
3
  def score_opportunity(data):
4
- # Weighted score calculation
5
- raw_score = (
6
- 0.3 * (data['lead_score'] or 0) +
7
- 0.2 * (data['email_count'] or 0) +
8
- 0.2 * (data['meeting_count'] or 0) -
9
- 0.1 * (data['close_date_gap'] or 0)
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
- # Extra points if at negotiation stage
12
- if data['stage'] == "Negotiation":
13
- raw_score += 10
14
 
15
- # Clip score between 0–100
16
- raw_score = max(0, min(100, round(raw_score)))
 
 
 
 
 
 
 
 
 
17
 
18
- # Risk classification logic
19
- if raw_score >= 75:
20
  risk = "Low"
21
- recommendation = " High chance of closing. Prioritize this deal."
22
- elif raw_score >= 50:
23
  risk = "Medium"
24
- recommendation = "🔁 Moderate potential. Consider a follow-up soon."
25
  else:
26
  risk = "High"
27
  recommendation = "⚠️ Low potential. Reassess or de-prioritize."
28
 
29
  return {
30
- "score": raw_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
  }