BUG: Fix extra minutely performance period during minute performance.

Prevent an extra performance result with the timestamp of the midnight of
the day from being emitted.

Fix by setting the `saved_dt` value with the dt of the first event,
before entering into the main performance loop, otherwise a performance
result with a midnight timestamp and data from just the first event is
emitted.
This commit is contained in:
Eddie Hebert
2013-04-09 19:31:25 -04:00
parent 5a7039ab93
commit e03d51f0bc
2 changed files with 20 additions and 1 deletions
+9
View File
@@ -1075,3 +1075,12 @@ class TestPerformanceTracker(unittest.TestCase):
# Check that transactions aren't emitted for previous events.
self.assertEquals(0, len(messages[1]['intraday_perf']['transactions']),
"The second message should have no transactions.")
# Ensure that period_close moves through time.
# Also, ensure that the period_closes are the expected dts.
self.assertEquals(foo_event_1.dt,
messages[0]['intraday_perf']['period_close'],
messages[0])
self.assertEquals(foo_event_2.dt,
messages[1]['intraday_perf']['period_close'],
messages[1])
+11 -1
View File
@@ -130,6 +130,7 @@ omitted).
"""
import itertools
import logbook
import math
@@ -205,7 +206,16 @@ class PerformanceTracker(object):
"""
Main generator work loop.
"""
for date, snapshot in stream_in:
# Set the simulation date to be the first event we see.
peek_date, peek_snapshot = next(stream_in)
self.saved_dt = peek_date
# Stitch back together the generator by placing the peeked
# event back in front
stream = itertools.chain([(peek_date, peek_snapshot)],
stream_in)
for date, snapshot in stream:
new_snapshot = []
for event in snapshot: