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
//! # Developer Experience Metrics
//!
//! Two practical measures from Part 3 of the book: **focus time**, the
//! count and duration of uninterrupted two-hour-plus blocks per week
//! (chapter 3.6's efficiency-and-flow dimension), and **survey response
//! rate**, itself a trust signal for a `DevEx` survey programme, not merely a
//! data-collection statistic (chapter 3.7).
//!
//! ## Formula
//!
//! ```text
//! Focus block = a calendar block >= 2.0 hours, uninterrupted
//! Response rate = (survey responses received / survey invitations sent) x 100%
//! ```
//!
//! ## Why it matters
//!
//! Refocusing after an interruption to deep, complex work routinely takes
//! many minutes, sometimes closer to half an hour, to fully rebuild the
//! working memory an engineer was holding before the interruption. An
//! engineer whose day is fragmented into short blocks may show plenty of
//! activity while accomplishing far less genuinely difficult work than the
//! same engineer would with two protected, uninterrupted hours. Separately,
//! a declining survey response rate often indicates eroding trust in the
//! process — survey fatigue, doubts that results lead to action, or
//! suspicion that anonymity is not genuinely protected — and deserves direct
//! investigation rather than being dismissed as a data-collection
//! inconvenience.
//!
//! ## Example
//!
//! ```rust
//! use software_engineering::developer_experience_metrics::{
//! is_focus_block, response_rate_percent,
//! };
//!
//! // "Uninterrupted blocks of two hours or more" count as focus time.
//! assert!(is_focus_block(2.0));
//! assert!(is_focus_block(2.5));
//! assert!(!is_focus_block(1.75));
//!
//! // A DevEx survey sent to 100 engineers, 72 responses: 72% response rate.
//! assert_eq!(response_rate_percent(72.0, 100.0), Some(72.0));
//! ```
//!
//! ## Pitfalls
//!
//! - **Using interruption or notification data as individual surveillance**
//! repeats the misuse risk the book warns against for activity data;
//! aggregate at the team level.
//! - **Imposing a single, rigid focus-time schedule on everyone** ignores
//! genuine individual variation in how people work best.
//! - **Ignoring a declining response rate** misses an important trust
//! signal in its own right — investigate rather than dismiss it.
//!
//! ## Sources
//!
//! - Chapter 3.6, Efficiency and flow: deep work and interruptions.
//! - Chapter 3.7, Developer experience surveys and `DevEx` metrics.
//!
//! Topic doc: software-engineering-metrics/locales/en-001/chapters/03-06-efficiency-and-flow.md
//! Topic doc: software-engineering-metrics/locales/en-001/chapters/03-07-developer-experience-surveys-and-devex-metrics.md
/// Whether a calendar block qualifies as protected "focus time".
///
/// The book defines focus time as "uninterrupted blocks of two hours or
/// more" measured from calendar data.
///
/// # Arguments
///
/// * `duration_hours` — length of the uninterrupted calendar block, in
/// hours.
///
/// # Returns
///
/// `true` iff `duration_hours >= 2.0`.
///
/// # Examples
///
/// ```rust
/// use software_engineering::developer_experience_metrics::is_focus_block;
///
/// assert!(is_focus_block(2.0));
/// assert!(!is_focus_block(1.99));
/// ```
/// Survey response rate as a percentage: responses received / invitations
/// sent x 100.
///
/// Treat this as a diagnostic signal in its own right (chapter 3.7): a
/// declining rate often indicates eroding trust in the survey process.
///
/// # Arguments
///
/// * `responses_received` — count of survey responses received.
/// * `invitations_sent` — count of survey invitations sent.
///
/// # Returns
///
/// `Some(percentage)`, or `None` when `invitations_sent` is zero (rate
/// undefined).
///
/// # Examples
///
/// ```rust
/// use software_engineering::developer_experience_metrics::response_rate_percent;
///
/// assert_eq!(response_rate_percent(72.0, 100.0), Some(72.0));
/// assert_eq!(response_rate_percent(1.0, 0.0), None);
/// ```