BUG: Stop intraday performance from emitting all transactions.

The intraday performance results were emitting all transactions
for the entire day up to that point, instead of the desired transaction
list for the current timestamp.

Add a `dt` parameter to the `to_dict` method of PerformancePeriod so
that the transactions are limited to a specific datetime.
When the parameter is `None`, a todays_performance object will
function as previously with returning all transactions for the day.
 # Please enter the commit message for your changes. Lines starting
This commit is contained in:
Eddie Hebert
2013-04-05 13:55:04 -04:00
parent dd76386e56
commit 5422970d13
2 changed files with 20 additions and 3 deletions
+6
View File
@@ -1069,3 +1069,9 @@ class TestPerformanceTracker(unittest.TestCase):
messages += tracker.process_event(foo_event_3)
self.assertEquals(2, len(messages))
self.assertEquals(1, len(messages[0]['intraday_perf']['transactions']),
"The first message should contain one transaction.")
# 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.")
+14 -3
View File
@@ -245,7 +245,8 @@ class PerformanceTracker(object):
# its own configuration down the line.
# Naming as intraday to make clear that these results are
# being updated per minute
_dict['intraday_perf'] = self.todays_performance.to_dict()
_dict['intraday_perf'] = self.todays_performance.to_dict(
self.saved_dt)
return _dict
@@ -634,10 +635,13 @@ class PerformancePeriod(object):
return rval
def to_dict(self):
def to_dict(self, dt=None):
"""
Creates a dictionary representing the state of this performance
period. See header comments for a detailed description.
Kwargs:
dt (datetime): If present, only return transactions for the dt.
"""
rval = self.__core_dict()
@@ -647,7 +651,14 @@ class PerformancePeriod(object):
# we want the key to be absent, not just empty
if self.keep_transactions:
transactions = [x.__dict__ for x in self.processed_transactions]
if dt:
# Only include transactions for given dt
transactions = [x.__dict__
for x in self.processed_transactions
if x.dt == dt]
else:
transactions = [x.__dict__
for x in self.processed_transactions]
rval['transactions'] = transactions
return rval