Skip to main content

ferric_fred/
aggregation_method.rs

1/// How observations are aggregated when down-sampling to a lower `frequency`
2/// (the `aggregation_method` request parameter). Only meaningful alongside
3/// [`ObservationsRequest::frequency`](crate::ObservationsRequest::frequency).
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[non_exhaustive]
6pub enum AggregationMethod {
7    /// Average of the higher-frequency values (`avg`, FRED's default).
8    Average,
9    /// Sum of the higher-frequency values (`sum`).
10    Sum,
11    /// The end-of-period value (`eop`).
12    EndOfPeriod,
13}
14
15impl AggregationMethod {
16    /// The FRED query code for this aggregation method.
17    pub fn query_code(self) -> &'static str {
18        match self {
19            Self::Average => "avg",
20            Self::Sum => "sum",
21            Self::EndOfPeriod => "eop",
22        }
23    }
24}
25
26#[cfg(test)]
27mod tests {
28    use super::*;
29
30    #[test]
31    fn query_codes_match_fred() {
32        assert_eq!(AggregationMethod::Average.query_code(), "avg");
33        assert_eq!(AggregationMethod::Sum.query_code(), "sum");
34        assert_eq!(AggregationMethod::EndOfPeriod.query_code(), "eop");
35    }
36}