fn add_down(&self, target_timeline: &'a Timeline) -> Self {
        let source_iter = self.timeline.into_iter();
        let mut target_iter = target_timeline.into_iter();
        let mut target_day = target_timeline.range.from();
        let mut data: Vec<f64> = Vec::with_capacity(target_timeline.len);
        let mut res_end = 0.0;
        let mut res_start = 0.0;
        let mut part_end = false;
        let mut part_start = false;
        let mut val_end = 0.0;

        // TODO: This still treats the final target period as fully fitting within the source period
        // Only affects weeks but there's the possibility that the final period is a wekk of only 2
        // days and ideally this period would only hold 2/7 of the value from the period that preceeds it
        for (source_range, source_val) in source_iter.zip(self.values.iter()) {
            // Count through the target ranges until we have spanned the current source range
            let mut i = 0;
            let source_day = source_range.to;
            while target_day < source_day {
                let target_range = target_iter.next().unwrap_or(target_timeline.range);
                target_day = target_range.to;
                if target_day <= source_day {
                    i += 1;
                } else {
                    res_end = match target_range.intersect(&source_range) {
                        Some(r) => f64::from(r.as_days()) / f64::from(target_range.as_days()),
                        None => 0.0,
                    };
                    part_end = true;
                }
            }
            let val = source_val / (i as f64 + res_start + res_end);
            if part_start {
                data.push(val_end + val * res_start);
            }
            let mut vals = vec![val; i];
            data.append(&mut vals);
            part_start = part_end;
            if part_end {
                val_end = val * res_end;
                res_start = 1.0 - res_end;
                res_end = 0.0;
            }
        }
        TimeSeries::new_unchecked(target_timeline, data)
    }
/// Internal method to change the periodicity of a TimeSeries object
/// from a bigger time period to a smaller one, i.e. years to months
/// using addition as the aggregation method. Since we're increasing
/// the number of time periods it will be inferred that the target
/// time series values will all be the same for each source period (i.e
/// we'll divide the source values by the number target periods). There
/// are potentially other ways to do this
Internal method to change the periodicity of a TimeSeries object
from a bigger time period to a smaller one, i.e. years to months
using addition as the aggregation method. Since we're increasing
the number of time periods it will be inferred that the target
time series values will all be the same for each source period . There
are potentially other ways to do this
Internal method to change the periodicity of a TimeSeries object from a bigger time period to a smaller one i . e . years to months using addition as the aggregation method . Since we ' re increasing the number of time periods it will be inferred that the target time series values will all be the same for each source period . There are potentially other ways to do this
fn add_down(&self, target_timeline: &'a Timeline) -> Self {
        let source_iter = self.timeline.into_iter();
        let mut target_iter = target_timeline.into_iter();
        let mut target_day = target_timeline.range.from();
        let mut data: Vec<f64> = Vec::with_capacity(target_timeline.len);
        let mut res_end = 0.0;
        let mut res_start = 0.0;
        let mut part_end = false;
        let mut part_start = false;
        let mut val_end = 0.0;
        // TODO: This still treats the final target period as fully fitting within the source period
        // Only affects weeks but there's the possibility that the final period is a wekk of only 2
        // days and ideally this period would only hold 2/7 of the value from the period that preceeds it
        for (source_range, source_val) in source_iter.zip(self.values.iter()) {
            // Count through the target ranges until we have spanned the current source range
            let mut i = 0;
            let source_day = source_range.to;
            while target_day < source_day {
                let target_range = target_iter.next().unwrap_or(target_timeline.range);
                target_day = target_range.to;
                if target_day <= source_day {
                    i += 1;
                } else {
                    res_end = match target_range.intersect(&source_range) {
                        Some(r) => f64::from(r.as_days()) / f64::from(target_range.as_days()),
                        None => 0.0,
                    };
                    part_end = true;
                }
            }
            let val = source_val / (i as f64 + res_start + res_end);
            if part_start {
                data.push(val_end + val * res_start);
            }
            let mut vals = vec![val; i];
            data.append(&mut vals);
            part_start = part_end;
            if part_end {
                val_end = val * res_end;
                res_start = 1.0 - res_end;
                res_end = 0.0;
            }
        }
        TimeSeries::new_unchecked(target_timeline, data)
    }
fn add_down ( & self , target_timeline : & ' a Timeline ) -> Self { let source_iter = self . timeline . into_iter ( ) ; let mut target_iter = target_timeline . into_iter ( ) ; let mut target_day = target_timeline . range . from ( ) ; let mut data : Vec < f64 > = Vec :: with_capacity ( target_timeline . len ) ; let mut res_end = 0.0 ; let mut res_start = 0.0 ; let mut part_end = false ; let mut part_start = false ; let mut val_end = 0.0 ; // TODO: This still treats the final target period as fully fitting within the source period // Only affects weeks but there's the possibility that the final period is a wekk of only 2 // days and ideally this period would only hold 2/7 of the value from the period that preceeds it for ( source_range , source_val ) in source_iter . zip ( self . values . iter ( ) ) { // Count through the target ranges until we have spanned the current source range let mut i = 0 ; let source_day = source_range . to ; while target_day < source_day { let target_range = target_iter . next ( ) . unwrap_or ( target_timeline . range ) ; target_day = target_range . to ; if target_day <= source_day { i += 1 ; } else { res_end = match target_range . intersect ( & source_range ) { Some ( r ) => f64 :: from ( r . as_days ( ) ) / f64 :: from ( target_range . as_days ( ) ) , None => 0.0 , } ; part_end = true ; } } let val = source_val / ( i as f64 + res_start + res_end ) ; if part_start { data . push ( val_end + val * res_start ) ; } let mut vals = vec ! [ val i ] ; data . append ( & mut vals ) ; part_start = part_end ; if part_end { val_end = val * res_end ; res_start = 1.0 - res_end ; res_end = 0.0 ; } } TimeSeries :: new_unchecked ( target_timeline , data ) }
Internal method to change the periodicity of a TimeSeries object
from a bigger time period to a smaller one, i.e.
Internal method to change the periodicity of a TimeSeries object from a bigger time period to a smaller one i . e .
&self
target_timeline
&'a Timeline
&self
target_timeline
&'a Timeline