(podcasts, start_date=datetime(2010, 1, 1), leap=timedelta(days=1))
Returns data for the podcast listener timeseries

    An iterator with data for each day (starting from either the first released
    episode or the earliest play-event) is returned, where each day is
    reresented by a ListenerData tuple.
Returns data for the podcast listener timeseries
Returns data for the podcast listener timeseries
def listener_data(podcasts, start_date=datetime(2010, 1, 1), leap=timedelta(days=1)):
    """Returns data for the podcast listener timeseries

    An iterator with data for each day (starting from either the first released
    episode or the earliest play-event) is returned, where each day is
    reresented by a ListenerData tuple."""
    # index episodes by releaes-date
    episodes = Episode.objects.filter(podcast__in=podcasts, released__gt=start_date)
    episodes = {e.released.date(): e for e in episodes}

    history = EpisodeHistoryEntry.objects.filter(
        episode__podcast__in=podcasts, timestamp__gte=start_date
    )
    # contains play-counts, indexed by date {date: play-count}
    play_counts = playcounts_timerange(history)

    # we start either at the first episode-release or the first listen-event
    events = list(episodes.keys()) + list(play_counts.keys())

    if not events:
        # if we don't have any events, stop
        return

    start = min(events)
    for date in daterange(start, leap=leap):
        playcount = play_counts.get(date, 0)
        episode = episodes.get(date, None)
        yield ListenerData(date, playcount, episode)
def listener_data ( podcasts , start_date = datetime ( 2010 , 1 , 1 ) , leap = timedelta ( days = 1 ) ) : # index episodes by releaes-date episodes = Episode . objects . filter ( podcast__in = podcasts , released__gt = start_date ) episodes = { e . released . date ( ) : e for e in episodes } history = EpisodeHistoryEntry . objects . filter ( episode__podcast__in = podcasts , timestamp__gte = start_date ) # contains play-counts, indexed by date {date: play-count} play_counts = playcounts_timerange ( history ) # we start either at the first episode-release or the first listen-event events = list ( episodes . keys ( ) ) + list ( play_counts . keys ( ) ) if not events : # if we don't have any events, stop return start = min ( events ) for date in daterange ( start , leap = leap ) : playcount = play_counts . get ( date , 0 ) episode = episodes . get ( date , None ) yield ListenerData ( date , playcount , episode )