def _usage_for_periods(periods):
"""
Generate a sequence of dictionaries of usage data corresponding to periods,
each of which should be a tuple of (start, end) datetimes, where start is
inclusive and end is exclusive.
Each dictionary in the generated sequence has this form:
{
period: {
start: datetime,
end: datetime,
}
usage: {
registered_users: int,
activated_users: int,
active_users: int,
}
}
"""
rp, ap, periods = itertools.tee(periods, 3)
ir = (registered_users_as_of(end) for start, end in rp)
ia = (count_active_users(*p) for p in ap)
for p, r, active in izip(periods, ir, ia):
start, end = p
registered, activated = r
yield dict(
period=dict(
start=start,
end=end,
),
usage=dict(
registered_users=registered,
activated_users=activated,
active_users=active,
),
)
评论列表
文章目录