Skip to main content

nominal_api/conjure/objects/scout/compute/api/
value_difference_series.rs

1/// Calculates the first discrete difference of the input series. For each point, computes the difference between
2/// the current value and the previous value (current - previous). The first point in the input series is omitted
3/// from the output since it has no previous point to compare against.
4///
5/// This is equivalent to pandas DataFrame.diff() with period=1. Useful for analyzing changes between consecutive
6/// data points in time series data, such as detecting value increases or decreases.
7///
8/// Example: For input values [1.0, 1.0, 2.0, 2.5, 1.8], the output would be [0.0, 1.0, 0.5, -0.7] at the
9/// corresponding timestamps (the first timestamp is omitted).
10#[derive(
11    Debug,
12    Clone,
13    conjure_object::serde::Serialize,
14    conjure_object::serde::Deserialize,
15    conjure_object::private::DeriveWith
16)]
17#[serde(crate = "conjure_object::serde")]
18#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
19#[conjure_object::private::staged_builder::staged_builder]
20#[builder(crate = conjure_object::private::staged_builder, update, inline)]
21pub struct ValueDifferenceSeries {
22    #[builder(custom(type = super::NumericSeries, convert = Box::new))]
23    #[serde(rename = "input")]
24    input: Box<super::NumericSeries>,
25    #[builder(
26        default,
27        custom(
28            type = impl
29            Into<Option<super::NegativeValueConfiguration>>,
30            convert = |v|v.into().map(Box::new)
31        )
32    )]
33    #[serde(
34        rename = "negativeValuesConfiguration",
35        skip_serializing_if = "Option::is_none",
36        default
37    )]
38    negative_values_configuration: Option<Box<super::NegativeValueConfiguration>>,
39}
40impl ValueDifferenceSeries {
41    /// Constructs a new instance of the type.
42    #[inline]
43    pub fn new(input: super::NumericSeries) -> Self {
44        Self::builder().input(input).build()
45    }
46    #[inline]
47    pub fn input(&self) -> &super::NumericSeries {
48        &*self.input
49    }
50    /// Defines the strategy for handling negative output values. Defaults to allowNegativeValues if not specified.
51    #[inline]
52    pub fn negative_values_configuration(
53        &self,
54    ) -> Option<&super::NegativeValueConfiguration> {
55        self.negative_values_configuration.as_ref().map(|o| &**o)
56    }
57}