Commit c64cb7e
## Summary
Implements comprehensive F-score tracking and analytics system as
requested in issue #91. This PR introduces dedicated F-score calculation
and tracking infrastructure for precision/recall metrics targeting
manager/executive use cases in MVP Phase 4.
### Key Features
- **Type-Safe F-score Domain Types**: Created validated newtypes using
`nutype` for `FScore`, `Precision`, `Recall`, `Beta`, and
`ConfidenceLevel` with proper validation ranges
- **F-score Calculation Engine**: Implements harmonic mean calculation
with support for configurable beta values (F1, F2, F-beta scores)
- **EventCore Integration**: Multi-stream event sourcing with
`RecordModelFScore` and `RecordApplicationFScore` commands
- **Time-Series Tracking**: `FScoreDataPoint` infrastructure for
tracking F-score trends over time with confidence intervals
- **Demo Data Generation**: Comprehensive demo data generator for MVP
visualization with realistic time-series data
- **Comprehensive Test Coverage**: 14 new passing tests covering domain
logic, EventCore integration, and edge cases
### Technical Implementation
- **Domain Types**: All F-score types include validation ensuring values
are finite and within valid ranges (0.0-1.0)
- **Event Sourcing**: Commands emit `FScoreCalculated` and
`ApplicationFScoreCalculated` events to appropriate streams
- **State Management**: `MetricsState` tracks F-score history for both
model versions and applications
- **Demo Data**: Includes provider comparison data, application-specific
trends, and performance categorization
### Recent Refactoring (per PR review)
Based on comprehensive type-driven development review:
1. **Eliminated Primitive Obsession**:
- Extracted stream ID prefix constants to remove string literals
- Created `PerformanceCategory` domain type replacing raw strings in
demo data
- Replaced magic numbers in tests with test_data constants
2. **Reduced Code Duplication**:
- Introduced `FScoreCommand` trait to share common logic between
`RecordModelFScore` and `RecordApplicationFScore`
- Consolidated F-score calculation logic
3. **Improved Type Safety**:
- Fixed string `contains()` usage on `ApplicationId` with proper
equality checks
- Enhanced readability and maintainability throughout metrics module
### Testing
All 289 tests pass including:
- F-score calculation accuracy with harmonic mean formula
- EventCore command execution and event emission
- Domain type validation and edge cases
- Demo data generation with realistic patterns
Closes #91
🤖 Generated with [Claude Code](https://claude.ai/code)
---------
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 36e46ec commit c64cb7e
File tree
23 files changed
+5288
-22
lines changed- src/domain
- commands
- metrics
23 files changed
+5288
-22
lines changedLarge diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
| 6 | + | |
5 | 7 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
109 | | - | |
| 110 | + | |
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| |||
119 | 120 | | |
120 | 121 | | |
121 | 122 | | |
122 | | - | |
| 123 | + | |
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| |||
191 | 192 | | |
192 | 193 | | |
193 | 194 | | |
194 | | - | |
| 195 | + | |
195 | 196 | | |
196 | 197 | | |
197 | 198 | | |
| |||
265 | 266 | | |
266 | 267 | | |
267 | 268 | | |
268 | | - | |
| 269 | + | |
269 | 270 | | |
270 | 271 | | |
271 | 272 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
| 50 | + | |
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
72 | | - | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | | - | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
92 | 113 | | |
93 | 114 | | |
94 | 115 | | |
95 | 116 | | |
96 | 117 | | |
97 | 118 | | |
98 | 119 | | |
99 | | - | |
| 120 | + | |
100 | 121 | | |
101 | 122 | | |
102 | 123 | | |
103 | | - | |
| 124 | + | |
104 | 125 | | |
105 | 126 | | |
106 | 127 | | |
107 | 128 | | |
108 | | - | |
| 129 | + | |
109 | 130 | | |
110 | 131 | | |
111 | 132 | | |
112 | 133 | | |
113 | 134 | | |
114 | | - | |
| 135 | + | |
115 | 136 | | |
116 | 137 | | |
117 | 138 | | |
| |||
125 | 146 | | |
126 | 147 | | |
127 | 148 | | |
| 149 | + | |
| 150 | + | |
128 | 151 | | |
129 | 152 | | |
130 | 153 | | |
| |||
146 | 169 | | |
147 | 170 | | |
148 | 171 | | |
149 | | - | |
| 172 | + | |
150 | 173 | | |
151 | 174 | | |
152 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments