Prepare to make external iterator for TimeSeries.

[?]
Jun 11, 2021, 2:55 AM
XIWTRGR6SRVSX3TA6YZVMZIETMZNLJBQSJ3BAL3O6ZXURJPTHQZAC

Dependencies

Change contents

  • edit in src/lib.rs at line 19
    [2.358]
    [2.358]
    use serde::Serializer;
  • replacement in src/lib.rs at line 26
    [2.522][2.522:567]()
    #[derive(Clone, Copy, Debug, Eq, Serialize)]
    [2.522]
    [2.567]
    #[derive(Clone, Copy, Debug, Eq)]
  • edit in src/lib.rs at line 66
    [2.1487]
    [2.1487]
    }
    impl Serialize for MonthlyDate {
    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
    where
    S: Serializer,
    {
    serializer.serialize_str(&format!("{}-{:02}-01", self.year(), self.month()))
    }
  • edit in src/lib.rs at line 208
    [2.5321]
    [2.5321]
    impl RegularTimeSeries::<1> {
  • edit in src/lib.rs at line 211
    [2.5322]
    [2.5322]
    /// Consume two `RegularTimeSeries<1>` and return a `RegularTimeSeries<2>` over a tuple of the
    /// original values. If the duration of the two time-series' are different then panic. If the
    /// the result is empty, return an empty `RegularTimeSeries`.
    pub fn zip(self, other: RegularTimeSeries<1>) -> RegularTimeSeries<2> {
    // Each TimeSeries is a Vec of DatePoints. We can therefore just do the checks and use a
    // consuming iterator over all the DatePoints.
    if self.duration() != other.duration() { panic!() };
    // Find first and last dates, then create iterators with this date range and zip.
    let first_date = self.first_date().max(other.first_date());
    let last_date = self.last_date().min(other.last_date());
    let date_range = DateRange::new(Some(first_date), Some(last_date));
    let v: Vec<DatePoint<2>> = Vec::new();
    let () = self.iter(date_range);
    for (dp1, dp2) in self.iter(date_range).zip(other.iter(date_range)) {
    // let () = dp1;
    v.push(DatePoint::<2>::new(dp1.date(), [ dp1.value(0), dp2.value(0) ]));
    }
    TimeSeries::<2>::new(v).try_into().unwrap()
    }
    }
  • edit in src/lib.rs at line 244
    [2.5366]
    [2.5366]
  • edit in src/lib.rs at line 324
    [2.7602]
    [2.7602]
    // Shouldn't we make a external RegularTimeSeriesIter ? It points into RegularTimeSeries and has a flag which
    // manages the dates.
  • replacement in src/lib.rs at line 329
    [2.7603][2.7603:7650]()
    /// A range of dates with monthly granularity.
    [2.7603]
    [2.7650]
    /// A `DateRange` is used to constrain a `TimeSeries` iterator over a range of dates. If
    /// `start_date` or `end_date` are `None` then the iterator will start at the first value in the
    /// `TimeSeries` or end at the last value in the `TimeSeries` respectively.
  • edit in src/lib.rs at line 339
    [2.7790]
    [2.7790]
    pub fn new(start_date: Option<MonthlyDate>, end_date: Option<MonthlyDate>) -> Self {
    DateRange { start_date, end_date }
    }