             return self.getFromHa1cArray(index)
         }
     }
-
 
     /**
      - returns: readings between startDate (inclusive) and endDate (inclusive)

                                        date: Date,
                                        decayLifeSeconds: TimeInterval) -> Float {

        if bgReadings.count == 0 {
            return 0.0
        }

        var sumOfWeightedBgReadings: Float = 0.0
        var sumOfWeights: Float = 0.0
        //var numBgReadingsInAverage: Int = 0

        for bgReading in bgReadings {

            if bgReading.timeStamp > date {
                // skip this reading, continue loop
                continue
            }

            let weight = TrendsAlgorithmModel.weightLinearDecayFirstDate(bgReading.timeStamp,
                                                                         secondDate: date,
                                                                         decayLifeSeconds: decayLifeSeconds)

            sumOfWeightedBgReadings += weight * bgReading.quantity.floatValue
            sumOfWeights += weight
            //numBgReadingsInAverage += 1
        }

        // avoid potential divide by 0
        if sumOfWeights == 0 {
        //if numBgReadingsInAverage == 0 {
            return 0.0
        }
        let average = sumOfWeightedBgReadings / sumOfWeights
        //let average = sumOfWeightedBgReadings / Float(numBgReadingsInAverage)
        print("averageDecayedBGReadingQuantity \(average)")
        return average
    }

    }
    
    /**
    This method uses BGReading, a CoreData managed object.
     - parameter bgReadings: BGReading readings to average.
       readings may appear in any chronological order, the method reads their timeStamp
     - parameter date: date for quantity. Blood glucose readings after date are ignored.
     - parameter decayLifeSeconds: time for blood glucose from a reading to decay to 0.0.
