sorted out conversion to dataframe, fixed logic bug with callbacks. still need to allow for dot notation to frame.

This commit is contained in:
fawce
2012-03-14 00:23:51 -04:00
parent 84bccbc67c
commit d5c4526e93
2 changed files with 12 additions and 7 deletions
+10 -5
View File
@@ -48,6 +48,7 @@ class TradeSimulationClient(qmsg.Component):
if msg == str(zp.CONTROL_PROTOCOL.DONE):
qutil.LOGGER.info("Client is DONE!")
self.run_callbacks()
self.signal_done()
return
@@ -61,9 +62,9 @@ class TradeSimulationClient(qmsg.Component):
#mark the start time for client's processing of this event.
event_start = datetime.datetime.utcnow()
self.queue_event(event)
for cb in self.event_callbacks:
if(event.dt >= self.current_dt):
cb(self.get_frame())
if event.dt >= self.current_dt:
self.run_callbacks()
#update time based on receipt of the order
self.last_iteration_duration = datetime.datetime.utcnow() - event_start
@@ -72,6 +73,11 @@ class TradeSimulationClient(qmsg.Component):
#signal done to order source.
self.order_socket.send(str(zp.ORDER_PROTOCOL.BREAK))
def run_callbacks(self):
frame = self.get_frame()
for cb in self.event_callbacks:
cb(frame)
def connect_order(self):
return self.connect_push_socket(self.addresses['order_address'])
@@ -94,8 +100,7 @@ class TradeSimulationClient(qmsg.Component):
self.event_queue[event.dt] = event.as_series()
def get_frame(self):
sorted_dates = sorted(self.event_queue.keys())
frame = pandas.DataFrame(self.event_queue, index=sorted_dates)
frame = pandas.DataFrame(self.event_queue)
self.event_queue = None
return frame
+2 -2
View File
@@ -208,9 +208,9 @@ class namedict(object):
return self.__dict__.has_key(name)
def as_series(self):
s = pandas.Series(self.__dict__.values(), self.__dict__.keys())
s = pandas.Series(self.__dict__, self.__dict__.keys())
return s
# ================
# Control Protocol
# ================