mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-24 06:18:08 -05:00
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:
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user