File size: 3,180 Bytes
687bd84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
from pydantic import BaseModel, Field, validator
from typing import Dict, List

class TaskAssignment(BaseModel):
    developer_id: int = Field(..., ge=1, description="Developer ID")
    current_task_count: int = Field(..., ge=0, le=15)
    avg_completion_time_days: float = Field(..., ge=1.0, le=30.0)
    skill_match_score: int = Field(..., ge=0, le=100)
    total_story_points_assigned: int = Field(..., ge=0, le=50)
    recent_overtime_hours: int = Field(..., ge=0, le=25)
    task_switch_frequency: float = Field(..., ge=0.0, le=10.0)
    pr_review_pending: int = Field(..., ge=0, le=20)
    priority: int = Field(..., ge=0, le=3)
    estimated_story_points: int = Field(...)
    days_until_deadline: int = Field(..., ge=1, le=30)
    required_skill: str = Field(...)
    has_dependencies: int = Field(..., ge=0, le=1)
    task_type: int = Field(..., ge=0, le=2)
    team_size: int = Field(..., ge=5, le=20)
    sprint_days_remaining: int = Field(..., ge=1, le=14)
    team_avg_velocity: int = Field(..., ge=20, le=100)
    
    @validator('estimated_story_points')
    def validate_fibonacci(cls, v):
        allowed = [1, 2, 3, 5, 8, 13]
        if v not in allowed:
            raise ValueError(f'Story points must be one of {allowed}')
        return v
    
    @validator('required_skill')
    def validate_skill(cls, v):
        allowed = ['frontend', 'backend', 'devops', 'ml', 'testing']
        if v not in allowed:
            raise ValueError(f'Skill must be one of {allowed}')
        return v
    
    class Config:
        schema_extra = {
            "example": {
                "developer_id": 5,
                "current_task_count": 6,
                "avg_completion_time_days": 5.5,
                "skill_match_score": 85,
                "total_story_points_assigned": 21,
                "recent_overtime_hours": 8,
                "task_switch_frequency": 4.2,
                "pr_review_pending": 3,
                "priority": 1,
                "estimated_story_points": 5,
                "days_until_deadline": 7,
                "required_skill": "backend",
                "has_dependencies": 0,
                "task_type": 0,
                "team_size": 10,
                "sprint_days_remaining": 8,
                "team_avg_velocity": 55
            }
        }


class PredictionResponse(BaseModel):
    developer_id: int
    overload_risk: int
    risk_label: str
    confidence: float
    risk_probabilities: Dict[str, float]
    contributing_factors: List[str]
    recommendation: str
    
    class Config:
        schema_extra = {
            "example": {
                "developer_id": 5,
                "overload_risk": 1,
                "risk_label": "Yellow (Moderate)",
                "confidence": 0.68,
                "risk_probabilities": {
                    "green": 0.25,
                    "yellow": 0.68,
                    "red": 0.07
                },
                "contributing_factors": [
                    "High task count (6)",
                    "Recent overtime (8h)"
                ],
                "recommendation": "Proceed with caution. Monitor workload closely."
            }
        }