-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoring.py
More file actions
77 lines (61 loc) · 2.21 KB
/
Copy pathscoring.py
File metadata and controls
77 lines (61 loc) · 2.21 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
73
74
75
76
77
from datetime import date
from typing import List, Dict
from .models import Task, ProfileConfig, ScoredTask
def _normalize(value: float, min_value: float, max_value: float) -> float:
if max_value == min_value:
return 0.0
value = max(min_value, min(max_value, value))
return (value - min_value) / (max_value - min_value)
def _stress_penalty(stress_impact: str) -> float:
mapping = {
"LOW": 0.0,
"MEDIUM": 0.1,
"HIGH": 0.25,
}
return mapping.get(stress_impact.upper(), 0.1)
def score_tasks(tasks: List[Task], profile: ProfileConfig) -> List[ScoredTask]:
"""Score tasks for a given profile.
This is a simple, transparent scoring model meant as a solid starting point.
"""
weights: Dict[str, float] = {
"importance": 0.4,
"urgency": 0.3,
"effort": 0.2,
"deadline": 0.1,
}
weights.update(profile.weights or {})
today = date.today()
scored: List[ScoredTask] = []
for task in tasks:
importance_n = _normalize(task.importance, 1, 5)
urgency_n = _normalize(task.urgency, 1, 5)
effort_n = 1.0 - _normalize(task.effort_estimate, 0.25, 8.0)
if task.due_date:
days_to_due = (task.due_date - today).days
if days_to_due <= 0:
deadline_n = 1.0
elif days_to_due >= 14:
deadline_n = 0.0
else:
deadline_n = 1.0 - (days_to_due / 14.0)
else:
deadline_n = 0.0
base_score = (
weights["importance"] * importance_n
+ weights["urgency"] * urgency_n
+ weights["effort"] * effort_n
+ weights["deadline"] * deadline_n
)
penalty = _stress_penalty(task.stress_impact)
final_score = max(0.0, base_score - penalty)
breakdown = {
"importance_n": importance_n,
"urgency_n": urgency_n,
"effort_n": effort_n,
"deadline_n": deadline_n,
"stress_penalty": penalty,
"base_score": base_score,
}
scored.append(ScoredTask(task=task, score=final_score, breakdown=breakdown))
scored.sort(key=lambda st: st.score, reverse=True)
return scored