fn add_up(&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_iter.next().unwrap_or(target_timeline.range).to;
        let mut data: Vec<f64> = Vec::with_capacity(target_timeline.len);
        let mut val = 0.0; // Initialising to avoid a compiler warning but not actually needed
        let mut start_period = true;

        //  loop through every source period
        for (source_range, source_val) in source_iter.zip(self.values.iter()) {
            if source_range.to <= target_day {
                // If source fully within target no need to part split periods
                if start_period {
                    start_period = false;
                    val = *source_val;
                } else {
                    val += source_val;
                }
                // If we've got to the end of the target range then
                // push in the aggregated value & move on
                if source_range.to == target_day {
                    // Append the data
                    data.push(val);
                    // Set vals to start the next target period
                    start_period = true;
                    target_day = target_iter.next().unwrap_or(target_timeline.range).to;
                }
            } else {
                // Source partially beyond the target period
                // allocate part of the source to the target period and the rest to the
                // next target period
                // split done by day count
                let res = source_val
                    * f64::from(DateRange::new(source_range.from, target_day).as_days())
                    / f64::from(source_range.as_days());
                val += res;
                data.push(val);
                start_period = false; // Needed?
                val = source_val - res;
                target_day = target_iter.next().unwrap_or(target_timeline.range).to;
            }
        }
        TimeSeries::new_unchecked(target_timeline, data)
    }
/// Internal method to change the periodicity of a TimeSeries object
/// from a smaller time period to a bigger one, i.e. weeks to quarters
/// using addition as the aggregation method
Internal method to change the periodicity of a TimeSeries object
from a smaller time period to a bigger one, i.e. weeks to quarters
using addition as the aggregation method
Internal method to change the periodicity of a TimeSeries object from a smaller time period to a bigger one i . e . weeks to quarters using addition as the aggregation method
fn add_up(&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_iter.next().unwrap_or(target_timeline.range).to;
        let mut data: Vec<f64> = Vec::with_capacity(target_timeline.len);
        let mut val = 0.0; // Initialising to avoid a compiler warning but not actually needed
        let mut start_period = true;
        //  loop through every source period
        for (source_range, source_val) in source_iter.zip(self.values.iter()) {
            if source_range.to <= target_day {
                // If source fully within target no need to part split periods
                if start_period {
                    start_period = false;
                    val = *source_val;
                } else {
                    val += source_val;
                }
                // If we've got to the end of the target range then
                // push in the aggregated value & move on
                if source_range.to == target_day {
                    // Append the data
                    data.push(val);
                    // Set vals to start the next target period
                    start_period = true;
                    target_day = target_iter.next().unwrap_or(target_timeline.range).to;
                }
            } else {
                // Source partially beyond the target period
                // allocate part of the source to the target period and the rest to the
                // next target period
                // split done by day count
                let res = source_val
                    * f64::from(DateRange::new(source_range.from, target_day).as_days())
                    / f64::from(source_range.as_days());
                val += res;
                data.push(val);
                start_period = false; // Needed?
                val = source_val - res;
                target_day = target_iter.next().unwrap_or(target_timeline.range).to;
            }
        }
        TimeSeries::new_unchecked(target_timeline, data)
    }
fn add_up ( & 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_iter . next ( ) . unwrap_or ( target_timeline . range ) . to ; let mut data : Vec < f64 > = Vec :: with_capacity ( target_timeline . len ) ; let mut val = 0.0 ; // Initialising to avoid a compiler warning but not actually needed let mut start_period = true ; //  loop through every source period for ( source_range , source_val ) in source_iter . zip ( self . values . iter ( ) ) { if source_range . to <= target_day { // If source fully within target no need to part split periods if start_period { start_period = false ; val = * source_val ; } else { val += source_val ; } // If we've got to the end of the target range then // push in the aggregated value & move on if source_range . to == target_day { // Append the data data . push ( val ) ; // Set vals to start the next target period start_period = true ; target_day = target_iter . next ( ) . unwrap_or ( target_timeline . range ) . to ; } } else { // Source partially beyond the target period // allocate part of the source to the target period and the rest to the // next target period // split done by day count let res = source_val * f64 :: from ( DateRange :: new ( source_range . from , target_day ) . as_days ( ) ) / f64 :: from ( source_range . as_days ( ) ) ; val += res ; data . push ( val ) ; start_period = false ; // Needed? val = source_val - res ; target_day = target_iter . next ( ) . unwrap_or ( target_timeline . range ) . to ; } } TimeSeries :: new_unchecked ( target_timeline , data ) }
Internal method to change the periodicity of a TimeSeries object
from a smaller time period to a bigger one, i.e.
Internal method to change the periodicity of a TimeSeries object from a smaller time period to a bigger one i . e .
&self
target_timeline
&'a Timeline
&self
target_timeline
&'a Timeline