-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoring.py
More file actions
56 lines (47 loc) · 1.35 KB
/
scoring.py
File metadata and controls
56 lines (47 loc) · 1.35 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
"""Deterministic scoring for Stack Engine recommendations."""
from __future__ import annotations
WEIGHTS = {
"impact": 0.35,
"reliability": 0.25,
"fit": 0.25,
"complexity": -0.10,
"cost": -0.05,
}
def calculate_score(
impact: int,
reliability: int,
fit: int,
complexity: int,
cost: int,
) -> float:
"""Return the weighted build score rounded to two decimals."""
raw_score = (
impact * WEIGHTS["impact"]
+ reliability * WEIGHTS["reliability"]
+ fit * WEIGHTS["fit"]
+ complexity * WEIGHTS["complexity"]
+ cost * WEIGHTS["cost"]
)
return round(raw_score, 2)
def verdict_for_score(score: float) -> str:
"""Map deterministic score to a build verdict."""
if score >= 3.50:
return "BUILD NOW"
if score >= 2.75:
return "MANUAL FIRST"
if score >= 2.00:
return "BUILD LATER"
return "DO NOT BUILD"
def score_payload(scorecard: dict) -> dict:
"""Add score and verdict to an input scorecard dictionary."""
scored = dict(scorecard)
overall = calculate_score(
impact=scored["impact"],
reliability=scored["reliability"],
fit=scored["fit"],
complexity=scored["complexity"],
cost=scored["cost"],
)
scored["overall"] = overall
scored["verdict"] = verdict_for_score(overall)
return scored