  
          Training graph refresh - Updates the stats for the current training session when the graph
          has been updated.
  
          When training is commenced - Removes the currently displayed session.
  
          When the analysis folder has been populated - Updates the stats from that folder.
          """
          self.vars["refresh_graph"].trace("w", self._update_current_session)
          self.vars["is_training"].trace("w", self._remove_current_session)
          self.vars["analysis_folder"].trace("w", self._populate_from_folder)
 
</s> remove         self.vars["is_training"].trace("w", self._remove_current_session)
 </s> add  </s> remove class SessionsSummary():
    """ Calculations for analysis summary stats """
 </s> add         If a training session is running, then updates the training sessions stats only.
        """
        if self._per_session_stats is None:
            logger.debug("Collating per session stats")
            compiled = list()
            for session_id, ts_data in self._time_stats.items():
                logger.debug("Compiling session ID: %s", session_id)
                if self._state is None:
                    logger.debug("Session state dict doesn't exist. Most likely task has been "
                                 "terminated during compilation")
                    return
                compiled.append(self._collate_stats(session_id, ts_data))

            self._per_session_stats = list(sorted(compiled, key=lambda k: k["session"]))

        elif self._session.is_training:
            logger.debug("Collating per session stats for latest training data")
            session_id = self._session.session_ids[-1]
            ts_data = self._time_stats[session_id]

            if session_id > len(self._per_session_stats):
                self._per_session_stats.append(self._collate_stats(session_id, ts_data))

            stats = self._per_session_stats[-1]

            stats["start"] = ts_data["start_time"]
            stats["end"] = ts_data["end_time"]
            stats["elapsed"] = int(stats["end"] - stats["start"])
            stats["iterations"] = ts_data["iterations"]
            stats["rate"] = (((stats["batch"] * 2) * stats["iterations"])
                             / stats["elapsed"] if stats["elapsed"] != 0 else 0)
        logger.debug("per_session_stats: %s", self._per_session_stats)

    def _collate_stats(self, session_id, timestamps):
        """ Collate the session summary statistics for the given session ID. </s> remove """ Stats functions for the GUI """
 </s> add """ Stats functions for the GUI.

Holds the globally loaded training session. This will either be a user selected session (loaded in
the analysis tab) or the currently training session.

""" </s> remove     @staticmethod
    def init_training_session(cliopt):
        """ Set the session stats for disable logging, model folder and model name """
        session = get_config().session
        if cliopt[0] == "-t":
            session.modelname = cliopt[1].lower().replace("-", "_")
            logger.debug("modelname: '%s'", session.modelname)
        if cliopt[0] == "-m":
            session.modeldir = cliopt[1]
            logger.debug("modeldir: '%s'", session.modeldir)
 </s> add     def _get_training_session_info(self, cli_option):
        """ Set the model folder and model name to :`attr:_training_session_location` so the global
        session picks them up for logging to the graph and analysis tab.

        Parameters
        ----------
        cli_option: list
            The command line option to be checked for model folder or name
        """
        if cli_option[0] == "-t":
            self._training_session_location["model_name"] = cli_option[1].lower().replace("-", "_")
            logger.debug("model_name: '%s'", self._training_session_location["model_name"])
        if cli_option[0] == "-m":
            self._training_session_location["model_folder"] = cli_option[1]
            logger.debug("model_folder: '%s'", self._training_session_location["model_folder"])
  
          Training graph refresh - Updates the stats for the current training session when the graph
          has been updated.
  


          When the analysis folder has been populated - Updates the stats from that folder.
          """
          self.vars["refresh_graph"].trace("w", self._update_current_session)
          self.vars["is_training"].trace("w", self._remove_current_session)
          self.vars["analysis_folder"].trace("w", self._populate_from_folder)
keep keep keep keep replace 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/display_analysis.py