Esempio n. 1
0
def episode_listener_data(
    episode, start_date=datetime(2010, 1, 1), leap=timedelta(days=1)
):
    """Returns data for the episode listener timeseries

    An iterator with data for each day (starting from the first event
    is returned, where each day is represented by a ListenerData tuple"""
    history = EpisodeHistoryEntry.objects.filter(
        episode=episode, timestamp__gte=start_date
    )
    # contains play-counts, indexed by date {date: play-count}
    play_counts = playcounts_timerange(history)

    # we start either at the episode-release or the first listen-event
    events = (
        list(play_counts.keys()) + [episode.released.date()] if episode.released else []
    )

    if not events:
        return

    # we always start at the first listen-event
    start = min(events)
    for date in daterange(start, leap=leap):
        playcount = play_counts.get(date, 0)
        e = episode if (episode.released.date() == date) else None
        yield ListenerData(date, playcount, e)
Esempio n. 2
0
def episode_listener_data(episode, start_date=datetime(2010, 1, 1),
                          leap=timedelta(days=1)):
    """ Returns data for the episode listener timeseries

    An iterator with data for each day (starting from the first event
    is returned, where each day is represented by a ListenerData tuple """
    history = EpisodeHistoryEntry.objects\
                                 .filter(episode=episode,
                                         timestamp__gte=start_date)\
    # contains play-counts, indexed by date {date: play-count}
    play_counts = playcounts_timerange(history)

    # we start either at the episode-release or the first listen-event
    events = play_counts.keys() + \
             [episode.released.date()] if episode.released else []

    if not events:
        return

    # we always start at the first listen-event
    start = min(events)
    for date in daterange(start, leap=leap):
        playcount = play_counts.get(date, 0)
        e = episode if (episode.released.date() == date) else None
        yield ListenerData(date, playcount, e)
Esempio n. 3
0
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)
Esempio n. 4
0
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 = episodes.keys() + 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)