reports.py 文件源码

python
阅读 42 收藏 0 点赞 0 评论 0

项目:django-souvenirs 作者: appsembler 项目源码 文件源码
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,
            ),
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号