def mavg(entries, lookback): """ Returns two lists, one for each of x_axis and y_axis where the y axis is a calculated moving average of the given count. """ logged, x, y = [], [], [] for e in entries: logged.append(e) if len(logged) < lookback: continue x.append(e.date) sample = [float(e.value) for e in logged[-lookback:]] assert len(sample) == lookback y.append(avg(sample)) return x, y
def _mavg(self, num): """Calculates the average of the last num entries.""" i = self._index() if len(self._parent_entries()) > num and i: return avg([float(e.value) for e in self._parent_entries()[i-num:i]])