          logger.debug("Loading State: '%s'", state_file)
          self.state = self.serializer.load(state_file)
          logger.debug("Loaded state: %s", self.state)
  
      def get_iterations_for_session(self, session_id):
          """ Return the number of iterations for the given session id """
          session = self.state["sessions"].get(str(session_id), None)
          if session is None:
              logger.warning("No session data found for session id: %s", session_id)
              return 0
          return session["iterations"]
  
  
  class SessionsSummary():
      """ Calculations for analysis summary stats """
  
 
</s> remove     def load_state_file(self):
        """ Load the current state file """
        state_file = os.path.join(self.modeldir, "{}_state.json".format(self.modelname))
        logger.debug("Loading State: '%s'", state_file)
        self.state = self.serializer.load(state_file)
        logger.debug("Loaded state: %s", self.state)
 </s> add             self._time_stats[session_id] = dict(
                start_time=np.min(latest) if np.any(latest) else 0,
                end_time=np.max(latest) if np.any(latest) else 0,
                iterations=latest.shape[0] if np.any(latest) else 0) </s> remove     def __init__(self, session):
        logger.debug("Initializing %s: (session: %s)", self.__class__.__name__, session)
        self.session = session
        logger.debug("Initialized %s", self.__class__.__name__)
 </s> add         Parameters
        ----------
        session_id: int
            The session id to compile the stats for
        timestamps:
            The time stamp summary data for the given session id </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     @property
    def total_timestamps(self):
        """ Return timestamps from logs separated per session for all sessions """
        return self.tb_logs.get_timestamps()

    def initialize_session(self, is_training=False, session_id=None):
        """ Initialize the training session """
        logger.debug("Initializing session: (is_training: %s, session_id: %s)",
                     is_training, session_id)
        self.load_state_file()
        self.tb_logs = TensorBoardLogs(os.path.join(self.modeldir,
                                                    "{}_logs".format(self.modelname)))
        if is_training:
            self.session_id = max(int(key) for key in self.state["sessions"].keys())
        else:
            self.session_id = session_id
        self.initialized = True
        logger.debug("Initialized session. Session_ID: %s", self.session_id)
 </s> add             session_id = Session.session_ids[-1]
            latest = self._session.get_timestamps(session_id) </s> remove     @property
    def loss(self):
        """ dict: The loss for the current session id for each loss key """
        loss_dict = self.tb_logs.get_loss(session=self.session_id)[self.session_id]
        return loss_dict
 </s> add class SessionsSummary():  # pylint:disable=too-few-public-methods
    """ Performs top level summary calculations for each session ID within the loaded or currently
    training Session for display in the Analysis tree view.
        logger.debug("time_stats: %s", self._time_stats)
          logger.debug("Loading State: '%s'", state_file)
          self.state = self.serializer.load(state_file)
          logger.debug("Loaded state: %s", self.state)
  
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
        logger.debug("time_stats: %s", self._time_stats)
  
  
  class SessionsSummary():
      """ Calculations for analysis summary stats """
  
keep keep keep keep replace replace replace replace replace 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/stats.py