              method = getattr(self, "calc_{}".format(selection))
              raw_keys = [key for key in self.stats.keys() if key.startswith("raw_")]
              for key in raw_keys:
                  selected_key = "{}_{}".format(selection, key.replace("raw_", ""))
                  self.stats[selected_key] = method(self.stats[key])
  
      def calc_avg(self, data):
          """ Calculate rolling average """
          logger.debug("Calculating Average")
          avgs = list()
 
</s> remove             method = getattr(self, "calc_{}".format(selection))
            raw_keys = [key for key in self.stats.keys() if key.startswith("raw_")]
 </s> add             method = getattr(self, "_calc_{}".format(selection))
            raw_keys = [key for key in self._stats if key.startswith("raw_")] </s> remove     def calc_avg(self, data):
        """ Calculate rolling average """
 </s> add         Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to calculate the moving average for

        Returns
        -------
        :class:`numpy.ndarray`
            The moving average for the given data
        """ </s> remove     def get_calculations(self):
        """ Perform the required calculations """
        for selection in self.selections:
 </s> add     def _get_calculations(self):
        """ Perform the required calculations and populate :attr:`stats`. """
        for selection in self._selections: </s> remove         avgs = list()
        presample = ceil(self.args["avg_samples"] / 2)
        postsample = self.args["avg_samples"] - presample
        datapoints = len(data)
 </s> add         window = self._args["avg_samples"]
        pad = ceil(window / 2)
        datapoints = data.shape[0] </s> remove     def calc_smoothed(self, data):
        """ Smooth the data """
        last = data[0]  # First value in the plot (first time step)
        weight = self.args["smooth_amount"]
        smoothed = list()
        for point in data:
            smoothed_val = last * weight + (1 - weight) * point  # Calculate smoothed value
            smoothed.append(smoothed_val)                        # Save it
            last = smoothed_val                                  # Anchor the last smoothed value

        return smoothed

    @staticmethod
    def calc_trend(data):
        """ Compile trend data """
 </s> add     def _calc_smoothed(self, data):
        """ Smooth the data.

        Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to smoothen

        Returns
        -------
        :class:`numpy.ndarray`
            The smoothed data
        """
        return ExponentialMovingAverage(data, self._args["smooth_amount"])()

    @classmethod
    def _calc_trend(cls, data):
        """ Calculate polynomial trend of the given data.

        Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to calculate the trend for

        Returns
        -------
        :class:`numpy.ndarray`
            The trend for the given data
        """
                self._stats[selected_key] = method(self._stats[key])

    def _calc_avg(self, data):
        """ Calculate moving average.
              method = getattr(self, "calc_{}".format(selection))
              raw_keys = [key for key in self.stats.keys() if key.startswith("raw_")]
              for key in raw_keys:
                  selected_key = "{}_{}".format(selection, key.replace("raw_", ""))
                self._stats[selected_key] = method(self._stats[key])

    def _calc_avg(self, data):
        """ Calculate moving average.
  
      def calc_avg(self, data):
          """ Calculate rolling average """
          logger.debug("Calculating Average")
          avgs = list()
keep keep keep keep replace keep keep keep keep keep
 GUI - Stats optimization (#1067)

* Faster stat loading + caching

* Compress data in cache

* Optimize some calculations

* Vectorize smoothing

* stats.Calculations optimized

* Load latest training data from live iterator

* Add options to training graph 
lib/gui/stats.py