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
//! # Pull Request and Code Review Metrics
//!
//! Code review is usually the single largest wait-time contributor inside
//! the cycle-time breakdown, and it is also the stage most directly under a
//! team's own control to improve. This module covers two of that stage's
//! core metrics: **time to first review**, the dominant wait-time lever, and
//! **reviewer load concentration**, a way to surface an otherwise-invisible
//! bottleneck and bus-factor risk in who does the reviewing.
//!
//! ## Formula
//!
//! ```text
//! Time to first review = t(first substantive comment or approval) - t(opened)
//! Reviewer load concentration = max(reviews per reviewer) / mean(reviews per reviewer)
//! ```
//!
//! ## Why it matters
//!
//! Most delay in the review stage comes from a pull request waiting to be
//! looked at, not from the review conversation taking long once it starts —
//! which is why time to first review, instrumented automatically from the
//! version control platform, "typically produces the largest single
//! improvement to overall cycle time available to a team." Separately,
//! reviewer load is commonly concentrated on a small number of people
//! without anyone measuring it directly: an enterprise example in the book
//! found "a handful of principal engineers were completing over 40% of all
//! code reviews across a two-hundred-person organization." That
//! concentration is both a bottleneck, since those engineers' availability
//! caps the whole team's review throughput, and a burnout risk.
//!
//! ## Example
//!
//! ```rust
//! use software_engineering::pull_request_metrics::{
//! time_to_first_review, reviewer_load_concentration_ratio,
//! };
//!
//! // A pull request opened at hour 0 gets its first review comment at hour 5.
//! assert_eq!(time_to_first_review(0.0, 5.0), 5.0);
//!
//! // Five reviewers complete 40, 10, 10, 10, and 10 reviews in a quarter:
//! // one reviewer is doing 2.5x the average review load.
//! let reviews = [40.0, 10.0, 10.0, 10.0, 10.0];
//! let ratio = reviewer_load_concentration_ratio(&reviews).unwrap();
//! assert!((ratio - 2.5).abs() < 1e-9);
//! ```
//!
//! ## Pitfalls
//!
//! - **Optimizing time to first review without a paired quality guardrail**
//! invites rubber-stamp approval that defeats review's purpose; a fast
//! approval with no real scrutiny is worse than a slower, genuine one.
//! - **Reviewer load concentration is a diagnostic system signal for
//! spotting bottleneck and bus-factor risk — never an individual
//! performance scorecard.** The book is explicit that review-related
//! counts are "more often a system or communication signal than a
//! personal one," and warns directly against "the evaluative drift"
//! of treating them as a judgement on any one reviewer or author. Use a
//! high ratio to prompt rotation and knowledge-sharing, not to rank or
//! evaluate the individuals involved.
//! - **Ignoring reviewer load concentration** leaves it invisible until it
//! surfaces as a bottleneck (the concentrated reviewers' availability caps
//! throughput) or a burnout event.
//!
//! ## Sources
//!
//! - Chapter 2.9, Pull request and code review metrics.
//!
//! Topic doc: software-engineering-metrics/locales/en-001/chapters/02-09-pull-request-and-code-review-metrics.md
/// Time to first review: the interval from a pull request being opened to a
/// reviewer's first substantive comment or approval.
///
/// The book identifies this as "usually the dominant wait-time contributor"
/// within the review stage, and improving it typically produces the largest
/// single improvement to overall cycle time available to a team.
///
/// # Arguments
///
/// * `opened_at` — the time the pull request was opened (any consistent time
/// unit, e.g. hours since epoch).
/// * `first_response_at` — the time of the reviewer's first substantive
/// comment or approval, in the same unit.
///
/// # Returns
///
/// The elapsed time between opening and first review response, in the same
/// unit as the inputs.
///
/// # Examples
///
/// ```rust
/// use software_engineering::pull_request_metrics::time_to_first_review;
///
/// // Opened at hour 10, first reviewed at hour 34: an 18-hour wait.
/// assert_eq!(time_to_first_review(10.0, 34.0), 24.0);
/// ```
/// Reviewer load concentration ratio: the busiest reviewer's review count
/// divided by the mean review count across all reviewers.
///
/// This is a **diagnostic system signal**, not an individual performance
/// scorecard. The book's own worked example, "a handful of principal
/// engineers were completing over 40% of all code reviews across a
/// two-hundred-person organization," is precisely the pattern this ratio is
/// meant to surface: a bottleneck (the concentrated reviewers' availability
/// caps team-wide review throughput) and a burnout risk, not evidence that
/// any individual reviewer is doing something wrong. Use a high ratio to
/// prompt review rotation and knowledge-sharing — never to rank or evaluate
/// individual reviewers.
///
/// # Arguments
///
/// * `reviews_per_reviewer` — completed review counts for each reviewer over
/// a rolling window.
///
/// # Returns
///
/// `Some(ratio)` where `ratio` is the maximum value divided by the mean of
/// `reviews_per_reviewer`; `None` when the slice is empty or the mean is
/// zero (ratio undefined). A ratio near `1.0` indicates evenly distributed
/// review load; a high ratio indicates concentration on a small number of
/// people.
///
/// # Examples
///
/// ```rust
/// use software_engineering::pull_request_metrics::reviewer_load_concentration_ratio;
///
/// // Evenly distributed load: ratio is 1.0.
/// let even = [10.0, 10.0, 10.0, 10.0];
/// assert!((reviewer_load_concentration_ratio(&even).unwrap() - 1.0).abs() < 1e-9);
///
/// // Concentrated load: one reviewer far above the mean.
/// let concentrated = [40.0, 10.0, 10.0, 10.0, 10.0];
/// assert!((reviewer_load_concentration_ratio(&concentrated).unwrap() - 2.5).abs() < 1e-9);
///
/// assert_eq!(reviewer_load_concentration_ratio(&[]), None);
/// ```