class_docstr: Helper class for computing moving average and sliding window
class_docstr_tok: ["Helper","class","for","computing","moving","average","and","sliding","window"]
docstr: Routine for computing a moving average.
  
  @param slidingWindow a list of previous values to use in computation that
      will be modified and returned
  @param total the sum of the values in slidingWindow to be used in the
      calculation of the moving average
  @param newVal a new number compute the new windowed average
  @param windowSize how many values to use in the moving window
  
  @returns an updated windowed average, the modified input slidingWindow list,
      and the new total sum of the sliding window
docstr_tok: ["Routine","for","computing","a","moving","average",".","@","param","slidingWindow","a","list","of","previous","values","to","use","in","computation","that","will","be","modified","and","returned","@","param","total","the","sum","of","the","values","in","slidingWindow","to","be","used","in","the","calculation","of","the","moving","average","@","param","newVal","a","new","number","compute","the","new","windowed","average","@","param","windowSize","how","many","values","to","use","in","the","moving","window","@","returns","an","updated","windowed","average",",","the","modified","input","slidingWindow","list",",","and","the","new","total","sum","of","the","sliding","window"]
code: def compute(slidingWindow, total, newVal, windowSize):
      """Routine for computing a moving average.
  
      @param slidingWindow a list of previous values to use in computation that
          will be modified and returned
      @param total the sum of the values in slidingWindow to be used in the
          calculation of the moving average
      @param newVal a new number compute the new windowed average
      @param windowSize how many values to use in the moving window
  
      @returns an updated windowed average, the modified input slidingWindow list,
          and the new total sum of the sliding window
      """
      if len(slidingWindow) == windowSize:
          total -= slidingWindow.pop(0)
  
      slidingWindow.append(newVal)
      total += newVal
      return float(total) / len(slidingWindow), slidingWindow, total
  
file_path: nupic-legacy/src/nupic/utils.py
imports: import numbers
  from nupic.serializable import Serializable
label_desc: Use image node_id 2 for calling the MovingAverage obj's underlying member method code with example usage: obj.compute(slidingWindow, total, newVal, windowSize) and returns: unknown,  slidingWindow,  total