Ejemplo n.º 1
0
def get_quotas(playlist):
    quotas = {'heavy_rotation_played': 0,
              'heavy_rotation_target': TRACKS_HEAVY_ROTATION_TARGET,
              'light_rotation_played': 0,
              'light_rotation_target': TRACKS_LIGHT_ROTATION_TARGET,
              'local_current_played': 0,
              'local_current_target': TRACKS_LOCAL_CURRENT_TARGET,
              'local_classic_played': 0,
              'local_classic_target': TRACKS_LOCAL_CLASSIC_TARGET}
    pl = PlaylistEvent.all().filter('playlist =', playlist)
    now = chicago_now()
    now.replace(second=0, microsecond=0)
    pl.filter('established >=', now - timedelta(seconds=60 * now.minute))
    pl.filter('established <', now + timedelta(seconds=60 * (60 - now.minute)))
    for event in iter_playlist_events_for_view(pl):
        if not event.is_break:
            if 'heavy_rotation' in event.categories:
                quotas['heavy_rotation_played'] += 1
            if 'light_rotation' in event.categories:
                quotas['light_rotation_played'] += 1
            if 'local_current' in event.categories:
                quotas['local_current_played'] += 1
            if 'local_classic' in event.categories:
                quotas['local_classic_played'] += 1

    return quotas
Ejemplo n.º 2
0
def get_quotas(playlist):
    quotas = {
        "heavy_rotation_played": 0,
        "heavy_rotation_target": TRACKS_HEAVY_ROTATION_TARGET,
        "light_rotation_played": 0,
        "light_rotation_target": TRACKS_LIGHT_ROTATION_TARGET,
        "local_current_played": 0,
        "local_current_target": TRACKS_LOCAL_CURRENT_TARGET,
        "local_classic_played": 0,
        "local_classic_target": TRACKS_LOCAL_CLASSIC_TARGET,
    }
    pl = PlaylistEvent.all().filter("playlist =", playlist)
    now = chicago_now()
    now.replace(second=0, microsecond=0)
    pl.filter("established >=", now - timedelta(seconds=60 * now.minute))
    pl.filter("established <", now + timedelta(seconds=60 * (60 - now.minute)))
    for event in iter_playlist_events_for_view(pl):
        if not event.is_break:
            if "heavy_rotation" in event.categories:
                quotas["heavy_rotation_played"] += 1
            if "light_rotation" in event.categories:
                quotas["light_rotation_played"] += 1
            if "local_current" in event.categories:
                quotas["local_current_played"] += 1
            if "local_classic" in event.categories:
                quotas["local_classic_played"] += 1

    return quotas
Ejemplo n.º 3
0
def get_quotas(playlist):
    quotas = {
        'heavy_rotation_played': 0,
        'heavy_rotation_target': TRACKS_HEAVY_ROTATION_TARGET,
        'light_rotation_played': 0,
        'light_rotation_target': TRACKS_LIGHT_ROTATION_TARGET,
        'local_current_played': 0,
        'local_current_target': TRACKS_LOCAL_CURRENT_TARGET,
        'local_classic_played': 0,
        'local_classic_target': TRACKS_LOCAL_CLASSIC_TARGET
    }
    pl = PlaylistEvent.all().filter('playlist =', playlist)
    now = chicago_now()
    now.replace(second=0, microsecond=0)
    pl.filter('established >=', now - timedelta(seconds=60 * now.minute))
    pl.filter('established <', now + timedelta(seconds=60 * (60 - now.minute)))
    for event in iter_playlist_events_for_view(pl):
        if not event.is_break:
            if 'heavy_rotation' in event.categories:
                quotas['heavy_rotation_played'] += 1
            if 'light_rotation' in event.categories:
                quotas['light_rotation_played'] += 1
            if 'local_current' in event.categories:
                quotas['local_current_played'] += 1
            if 'local_classic' in event.categories:
                quotas['local_classic_played'] += 1

    return quotas
