File size: 1,481 Bytes
4f47b69
 
579b95c
21c0a92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579b95c
4f47b69
21c0a92
 
 
 
 
 
 
 
 
 
 
579b95c
21c0a92
 
579b95c
21c0a92
 
579b95c
21c0a92
579b95c
 
4f47b69
579b95c
 
21c0a92
 
579b95c
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# model.py

def score_opportunity(data):
    # Stage weights
    stage_weights = {
        "Prospecting": 0.1,
        "Qualified": 0.2,
        "Proposal/Price Quote": 0.3,
        "Proposal": 0.3,
        "Negotiation": 0.4,
        "Closed Won": 0.5,
        "Closed Lost": 0.0
    }

    # Base scoring formula
    score = (
        0.25 * (data.get('lead_score') or 0) +
        0.2 * (data.get('emails_last_7_days') or 0) * 5 +
        0.2 * (data.get('meetings_last_30_days') or 0) * 10 +
        0.15 * (data.get('amount') or 0) / 10000 +
        0.2 * stage_weights.get(data.get('stage'), 0)
    )

    score = min(100, round(score))

    # Confidence score between 0 and 1
    confidence = round(
        min(1.0, (
            (data.get('lead_score') or 0) / 100 * 0.5 +
            min(1, data.get('emails_last_7_days', 0) / 10) * 0.25 +
            min(1, data.get('meetings_last_30_days', 0) / 5) * 0.25
        )),
        2
    )

    # Risk and recommendation
    if score >= 80:
        risk = "Low"
        recommendation = "🔥 Strong lead. Proceed with final proposal or close."
    elif score >= 60:
        risk = "Medium"
        recommendation = "🗓️ Schedule another meeting before sending proposal."
    else:
        risk = "High"
        recommendation = "⚠️ Low potential. Reassess or de-prioritize."

    return {
        "score": score,
        "confidence": confidence,
        "risk": risk,
        "recommendation": recommendation
    }