#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ForecastIntervals {
pub level: f64,
pub lower: Vec<f64>,
pub upper: Vec<f64>,
}
impl ForecastIntervals {
pub fn empty(level: f64) -> ForecastIntervals {
Self {
level,
lower: Vec::new(),
upper: Vec::new(),
}
}
pub fn with_capacity(level: f64, capacity: usize) -> ForecastIntervals {
Self {
level,
lower: Vec::with_capacity(capacity),
upper: Vec::with_capacity(capacity),
}
}
}
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Forecast {
pub point: Vec<f64>,
pub intervals: Option<ForecastIntervals>,
}
impl Forecast {
pub fn empty() -> Forecast {
Self {
point: Vec::new(),
intervals: None,
}
}
pub fn with_capacity(capacity: usize) -> Forecast {
Self {
point: Vec::with_capacity(capacity),
intervals: None,
}
}
pub fn with_capacity_and_level(capacity: usize, level: f64) -> Forecast {
Self {
point: Vec::with_capacity(capacity),
intervals: Some(ForecastIntervals::with_capacity(level, capacity)),
}
}
pub fn chain(self, other: Self) -> Self {
let mut out = Self::empty();
out.point.extend(self.point);
out.point.extend(other.point);
if let Some(mut intervals) = self.intervals {
if let Some(other_intervals) = other.intervals {
intervals.lower.extend(other_intervals.lower);
intervals.upper.extend(other_intervals.upper);
}
out.intervals = Some(intervals);
} else if let Some(other_intervals) = other.intervals {
out.intervals = Some(other_intervals);
}
out
}
}