mixins/dataProcessing.js
/**
     * Finds consecutive null's and averages the next non-null value over itself and the preceeding nulls
     * This is used to handle days for which no numbers are reported (sundays, holidays, it varies by province)
     * This avoids misleading spikes in the chart and gives a more accurate visualization
     * @param {Array<number|null>} arr - Array of values or null for unreported days
     * @returns {Array<number>} - Array of processed values
     *
     */
Finds consecutive null's and averages the next non-null value over itself and the preceeding nulls
This is used to handle days for which no numbers are reported (sundays, holidays, it varies by province)
This avoids misleading spikes in the chart and gives a more accurate visualization
@param {Array} arr - Array of values or null for unreported days
@returns {Array} - Array of processed values
Finds consecutive null ' s and averages the next non - null value over itself and the preceeding nulls This is used to handle days for which no numbers are reported ( sundays holidays it varies by province ) This avoids misleading spikes in the chart and gives a more accurate visualization @param { Array } arr - Array of values or null for unreported days @returns { Array } - Array of processed values
averageNulls(arr) {
      const output = [...arr];
      []
      const consecutiveNulls = [];
      for (let i = 0; i < output.length; i++) {
        if (output[i] === null) {
          const nulls = [i];
          for (let j = i + 1; j < output.length; j++) {
            i = j;
            if (output[j] !== null) {
              break;
            } else {
              nulls.push(j);
            }
          }
          consecutiveNulls.push(nulls);
        }
      }
      consecutiveNulls.forEach(nullArray => {
        const nextNonNullIndex = nullArray[nullArray.length - 1] + 1;
        const valueToBeAveraged = output[nextNonNullIndex];
        const averagedValue = valueToBeAveraged / (nullArray.length + 1);
        const indexesToBeMutated = [...nullArray, nextNonNullIndex];
        indexesToBeMutated.forEach(mIndex => {
          output[mIndex] = averagedValue;
        });
      });
      return output;
    }
averageNulls ( arr ) { const output = [ ... arr ] ; const consecutiveNulls = [ ] ; for ( let i = 0 ; i < output . length ; i ++ ) { if ( output [ i ] === null ) { const nulls = [ i ] ; for ( let j = i + 1 ; j < output . length ; j ++ ) { i = j ; if ( output [ j ] !== null ) { break ; } else { nulls . push ( j ) ; } } consecutiveNulls . push ( nulls ) ; } } consecutiveNulls . forEach ( nullArray => { const nextNonNullIndex = nullArray [ nullArray . length - 1 ] + 1 ; const valueToBeAveraged = output [ nextNonNullIndex ] ; const averagedValue = valueToBeAveraged / ( nullArray . length + 1 ) ; const indexesToBeMutated = [ ... nullArray , nextNonNullIndex ] ; indexesToBeMutated . forEach ( mIndex => { output [ mIndex ] = averagedValue ; } ) ; } ) ; return output ; }
Finds consecutive null's and averages the next non-null value over itself and the preceeding nulls
 This is used to handle days for which no numbers are reported (sundays, holidays, it varies by province)
 This avoids misleading spikes in the chart and gives a more accurate visualization
 @param {Array<number|null>} arr - Array of values or null for unreported days
 @returns {Array<number>} - Array of processed values
Finds consecutive null ' s and averages the next non - null value over itself and the preceeding nulls This is used to handle days for which no numbers are reported ( sundays holidays it varies by province ) This avoids misleading spikes in the chart and gives a more accurate visualization @param { Array<number|null > } arr - Array of values or null for unreported days @returns { Array<number > } - Array of processed values
// Number[] // Number[][] // iterate over every input value, looking for nulls // we found a null // this stores the consecutive nulls for this interation. // let's check for any consecutive nulls // starting with the next index, we will iterate until we find a non-null value // keep the outer iterator in sync with the inner iterator, so we don't process any indexes twice. // this function could use a single loop if we kept track of if the previous value was null // that would possibly simplify this quite a bit. This approach made sense to me but now my brain is tired so I am not sure! // break out of inner loop // add index to this array of consecutive nulls // `nulls` is an array of consecutive null value indexes // add this group of consecutive nulls to our array for later processing // Now that we have recorded all the indexes of groups of consecutive nulls, let's process them // return the mutated array