Ejemplo n.º 1
0
 def deserialize(cls, strategy_id=None, path=None):
     """Deserialize the strategy."""
     if path is None:
         assert strategy_id is not None
         path = os.path.join(DEFAULT_SERIALIZATION_DIR, strategy_id)
     with open(path, 'rb') as f:
         data = f.read()
     new_strategy = strategy_pb2.Strategy()
     new_strategy.ParseFromString(data)
     return cls(strategy=new_strategy)
Ejemplo n.º 2
0
 def copy(self):
     """Create a copy of this strategy."""
     other_strategy = strategy_pb2.Strategy()
     other_strategy.CopyFrom(self._strategy)
     return Strategy(strategy=other_strategy)
Ejemplo n.º 3
0
 def __init__(self, strategy=None):
     self._strategy = strategy or strategy_pb2.Strategy()
     if strategy is None:
         self._strategy.id = datetime.utcnow().strftime('%Y%m%dT%H%M%SM%f')