Repository navigation
Expand file tree
/
Copy pathscoring_engine.py
More file actions
72 lines (55 loc) · 1.95 KB
/
Copy pathscoring_engine.py
File metadata and controls
72 lines (55 loc) · 1.95 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
import json
import math
import sys
from datetime import datetime
def read_payload():
raw = sys.stdin.read().strip()
if not raw:
raise ValueError("Missing scoring payload.")
return json.loads(raw)
def safe_parse_date(value):
if not value:
return None
return datetime.strptime(value, "%Y-%m-%d")
def build_score(payload):
ventes = payload.get("ventes", [])
boutique = payload.get("commercant", {})
count = len(ventes)
volume = sum(float(vente.get("montant", 0) or 0) for vente in ventes)
average = volume / count if count else 0.0
dates = [safe_parse_date(vente.get("date_vente")) for vente in ventes if vente.get("date_vente")]
dates = [date for date in dates if date is not None]
activity_span = max((dates[-1] - dates[0]).days, 0) if len(dates) >= 2 else 0
consistency_bonus = min(10.0, activity_span / 3.0)
article_diversity = len({(vente.get("article") or "").strip().lower() for vente in ventes if vente.get("article")})
diversity_bonus = min(8.0, article_diversity * 1.5)
profile_bonus = 4.0 if len((boutique.get("boutique_info") or "").strip()) >= 40 else 0.0
score = (
38.0
+ min(25.0, count * 3.5)
+ min(18.0, volume / 220.0)
+ min(12.0, average / 90.0)
+ consistency_bonus
+ diversity_bonus
+ profile_bonus
)
score = round(max(0.0, min(96.0, score)), 1)
mention = "Eligible" if score >= 70 else "A consolider"
return {
"score": score,
"mention": mention,
"metrics": {
"sales_count": count,
"volume": round(volume, 2),
"average_ticket": round(average, 2),
"activity_span_days": activity_span,
"article_diversity": article_diversity,
},
}
def main():
payload = read_payload()
result = build_score(payload)
sys.stdout.write(json.dumps(result))
if __name__ == "__main__":
main()