Exemplo n.º 1
0
    def test_report_dates(self):
        selector = self.get_selector()
        playlist = ChirpBroadcast()

        def create_track(artist, album, track, label):
            track = PlaylistTrack(playlist=playlist,
                                  selector=selector,
                                  freeform_artist_name=artist,
                                  freeform_album_title=album,
                                  freeform_track_title=track,
                                  freeform_label=label)
            track.put()
            return track

        # default date
        d = datetime.datetime(2010, 01, 10, 1, 1, 1)

        # album 'a', will be played twice
        albums = ['a', 'b', 'c', 'a']
        tracks = ['a', 'b', 'c']
        for album in albums:
            for track in tracks:
                s = "%s_%s" % (album, track)
                t = create_track("artist_" + s, "album_" + album,
                                 "track_" + track, "label_" + s)
                t.established = d
                t.put()

            # change date so each album is played once in a day
            # total of len(tracks) per day
            d = d - timedelta(days=1)

        # run report check against expected counts
        total_tracks = len(albums) * len(tracks)

        # date range to get all records
        from_date = datetime.datetime(2010, 01, 01, 0, 0, 0)
        to_date = datetime.datetime(2010, 01, 20, 0, 0, 0)

        # test query object recs
        pl = playlists_views.filter_tracks_by_date_range(from_date, to_date)
        self.assertEquals(total_tracks, pl.count())

        # test group by query, expect a total of 9 recs since album_a was played twice
        items = playlists_views.query_group_by_track_key(from_date, to_date)
        for i in items:
            if i['album_title'] is 'album_a':
                self.assertEquals(i['play_count'], 2)
        self.assertEquals(len(items), 9)

        # check timestamp is set correctly for same date range
        from_date = to_date = datetime.datetime(2010, 01, 10, 0, 0, 0)
        pl = playlists_views.filter_tracks_by_date_range(from_date, to_date)
        self.assertEquals(len(tracks), pl.count())
Exemplo n.º 2
0
    def test_report_dates(self):
        selector = self.get_selector()
        playlist = ChirpBroadcast()

        def create_track(artist, album, track, label):
            track = PlaylistTrack(
                        playlist=playlist,
                        selector=selector,
                        freeform_artist_name=artist,
                        freeform_album_title=album,
                        freeform_track_title=track,
                        freeform_label=label)
            track.put()
            return track

        # default date
        d = datetime.datetime(2010,01,10,1,1,1)

        # album 'a', will be played twice
        albums = ['a','b','c','a']
        tracks = ['a','b','c']
        for album in albums:
            for track in tracks:
                s = "%s_%s" % (album,track)
                t = create_track("artist_"+s, "album_"+album, "track_"+track, "label_"+s)
                t.established = d
                t.put()

            # change date so each album is played once in a day
            # total of len(tracks) per day
            d = d - timedelta(days=1)

        # run report check against expected counts
        total_tracks = len(albums) * len(tracks)

        # date range to get all records
        from_date = datetime.datetime(2010,01,01,0,0,0)
        to_date = datetime.datetime(2010,01,20,0,0,0)

        # test query object recs
        pl = playlists_views.filter_tracks_by_date_range(from_date, to_date)
        self.assertEquals(total_tracks, pl.count())

        # test group by query, expect a total of 9 recs since album_a was played twice
        items = playlists_views.query_group_by_track_key(from_date, to_date)
        for i in items:
            if i['album_title'] is 'album_a':
                self.assertEquals(i['play_count'], 2)
        self.assertEquals(len(items), 9)

        # check timestamp is set correctly for same date range
        from_date = to_date = datetime.datetime(2010,01,10,0,0,0)
        pl = playlists_views.filter_tracks_by_date_range(from_date, to_date)
        self.assertEquals(len(tracks), pl.count())
Exemplo n.º 3
0
def playlist_report_worker(results, request_params):
    form = PlaylistReportForm(data=request_params)
    if not form.is_valid():
        # TODO(Kumar) make this visible to the user
        raise ValueError('Invalid PlaylistReportForm')
    from_date = form.cleaned_data['from_date']
    to_date = form.cleaned_data['to_date']

    if results is None:
        # when starting the job, init file lines with the header row...
        results = {
            'items': {},  # items keyed by play key
            'last_offset': 0,
            'play_counts': {},  # play keys to number of plays
            'from_date': str(from_date),
            'to_date': str(to_date),
        }

    offset = results['last_offset']
    last_offset = offset + 50
    results['last_offset'] = last_offset

    query = filter_tracks_by_date_range(from_date, to_date)
    all_entries = query[offset:last_offset]

    if len(all_entries) == 0:
        finished = True
    else:
        finished = False

    for entry in all_entries:
        play_key = play_count_key(entry)
        if play_key in results['play_counts']:
            results['play_counts'][play_key] += 1
            continue
        else:
            results['play_counts'][play_key] = 1
        results['items'][play_key] = {
            'album_title':
            as_encoded_str(_get_entity_attr(entry, 'album_title')),
            'artist_name':
            as_encoded_str(_get_entity_attr(entry, 'artist_name')),
            'label':
            as_encoded_str(_get_entity_attr(entry, 'label')),
            'heavy_rotation':
            str(int(bool(HEAVY_ROTATION_TAG in entry.categories))),
            'light_rotation':
            str(int(bool(LIGHT_ROTATION_TAG in entry.categories)))
        }

    return finished, results
Exemplo n.º 4
0
def playlist_report_worker(results, request_params):
    form = PlaylistReportForm(data=request_params)
    if not form.is_valid():
        # TODO(Kumar) make this visible to the user
        raise ValueError('Invalid PlaylistReportForm')
    from_date = form.cleaned_data['from_date']
    to_date = form.cleaned_data['to_date']

    if results is None:
        # when starting the job, init file lines with the header row...
        results = {
            'items': {},  # items keyed by play key
            'last_offset': 0,
            'play_counts': {},  # play keys to number of plays
            'from_date': str(from_date),
            'to_date': str(to_date),
        }

    offset = results['last_offset']
    last_offset = offset+50
    results['last_offset'] = last_offset

    query = filter_tracks_by_date_range(from_date, to_date)
    all_entries = query[ offset: last_offset ]

    if len(all_entries) == 0:
        finished = True
    else:
        finished = False

    for entry in all_entries:
        play_key = play_count_key(entry)
        if play_key in results['play_counts']:
            results['play_counts'][play_key] += 1
            continue
        else:
            results['play_counts'][play_key] = 1
        results['items'][play_key] = {
            'album_title': as_encoded_str(_get_entity_attr(entry,
                                                           'album_title')),
            'artist_name': as_encoded_str(_get_entity_attr(entry,
                                                           'artist_name')),
            'label': as_encoded_str(_get_entity_attr(entry, 'label')),
            'heavy_rotation': str(int(bool(HEAVY_ROTATION_TAG in
                                           entry.categories))),
            'light_rotation': str(int(bool(LIGHT_ROTATION_TAG in
                                           entry.categories)))
        }

    return finished, results