Ejemplo n.º 1
0
 def test_different_tracks(self):
     self.count()
     new_trk = PlaylistTrack(playlist=self.track.playlist,
                             selector=self.track.selector,
                             freeform_artist_name='Prince',
                             freeform_album_title='Purple Rain',
                             freeform_track_title='When Doves Cry')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     track_ids = [str(w.key()) for w in PlayCount.all()]
     assert track_ids[0] != track_ids[1], (
         'Different artist/albums cannot have the same key')
Ejemplo n.º 2
0
 def test_different_tracks(self):
     self.count()
     new_trk = PlaylistTrack(
         playlist=self.track.playlist,
         selector=self.track.selector,
         freeform_artist_name='Prince',
         freeform_album_title='Purple Rain',
         freeform_track_title='When Doves Cry')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     track_ids = [str(w.key()) for w in PlayCount.all()]
     assert track_ids[0] != track_ids[1], (
         'Different artist/albums cannot have the same key')
Ejemplo n.º 3
0
def clear_data():
    for pl in Playlist.all():
        for track in PlaylistTrack.all().filter('playlist =', pl):
            track.delete()
        pl.delete()
    for ob in PlayCount.all():
        ob.delete()
Ejemplo n.º 4
0
def clear_data():
    for pl in Playlist.all():
        for track in PlaylistTrack.all().filter('playlist =', pl):
            track.delete()
        pl.delete()
    for ob in PlayCount.all():
        ob.delete()
Ejemplo n.º 5
0
def play_count_snapshot(request):
    """Cron view to create a play count snapshot (top 40)."""
    qs = PlayCount.all().order('-play_count')
    results = []
    for count in qs.fetch(40):
        results.append(PlayCountSnapshot.create_from_count(count))
    for res in results:
        res.get_result()  # wait for result
    log.info('Created play count snapshot')
Ejemplo n.º 6
0
def play_count_snapshot(request):
    """Cron view to create a play count snapshot (top 40)."""
    qs = PlayCount.all().order('-play_count')
    results = []
    for count in qs.fetch(40):
        results.append(PlayCountSnapshot.create_from_count(count))
    for res in results:
        res.get_result()  # wait for result
    log.info('Created play count snapshot')
Ejemplo n.º 7
0
def expunge_play_count(request):
    """Cron view to expire old play counts."""
    # Delete tracks that have not been incremented in the last week.
    qs = PlayCount.all().filter('modified <',
                                datetime.now() - timedelta(days=7))
    num = 0
    for ob in qs.fetch(1000):
        ob.delete()
        num += 1
    log.info('Deleted %s old play count entries' % num)
Ejemplo n.º 8
0
def expunge_play_count(request):
    """Cron view to expire old play counts."""
    # Delete tracks that have not been incremented in the last week.
    qs = PlayCount.all().filter('modified <',
                                datetime.now() - timedelta(days=7))
    num = 0
    for ob in qs.fetch(1000):
        ob.delete()
        num += 1
    log.info('Deleted %s old play count entries' % num)
Ejemplo n.º 9
0
    def test_expunge(self):
        self.count()
        ob = PlayCount.all()[0]
        old_ts = datetime.datetime.now() - timedelta(days=8)

        @staticmethod
        def now():
            return old_ts

        # Trick the data model into saving an auto-modified timestamp
        # a week in the past.
        p = fudge.patch_object(datetime.datetime, 'now', now)
        try:
            ob.save()
        finally:
            p.restore()

        res = self.expunge()
        eq_(res.status_code, 200)
        eq_(PlayCount.all().count(1), 0)
Ejemplo n.º 10
0
    def test_expunge(self):
        self.count()
        ob = PlayCount.all()[0]
        old_ts = datetime.datetime.now() - timedelta(days=8)

        @staticmethod
        def now():
            return old_ts

        # Trick the data model into saving an auto-modified timestamp
        # a week in the past.
        p = fudge.patch_object(datetime.datetime, 'now', now)
        try:
            ob.save()
        finally:
            p.restore()

        res = self.expunge()
        eq_(res.status_code, 200)
        eq_(PlayCount.all().count(1), 0)
Ejemplo n.º 11
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.º 12
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.º 13
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.º 14
0
    def test_expunge(self):
        from nose.exc import SkipTest
        raise SkipTest(
                'App Engine is stupid and doesnt allow you to use a '
                'stub datetime object')
        self.count()
        ob = PlayCount.all()[0]
        old_ts = datetime.datetime.now() - timedelta(days=8)

        @staticmethod
        def now():
            return old_ts

        # Trick the data model into saving an auto-modified timestamp
        # a week in the past.
        p = fudge.patch_object(datetime.datetime, 'now', now)
        try:
            ob.save()
        finally:
            p.restore()

        res = self.expunge()
        eq_(res.status_code, 200)
        eq_(PlayCount.all().count(1), 0)
Ejemplo n.º 15
0
    def test_expunge(self):
        from nose.exc import SkipTest
        raise SkipTest(
                'App Engine is stupid and doesnt allow you to use a '
                'stub datetime object')
        self.count()
        ob = PlayCount.all()[0]
        old_ts = datetime.datetime.now() - timedelta(days=8)

        @staticmethod
        def now():
            return old_ts

        # Trick the data model into saving an auto-modified timestamp
        # a week in the past.
        p = fudge.patch_object(datetime.datetime, 'now', now)
        try:
            ob.save()
        finally:
            p.restore()

        res = self.expunge()
        eq_(res.status_code, 200)
        eq_(PlayCount.all().count(1), 0)
Ejemplo n.º 16
0
 def test_count_different_track(self):
     self.count()
     # Copy the same artist/track into a new track.
     new_trk = PlaylistTrack(
         playlist=self.track.playlist,
         selector=self.track.selector,
         freeform_artist_name=self.track.freeform_artist_name,
         freeform_album_title=self.track.freeform_album_title,
         freeform_track_title='Another track from the album')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     eq_(count.artist_name, self.track.freeform_artist_name)
     eq_(count.album_title, self.track.freeform_album_title)
     eq_(count.label, self.track.label)
     eq_(count.play_count, 2)
Ejemplo n.º 17
0
 def test_count_different_track(self):
     self.count()
     # Copy the same artist/track into a new track.
     new_trk = PlaylistTrack(
         playlist=self.track.playlist,
         selector=self.track.selector,
         freeform_artist_name=self.track.freeform_artist_name,
         freeform_album_title=self.track.freeform_album_title,
         freeform_track_title='Another track from the album')
     new_trk.put()
     self.count(track_key=new_trk.key())
     count = PlayCount.all()[0]
     eq_(count.artist_name, self.track.freeform_artist_name)
     eq_(count.album_title, self.track.freeform_album_title)
     eq_(count.label, self.track.label)
     eq_(count.play_count, 2)
Ejemplo n.º 18
0
 def test_no_expunge(self):
     self.count()
     res = self.expunge()
     eq_(res.status_code, 200)
     eq_(PlayCount.all().count(1), 1)
Ejemplo n.º 19
0
 def test_no_expunge(self):
     self.count()
     res = self.expunge()
     eq_(res.status_code, 200)
     eq_(PlayCount.all().count(1), 1)