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
//! Pure helpers used by [`super::ProviderMetrics::all_snapshots`].
//!
//! Kept in their own file so the orchestration code in `metrics.rs` stays
//! small and readable.
/// Return the value at the `(n * pct) as usize` index of `sorted_values`,
/// or `0.0` if out of bounds. Inputs must be pre-sorted ascending.
///
/// # Examples
///
/// ```rust
/// use codetether_agent::telemetry::provider::stats::percentile;
///
/// let xs = [1.0, 2.0, 3.0, 4.0, 5.0];
/// assert_eq!(percentile(&xs, 0.50), 3.0);
/// assert_eq!(percentile(&xs, 0.95), 5.0);
/// assert_eq!(percentile(&[], 0.50), 0.0);
/// ```
/// Sort a `Vec<f64>` ascending, treating NaN as equal. Pure utility so the
/// unwrap-on-ordering pattern only appears here.
/// Arithmetic mean of `values`. Returns `0.0` for empty input.
///
/// # Examples
///
/// ```rust
/// use codetether_agent::telemetry::provider::stats::mean;
///
/// assert_eq!(mean(&[2.0, 4.0, 6.0]), 4.0);
/// assert_eq!(mean(&[]), 0.0);
/// ```