File size: 5,685 Bytes
c2cb41b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
from pydantic import BaseModel, Field
from typing import List, Optional, Dict
from datetime import datetime, date


class DeliveryHealthMetrics(BaseModel):
    """Metrics for delivery health analysis"""
    sprint_id: Optional[str] = None
    sprint_name: Optional[str] = None
    period_start: date
    period_end: date
    
    # Velocity Metrics
    planned_story_points: float = 0
    completed_story_points: float = 0
    velocity: float = 0
    velocity_trend: float = 0  # percentage change from previous period
    
    # Completion Metrics
    total_issues: int = 0
    completed_issues: int = 0
    completion_rate: float = 0
    
    # Time Metrics
    avg_cycle_time_hours: float = 0
    avg_lead_time_hours: float = 0
    
    # Quality Indicators
    blocked_issues_count: int = 0
    overdue_issues_count: int = 0
    reopened_issues_count: int = 0
    
    # Risk Indicators
    at_risk_issues: int = 0
    health_score: float = 0  # 0-100


class ProductivityMetrics(BaseModel):
    """Workforce productivity metrics"""
    team_member_id: str
    team_member_name: str
    period_start: date
    period_end: date
    
    # Activity Metrics
    issues_completed: int = 0
    story_points_completed: float = 0
    code_commits: int = 0  # from GitHub
    pull_requests: int = 0  # from GitHub
    
    # Time Metrics
    total_hours_logged: float = 0
    avg_hours_per_day: float = 0
    
    # Efficiency Metrics
    avg_issue_completion_time_hours: float = 0
    productivity_score: float = 0  # 0-100
    
    # Workload Metrics
    current_assigned_issues: int = 0
    current_story_points: float = 0
    utilization_rate: float = 0  # percentage


class CostEfficiencyMetrics(BaseModel):
    """Cost and efficiency analysis"""
    period_start: date
    period_end: date
    project_key: Optional[str] = None
    
    # Resource Metrics
    total_team_members: int = 0
    total_hours_logged: float = 0
    estimated_cost: float = 0  # based on hours
    
    # Output Metrics
    features_delivered: int = 0
    story_points_delivered: float = 0
    
    # Efficiency Ratios
    cost_per_feature: float = 0
    cost_per_story_point: float = 0
    hours_per_story_point: float = 0
    
    # Waste Indicators
    blocked_time_hours: float = 0
    rework_hours: float = 0
    waste_percentage: float = 0


class TeamCapacityMetrics(BaseModel):
    """Team capacity and utilization"""
    team_id: Optional[str] = None
    team_name: str
    period_start: date
    period_end: date
    
    # Capacity Metrics
    total_capacity_hours: float = 0
    allocated_hours: float = 0
    available_hours: float = 0
    utilization_rate: float = 0
    
    # Workload Distribution
    team_members: List[Dict] = Field(default_factory=list)
    overloaded_members: int = 0
    underutilized_members: int = 0
    
    # Sprint Metrics
    current_sprint_load: float = 0
    forecasted_capacity: float = 0


class RiskAlert(BaseModel):
    """Risk and alert model"""
    alert_id: str
    alert_type: str  # delivery_delay, cost_overrun, resource_shortage, quality_issue
    severity: str  # critical, high, medium, low
    title: str
    description: str
    affected_entity: str  # sprint, project, team_member
    entity_id: str
    detected_at: datetime
    suggested_action: Optional[str] = None
    metrics: Dict = Field(default_factory=dict)


class InsightRecommendation(BaseModel):
    """AI-generated insights and recommendations"""
    insight_id: str
    category: str  # delivery, productivity, cost, resource
    title: str
    description: str
    confidence_score: float = 0  # 0-1
    impact_level: str  # high, medium, low
    recommendations: List[str] = Field(default_factory=list)
    supporting_data: Dict = Field(default_factory=dict)
    generated_at: datetime


class KanbanFlowMetrics(BaseModel):
    """Kanban flow efficiency metrics"""
    board_id: int
    board_name: str
    period_start: date
    period_end: date
    
    # Flow Metrics
    throughput: int = 0  # Issues completed in period
    avg_cycle_time_days: float = 0
    avg_lead_time_days: float = 0
    flow_efficiency: float = 0  # 0-100
    
    # WIP Metrics
    current_wip: int = 0
    avg_wip: float = 0
    wip_violations: int = 0  # Number of times WIP limits were exceeded
    
    # Column Metrics
    bottleneck_column: Optional[str] = None
    bottleneck_score: float = 0
    
    # Predictability
    throughput_variance: float = 0
    cycle_time_variance: float = 0
    
    # Health Score
    flow_health_score: float = 0  # 0-100


class KanbanColumnAnalysis(BaseModel):
    """Analysis for a specific Kanban column"""
    column_name: str
    statuses: List[str]
    
    # Current State
    current_issue_count: int = 0
    wip_limit_min: Optional[int] = None
    wip_limit_max: Optional[int] = None
    is_over_wip_limit: bool = False
    
    # Flow Metrics
    avg_time_in_column_days: float = 0
    throughput: int = 0  # Issues exited this column
    
    # Efficiency
    utilization_rate: float = 0  # current / max limit
    is_bottleneck: bool = False
    bottleneck_score: float = 0  # Higher = more of a bottleneck


class KanbanCumulativeFlow(BaseModel):
    """Cumulative flow diagram data"""
    board_id: int
    period_start: date
    period_end: date
    
    # Daily snapshots
    data_points: List[Dict] = Field(default_factory=list)
    # Each data point: {date, column_name, issue_count}


class WIPLimitRecommendation(BaseModel):
    """WIP limit optimization recommendations"""
    column_name: str
    current_limit: Optional[int]
    recommended_min: int
    recommended_max: int
    reasoning: str
    confidence_score: float = 0  # 0-1