func (s *StatsTracker) Add(value int64) {
	s.lock.Lock()
	defer s.lock.Unlock()

	s.allTimeAvg = (s.totalPoints*s.allTimeAvg + value) / (s.totalPoints + 1)
	s.totalPoints++

	if value > s.allTimePeak {
		s.allTimePeak = value
	}

	now := s.timeProvider()

	s.dropOldPoints(now)

	if s.avgPointsHead == nil {
		s.avgPointsHead = &taggedPoint{now, value, 0}
		s.peakPointsHead = &taggedPoint{now, value, 0}
	} else if s.peakPointsHead.value < value {
		s.peakPointsHead.value = value
	}

	// We initialized avgPointsHead with the first value, don't count it twice
	if s.avgPointsHead.count > 0 {
		s.avgPointsHead.value = (s.avgPointsHead.count*s.avgPointsHead.value + value) / (s.avgPointsHead.count + 1)
	}
	s.avgPointsHead.count++
}
// Add Records a new value to the stats tracker
Add Records a new value to the stats tracker
// Add Records a new value to the stats tracker
func (s *StatsTracker) Add(value int64) {
	s.lock.Lock()
	defer s.lock.Unlock()
	s.allTimeAvg = (s.totalPoints*s.allTimeAvg + value) / (s.totalPoints + 1)
	s.totalPoints++
	if value > s.allTimePeak {
		s.allTimePeak = value
	}
	now := s.timeProvider()
	s.dropOldPoints(now)
	if s.avgPointsHead == nil {
		s.avgPointsHead = &taggedPoint{now, value, 0}
		s.peakPointsHead = &taggedPoint{now, value, 0}
	} else if s.peakPointsHead.value < value {
		s.peakPointsHead.value = value
	}
	if s.avgPointsHead.count > 0 {
		s.avgPointsHead.value = (s.avgPointsHead.count*s.avgPointsHead.value + value) / (s.avgPointsHead.count + 1)
	}
	s.avgPointsHead.count++
}
func ( s * StatsTracker ) Add ( value int64 ) { s . lock . Lock ( ) defer s . lock . Unlock ( ) s . allTimeAvg = ( s . totalPoints * s . allTimeAvg + value ) / ( s . totalPoints + 1 ) s . totalPoints ++ if value > s . allTimePeak { s . allTimePeak = value } now := s . timeProvider ( ) s . dropOldPoints ( now ) if s . avgPointsHead == nil { s . avgPointsHead = & taggedPoint { now , value , 0 } s . peakPointsHead = & taggedPoint { now , value , 0 } } else if s . peakPointsHead . value < value { s . peakPointsHead . value = value } if s . avgPointsHead . count > 0 { s . avgPointsHead . value = ( s . avgPointsHead . count * s . avgPointsHead . value + value ) / ( s . avgPointsHead . count + 1 ) } s . avgPointsHead . count ++ }
Add Records a new value to the stats tracker
Add Records a new value to the stats tracker
// We initialized avgPointsHead with the first value, don't count it twice