zip_timeseries: Handle descending *and* ascending data correctly.

The previous fix broke promoted link traffic which is ordered the other
way.
This commit is contained in:
Neil Williams
2012-07-13 10:45:22 -07:00
parent 251f0f310b
commit 0c4b64ee3b
2 changed files with 5 additions and 3 deletions

View File

@@ -354,7 +354,7 @@ class PromotedLinkTraffic(RedditTraffic):
clicks = traffic.ClickthroughsByCodename.promotion_history(fullname,
start, end)
history = traffic.zip_timeseries(imps, clicks)
history = traffic.zip_timeseries(imps, clicks, order="ascending")
computed_history = []
self.total_impressions, self.total_clicks = 0, 0
for date, data in history:

View File

@@ -80,7 +80,7 @@ class PeekableIterator(object):
return item
def zip_timeseries(*series):
def zip_timeseries(*series, **kwargs):
"""Zip timeseries data while gracefully handling gaps in the data.
Timeseries data is expected to be a sequence of two-tuples (date, values).
@@ -93,6 +93,8 @@ def zip_timeseries(*series):
"""
next_slice = (max if kwargs.get("order", "descending") == "descending"
else min)
iterators = [PeekableIterator(s) for s in series]
widths = [len(w.peek()) for w in iterators]
@@ -101,7 +103,7 @@ def zip_timeseries(*series):
if not any(items):
return
current_slice = max(item[0] for item in items if item)
current_slice = next_slice(item[0] for item in items if item)
data = []
for i, item in enumerate(items):