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
/* ***
*
* Harmos
*
* SPDX-License-Identifier: Apache-2.0
*
* ***
*/
/* === Modules === */
/* === Re-Exports === */
/* === Imports === */
// Standard Library Imports
// Third Party Imports
use crate::signal::{Series, Summary};
// Local Imports
use harmos_domain::Aggregate;
/* === Constants === */
/* === Macros === */
/* === Type Aliases === */
/* === Structs === */
/* === Enums === */
/* === Traits === */
/* === Implementations === */
/* === Public Functions === */
// Answers one member of the contract vocabulary from the signal math. The
// kernels live in the sibling `signal` module; these functions connect them to
// core reductions and for `signal::Aggregates` alike. Empty input answers
// `Count` and `Sum` with zero and every other member with `None`.
pub fn of_series(series: &Series<'_>, kind: Aggregate) -> Option<f64> {
match kind {
Aggregate::Median => series.median(),
Aggregate::Percentile(rank) => series.percentile(f64::from(rank)),
mergeable => of_summary(&series.summary(), mergeable),
}
}
pub fn of_summary(summary: &Summary, kind: Aggregate) -> Option<f64> {
match kind {
Aggregate::Count => Some(summary.count() as f64),
Aggregate::Sum => Some(summary.sum()),
Aggregate::Mean => summary.mean(),
Aggregate::Min => summary.min(),
Aggregate::Max => summary.max(),
Aggregate::Rms => summary.rms(),
Aggregate::Std => summary.std(),
// A summary keeps constant state so it can merge, and an order
// statistic is not a function of any constant state: the median of a
// union depends on where every value falls, not on per-part counts
// and moments. Refusing beats an estimate that reads exact.
Aggregate::Median | Aggregate::Percentile(_) => None,
}
}
/* === Private Functions === */
/* === Tests === */