Ejemplo n.º 1
0
 def _load(self):
     ''' Moves snapshots from db into the cache '''
     logging.info("Loading game history from database ...")
     if Snapshot.by_id(1) is None:
         self.__now__()  # Take starting snapshot
     self.epoch = Snapshot.by_id(1).created
     try:
         max_index = len(self)
         start_index = 1 if len(self) <= 10 else max_index - 9
         for index in range(start_index, max_index + 1):
             snapshot = Snapshot.by_id(index)
             if self.cache.get(snapshot.key) is None:
                 logging.info("Cached snapshot (%d of %d)" %
                              (snapshot.id, max_index))
                 self.cache.set(snapshot.key, snapshot.to_dict())
         logging.info("History load complete.")
     except KeyboardInterrupt:
         logging.info("History load stopped by user.")
Ejemplo n.º 2
0
 def _load(self):
     ''' Moves snapshots from db into the cache '''
     logging.info("Loading game history from database ...")
     if Snapshot.by_id(1) is None:
         self.__now__()  # Take starting snapshot
     self.epoch = Snapshot.by_id(1).created
     try:
         max_index = len(self)
         start_index = 1 if len(self) <= 10 else max_index - 9
         for index in range(start_index, max_index + 1):
             snapshot = Snapshot.by_id(index)
             if self.cache.get(snapshot.key) is None:
                 logging.info("Cached snapshot (%d of %d)" % (
                     snapshot.id, max_index
                 ))
                 self.cache.set(snapshot.key, snapshot.to_dict())
         logging.info("History load complete.")
     except KeyboardInterrupt:
         logging.info("History load stopped by user.")
Ejemplo n.º 3
0
 def __at__(self, index):
     ''' Get snapshot at specific index '''
     key = Snapshot.to_key(index + 1)
     if self.cache.get(key) is not None:
         return self.cache.get(key)
     else:
         snapshot = Snapshot.by_id(index + 1)
         if snapshot is not None:
             self.cache.set(snapshot.key, snapshot.to_dict())
             return snapshot.to_dict()
     return None
Ejemplo n.º 4
0
 def __at__(self, index):
     ''' Get snapshot at specific index '''
     key = Snapshot.to_key(index + 1)
     if self.cache.get(key) is not None:
         return self.cache.get(key)
     else:
         snapshot = Snapshot.by_id(index + 1)
         if snapshot is not None:
             self.cache.set(snapshot.key, snapshot.to_dict())
             return snapshot.to_dict()
     return None
Ejemplo n.º 5
0
 def _load(self):
     """ Moves snapshots from db into the cache """
     logging.info("Loading game history from database ...")
     snaps = Snapshot.all()
     if len(snaps) > 0:
         snap = snaps[0]
     else:
         snap = self.__now__()  # Take starting snapshot
     self.epoch = snap.created
     try:
         max_index = len(self)
         start_index = snap.id if len(self) <= (snap.id + 9) else max_index - 9
         for index in range(start_index, max_index + 1):
             snapshot = Snapshot.by_id(index)
             if snapshot and self.cache.get(snapshot.key) is None:
                 logging.info(
                     "Cached snapshot (%d of %d)" % (snapshot.id, max_index)
                 )
                 self.cache.set(snapshot.key, snapshot.to_dict())
         logging.info("History load complete.")
     except TypeError:
         logging.error("Error Loading Cache (try to restart memcached)")
     except KeyboardInterrupt:
         logging.info("History load stopped by user.")
Ejemplo n.º 6
0
 def __contains__(self, index):
     return True if Snapshot.by_id(index) is not None else False
Ejemplo n.º 7
0
 def __contains__(self, index):
     return True if Snapshot.by_id(index) is not None else False