Ejemplo n.º 4
0
def filter_playlist_events_by_date_range(from_date, to_date):
    fd = datetime(from_date.year, from_date.month, from_date.day, 0, 0, 0)
    td = datetime(to_date.year, to_date.month, to_date.day, 23, 59, 59)
    playlist = chirp_playlist_key()
    pl = PlaylistEvent.all().filter('playlist =', playlist)
    pl = pl.filter('established >=', fd)
    pl = pl.filter('established <=', td)
    pl = pl.order('-established')
    return pl
Ejemplo n.º 5
0
def filter_playlist_events_by_date_range(from_date, to_date):
    fd = datetime(from_date.year, from_date.month, from_date.day, 0, 0, 0)
    td = datetime(to_date.year, to_date.month, to_date.day, 23, 59, 59)
    playlist = chirp_playlist_key()
    pl = PlaylistEvent.all().filter('playlist =', playlist)
    pl = pl.filter('established >=', fd)
    pl = pl.filter('established <=', td)
    pl = pl.order('-established')
    return pl
Ejemplo n.º 6
0
def play_count(request):
    """View for keeping track of play counts"""
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)

    count = PlayCount.query(track.artist_name, track.album_title)
    if not count:
        count = PlayCount.create_first(track.artist_name, track.album_title,
                                       track.label)

    @db.transactional
    def increment(key):
        ob = db.get(key)
        ob.play_count += 1
        ob.put()

    increment(count.key())

    # See also:
    # https://developers.google.com/appengine/articles/sharding_counters
    return HttpResponse("OK")
Ejemplo n.º 7
0
def play_count(request):
    """View for keeping track of play counts"""
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)

    count = PlayCount.query(track.artist_name, track.album_title)
    if not count:
        count = PlayCount.create_first(track.artist_name,
                                       track.album_title,
                                       track.label)

    @db.transactional
    def increment(key):
        ob = db.get(key)
        ob.play_count += 1
        ob.put()

    increment(count.key())

    # See also:
    # https://developers.google.com/appengine/articles/sharding_counters
    return HttpResponse("OK")
Ejemplo n.º 8
0
def play_count(request):
    """View for keeping track of play counts"""
    track_key = request.POST['id']
    track = PlaylistEvent.get(track_key)
    artist_name = track.artist_name
    album = track.album
    if not album:
        # Try to find a compilation album based on track name.
        qs = Track.all().filter('title =', track.track_title)
        for candidate in qs.run():
            if (candidate.track_artist and
                candidate.album.title == track.album_title and
                candidate.track_artist.name == track.artist_name):
                album = candidate.album
                break
        if not album:
            log.info('No album for %s / %s / %s'
                     % (track.artist_name, track.track_title,
                        track.album_title))
    if album and album.is_compilation:
        artist_name = 'Various'

    count = PlayCount.query(artist_name, track.album_title)
    if not count:
        count = PlayCount.create_first(artist_name,
                                       track.album_title,
                                       track.label)

    @db.transactional
    def increment(key):
        ob = db.get(key)
        ob.play_count += 1
        ob.put()

    increment(count.key())

    # See also:
    # https://developers.google.com/appengine/articles/sharding_counters
    return HttpResponse("OK")
Ejemplo n.º 9
0
def get_playlist_history(playlist):
    pl = PlaylistEvent.all().filter("playlist =", playlist)
    pl = pl.filter("established >=", datetime.now() - timedelta(hours=3))
    pl = pl.order("-established")
    return list(iter_playlist_events_for_view(pl))
Ejemplo n.º 10
0
def get_playlist_history(playlist):
    pl = PlaylistEvent.all().filter('playlist =', playlist)
    pl = pl.filter('established >=', datetime.now() - timedelta(hours=3))
    pl = pl.order('-established')
    return list(iter_playlist_events_for_view(pl))