Skip to main content

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

1/// Converts a boolean series to a range series, where each contiguous run of true values becomes a
2/// half-open range [start, end). The boolean series is treated as forward-filled: a value holds until the
3/// next sample. For example, given timestamps [0, 1, 2, 3, 4] and values [true, true, true, false, false],
4/// the result is a single range [0, 3). When openEnded is false and the series ends with true, the last
5/// range is closed at the final timestamp, producing a zero-duration range (moment) for isolated true values.
6#[derive(
7    Debug,
8    Clone,
9    conjure_object::serde::Serialize,
10    conjure_object::serde::Deserialize,
11    conjure_object::private::DeriveWith
12)]
13#[serde(crate = "conjure_object::serde")]
14#[derive_with(PartialEq, Eq, PartialOrd, Ord, Hash)]
15#[conjure_object::private::staged_builder::staged_builder]
16#[builder(crate = conjure_object::private::staged_builder, update, inline)]
17pub struct BooleanToRanges {
18    #[builder(custom(type = super::BooleanSeries, convert = Box::new))]
19    #[serde(rename = "input")]
20    input: Box<super::BooleanSeries>,
21    #[builder(default, into)]
22    #[serde(rename = "openEnded", skip_serializing_if = "Option::is_none", default)]
23    open_ended: Option<bool>,
24}
25impl BooleanToRanges {
26    /// Constructs a new instance of the type.
27    #[inline]
28    pub fn new(input: super::BooleanSeries) -> Self {
29        Self::builder().input(input).build()
30    }
31    #[inline]
32    pub fn input(&self) -> &super::BooleanSeries {
33        &*self.input
34    }
35    /// If true, the last range will be open-ended if the last value is true. Defaults to true.
36    /// Set to false to close trailing ranges at the last timestamp, which produces zero-duration
37    /// ranges (moments) for isolated trailing true values.
38    #[inline]
39    pub fn open_ended(&self) -> Option<bool> {
40        self.open_ended.as_ref().map(|o| *o)
41    }
42}