Skip to main content

nominal_api_conjure/conjure/objects/scout/compute/api/
numeric_bucket.rs

1#[derive(
2    Debug,
3    Clone,
4    conjure_object::serde::Serialize,
5    conjure_object::serde::Deserialize,
6    conjure_object::private::DeriveWith
7)]
8#[serde(crate = "conjure_object::serde")]
9#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
10#[conjure_object::private::staged_builder::staged_builder]
11#[builder(crate = conjure_object::private::staged_builder, update, inline)]
12pub struct NumericBucket {
13    #[builder(default, into)]
14    #[serde(rename = "min", skip_serializing_if = "Option::is_none", default)]
15    #[derive_with(with = conjure_object::private::DoubleWrapper)]
16    min: Option<f64>,
17    #[builder(default, into)]
18    #[serde(rename = "max", skip_serializing_if = "Option::is_none", default)]
19    #[derive_with(with = conjure_object::private::DoubleWrapper)]
20    max: Option<f64>,
21    #[builder(default, into)]
22    #[serde(rename = "mean", skip_serializing_if = "Option::is_none", default)]
23    #[derive_with(with = conjure_object::private::DoubleWrapper)]
24    mean: Option<f64>,
25    #[builder(default, into)]
26    #[serde(rename = "count", skip_serializing_if = "Option::is_none", default)]
27    count: Option<conjure_object::SafeLong>,
28    #[builder(default, into)]
29    #[serde(rename = "variance", skip_serializing_if = "Option::is_none", default)]
30    #[derive_with(with = conjure_object::private::DoubleWrapper)]
31    variance: Option<f64>,
32    #[builder(
33        default,
34        custom(
35            type = impl
36            Into<Option<super::NumericPoint>>,
37            convert = |v|v.into().map(Box::new)
38        )
39    )]
40    #[serde(rename = "firstPoint", skip_serializing_if = "Option::is_none", default)]
41    first_point: Option<Box<super::NumericPoint>>,
42    #[builder(
43        default,
44        custom(
45            type = impl
46            Into<Option<super::NumericPoint>>,
47            convert = |v|v.into().map(Box::new)
48        )
49    )]
50    #[serde(rename = "lastPoint", skip_serializing_if = "Option::is_none", default)]
51    last_point: Option<Box<super::NumericPoint>>,
52    #[builder(default, map(key(type = String, into), value(type = f64)))]
53    #[serde(
54        rename = "aggregations",
55        skip_serializing_if = "std::collections::BTreeMap::is_empty",
56        default
57    )]
58    #[derive_with(with = conjure_object::private::DoubleWrapper)]
59    aggregations: std::collections::BTreeMap<String, f64>,
60}
61impl NumericBucket {
62    /// Constructs a new instance of the type.
63    #[inline]
64    pub fn new() -> Self {
65        Self::builder().build()
66    }
67    #[inline]
68    pub fn min(&self) -> Option<f64> {
69        self.min.as_ref().map(|o| *o)
70    }
71    #[inline]
72    pub fn max(&self) -> Option<f64> {
73        self.max.as_ref().map(|o| *o)
74    }
75    #[inline]
76    pub fn mean(&self) -> Option<f64> {
77        self.mean.as_ref().map(|o| *o)
78    }
79    #[inline]
80    pub fn count(&self) -> Option<conjure_object::SafeLong> {
81        self.count.as_ref().map(|o| *o)
82    }
83    /// The population variance of the bucket. If the bucket has only one value, this will be 0.
84    #[inline]
85    pub fn variance(&self) -> Option<f64> {
86        self.variance.as_ref().map(|o| *o)
87    }
88    #[inline]
89    pub fn first_point(&self) -> Option<&super::NumericPoint> {
90        self.first_point.as_ref().map(|o| &**o)
91    }
92    /// Will be empty if the bucket only has a single point.
93    #[inline]
94    pub fn last_point(&self) -> Option<&super::NumericPoint> {
95        self.last_point.as_ref().map(|o| &**o)
96    }
97    /// Additional per-bucket aggregations that have no dedicated field above, keyed by the output column name
98    /// requested via `numericAggregations` or `numericOutputFieldsV2` (e.g. `sum`, `standardDeviation`,
99    /// `rootMeanSquare`, `p50`). Empty when no additional aggregations were requested.
100    #[inline]
101    pub fn aggregations(&self) -> &std::collections::BTreeMap<String, f64> {
102        &self.aggregations
103    }
104}