예제 #1
0
  def testArtistRatingPickle(self):
    Factories.clear()
    trackA= TrackFactory.get(self.artist, self.titleA)
    trackB = TrackFactory.get(self.artist, self.titleB)
    artist = trackA.artist
    trackA.played()
    trackB.skipped()
    rating = artist.rating
    i = 0
    for r in RatingFactory.ratings():
      i+=1
    # track init rating: 1
    # artist init rating: 2
    # track play rating: 3
    # artist play rating: 4
    # track skip rating: 5
    # artist skip rating: 6
    self.assertEqual(i, 6)

    state = pickle.dumps(Factories.getstate())
    Factories.clear()
    pickle.loads(state)

    i = 0
    for r in RatingFactory.ratings():
      i+=1
    self.assertEqual(i, 6)

    track = TrackFactory.get(self.artist, self.titleA)
    artist = track.artist
    self.assertEqual(artist.rating, rating)
예제 #2
0
파일: test_artist.py 프로젝트: pscn/ads
 def testArtistRef(self):
   # test if 2 calls to the same artist return the same reference
   Factories.clear()
   artist = ArtistFactory.get(self.artist)
   artist.test = self.artist_test
   artist2 = ArtistFactory.get(self.artist)
   self.assertEqual(artist.test, artist2.test)
예제 #3
0
파일: test_artist.py 프로젝트: pscn/ads
  def testArtistClear(self):
    Factories.clear()
    artist = ArtistFactory.get(self.artist)
    artist.test = self.artist_test

    Factories.clear()
    artist = ArtistFactory.get(self.artist)
    self.assertEqual(artist.test, None)
예제 #4
0
파일: test_rating.py 프로젝트: pscn/ads
  def testRatingClear(self):
    Factories.clear()
    rating = RatingFactory.get(0.7)
    rating.test = self.rating_test

    Factories.clear()
    rating = RatingFactory.get(0.7)
    self.assertNotEqual(rating.test, self.rating_test)
예제 #5
0
파일: test_file.py 프로젝트: pscn/ads
 def testFileTrack(self):
   Factories.clear()
   file1 = FileFactory.get(self.path, self.artist, self.title)
   file2 = FileFactory.get(self.path2, self.artist, self.title)
   found = 0
   for f in file1.track.files():
     found += 1
   self.assertEqual(found, 2)
예제 #6
0
파일: test_file.py 프로젝트: pscn/ads
  def testFileClear(self):
    Factories.clear()
    file = FileFactory.get(self.path, self.artist, self.title)
    file.test = self.file_test
    self.assertEqual(file.test, self.file_test)

    Factories.clear()
    file = FileFactory.get(self.path, self.artist, self.title)
    self.assertEqual(file.test, None)
예제 #7
0
파일: test_track.py 프로젝트: pscn/ads
  def testTrackClear(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    track.test = self.track_test
    self.assertEqual(track.test, self.track_test)

    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    self.assertEqual(track.test, None)
예제 #8
0
 def testArtistRelationRef(self):
   # test if 2 calls to the same artist return the same reference
   Factories.clear()
   artistA = ArtistFactory.get(self.artistA)
   artistB = ArtistFactory.get(self.artistB)
   artist_relationA = ArtistRelationFactory.get(artistA, artistB)
   artist_relationA.test = self.artist_relation_test
   artist_relationB = ArtistRelationFactory.get(artistA, artistB)
   self.assertEqual(artist_relationA.test, artist_relationB.test)
예제 #9
0
파일: test_track.py 프로젝트: pscn/ads
  def testTrack(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    track.test = self.track_test
    track.artist.test = self.artist_test

    self.assertEqual(track.title, self.title)
    self.assertEqual(track.test, self.track_test)
    self.assertEqual(track.artist.name, self.artist)
    self.assertEqual(track.artist.test, self.artist_test)
예제 #10
0
  def testRatingClear(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    track.played()
    track.skipped()

    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    self.assertEqual(track.ratingref.playcount, 0)
    self.assertEqual(track.ratingref.skipcount, 0)
예제 #11
0
  def testArtistRatingClear(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.titleA)
    track.played()
    track.skipped()

    Factories.clear()
    track = TrackFactory.get(self.artist, self.titleA)
    artist = track.artist
    self.assertEqual(artist.rating, 0.5)
예제 #12
0
파일: test_artist.py 프로젝트: pscn/ads
  def testArtistPickle(self):
    Factories.clear()
    artist = ArtistFactory.get(self.artist)
    artist.test = self.artist_test
    state = pickle.dumps(Factories.getstate())

    Factories.clear()
    pickle.loads(state)
    artist = ArtistFactory.get(self.artist)

    self.assertEqual(artist.test, self.artist_test)
예제 #13
0
 def testArtistRelation(self):
   Factories.clear()
   artistA = ArtistFactory.get(self.artistA)
   artistA.test = self.artistA_test
   artistB = ArtistFactory.get(self.artistB)
   artistB.test = self.artistB_test
   artist_relation = ArtistRelationFactory.get(artistA, artistB)
   artist_relation.test = self.artist_relation_test
   self.assertEqual(artist_relation.artistA.test, self.artistA_test)
   self.assertEqual(artist_relation.artistB.test, self.artistB_test)
   self.assertEqual(artist_relation.test, self.artist_relation_test)
예제 #14
0
 def testArtistRating(self):
   Factories.clear()
   track = TrackFactory.get(self.artist, self.titleA)
   track.ratingref.mix = 1.0
   artist = track.artist
   artist.ratingref.mix = 1.0
   artist.ratingfactor = 1.0
   track.played()
   self.assertNotEqual(track.rating, 0.5)
   self.assertNotEqual(artist.rating, 0.5)
   track.skipped()
   self.assertEqual(track.rating, 0.5)
   self.assertEqual(artist.rating, 0.5)
예제 #15
0
파일: test_file.py 프로젝트: pscn/ads
  def testFile(self):
    Factories.clear()
    file = FileFactory.get(self.path, self.artist, self.title)
    file.test = self.file_test
    file.track.test = self.track_test
    file.track.artist.test = self.artist_test

    self.assertEqual(file.path, self.path)
    self.assertEqual(file.track.artist.name, self.artist)
    self.assertEqual(file.track.title, self.title)
    self.assertEqual(file.test, self.file_test)
    self.assertEqual(file.track.test, self.track_test)
    self.assertEqual(file.track.artist.test, self.artist_test)
예제 #16
0
 def testRatingRef(self):
   Factories.clear()
   track = TrackFactory.get(self.artist, self.title)
   track1 = TrackFactory.get(self.artist, self.title)
   track.played()
   track.skipped()
   self.assertEqual(track1.ratingref.stable, 0.5)
   track.played(0.5)
   track.skipped(0.5)
   self.assertEqual(track1.ratingref.playcount, 1)
   self.assertEqual(track1.ratingref.skipcount, 1)
   self.assertEqual(track1.ratingref.playfactor, 1.5)
   self.assertEqual(track1.ratingref.skipfactor, 1.5)
예제 #17
0
파일: test_track.py 프로젝트: pscn/ads
  def testTrackPickle(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    track.test = self.track_test
    track.artist.test = self.artist_test

    state = pickle.dumps(Factories.getstate())
    Factories.clear()
    pickle.loads(state)

    self.assertEqual(track.title, self.title)
    self.assertEqual(track.test, self.track_test)
    self.assertEqual(track.artist.name, self.artist)
    self.assertEqual(track.artist.test, self.artist_test)
예제 #18
0
파일: library.py 프로젝트: pscn/ads
 def load(self, locked=False):
   if not path.exists(self._library_filename):
     self._logger.info(u"not loading: %s not found" % self._library_filename)
   else:
     if not locked: self.acquire()
     self._logger.info(u"loading from %s" % self._library_filename)
     Factories.clear()
     try:
       timestamp = datetime.utcnow()
       input = open(self._library_filename, 'rb')
       Factories.load(input)
       self._client_data = pickle.load(input)
       input.close()
       self._logger.info(u"loading took %s" % ( (datetime.utcnow() - timestamp)))
       self.dump_stats()
     except IOError:
       self._logger.error('IOError')
       self._logger.error(format_exc())
     except EOFError:
       self._logger.error('EOFError')
       self._logger.error(format_exc())
       Factories.clear()
     except AttributeError:
       self._logger.error('AttributeError: Format changed?')
       self._logger.error(format_exc())
       Factories.clear()
     if not locked: self.release()
예제 #19
0
 def testRatingRef2(self):
   Factories.clear()
   track = TrackFactory.get(self.artist, self.title)
   track2 = TrackFactory.get(self.artist2, self.title2)
   track.played()
   track.skipped()
   track.played(0.5)
   track.skipped(0.5)
   track.ratingref.test = self.rating_test
   track2.played()
   track2.skipped()
   track2.played(0.5)
   self.assertNotEqual(track.ratingref.test, track2.ratingref.test)
   track2.skipped(0.5)
   self.assertEqual(track.ratingref.test, track2.ratingref.test)
예제 #20
0
  def testArtistRelationPickle(self):
    Factories.clear()
    artistA = ArtistFactory.get(self.artistA)
    artistB = ArtistFactory.get(self.artistB)
    artist_relation = ArtistRelationFactory.get(artistA, artistB)
    artist_relation.test = self.artist_relation_test

    state = pickle.dumps(Factories.getstate())
    Factories.clear()
    pickle.loads(state)

    artistA = ArtistFactory.get(self.artistA)
    artistB = ArtistFactory.get(self.artistB)
    artist_relation = ArtistRelationFactory.get(artistA, artistB)
    artist_relation.test = self.artist_relation_test
    self.assertEqual(artist_relation.test, self.artist_relation_test)
예제 #21
0
  def testRatingPickle(self):
    Factories.clear()
    track = TrackFactory.get(self.artist, self.title)
    track.played()
    track.skipped()
    track.played(0.5)
    track.skipped(0.5)
    track.ratingref.test = self.rating_test

    state = pickle.dumps(Factories.getstate())
    Factories.clear()
    pickle.loads(state)

    track = TrackFactory.get(self.artist, self.title)
    self.assertEqual(track.ratingref.playcount, 1)
    self.assertEqual(track.ratingref.skipcount, 1)
    self.assertEqual(track.ratingref.playfactor, 1.5)
    self.assertEqual(track.ratingref.skipfactor, 1.5)
    self.assertEqual(track.ratingref.test, self.rating_test)
예제 #22
0
파일: library.py 프로젝트: pscn/ads
 def _save(self):
   self.acquire()
   self._logger.info(u"saving %s~" % self._library_filename)
   level = -1 # -1 for latest method, 0 for ascii
   timestamp = datetime.utcnow()
   output = open(u"%s~" % self._library_filename, 'wb')
   Factories.dump(output, level)
   pickle.dump(self._client_data, output, level)
   output.close()
   self._logger.info(u"saved %s~" % self._library_filename)
   if path.exists(self._library_filename):
     try:
       self._logger.info(u"removing %s" % self._library_filename)
       remove(self._library_filename)
     except OSError:
       self._logger.error('OSError')
       self._logger.error(format_exc())
   self._logger.info(u"moving %s~ to %s" % (self._library_filename,
       self._library_filename))
   rename(u"%s~" % self._library_filename, self._library_filename)
   self._logger.info(u"saving took %s" % ( (datetime.utcnow() - timestamp)))
   # save configuration
   self._config.save()
   self.release()
예제 #23
0
파일: test_file.py 프로젝트: pscn/ads
  def testFilePickle(self):
    Factories.clear()
    file = FileFactory.get(self.path, self.artist, self.title)
    file.test = self.file_test
    file.track.test = self.track_test
    file.track.artist.test = self.artist_test

    state = pickle.dumps(Factories.getstate())

    Factories.clear()
    file = FileFactory.get(self.path, self.artist, self.title)

    Factories.clear()
    pickle.loads(state)

    file = FileFactory.get(self.path, self.artist, self.title)
    self.assertEqual(file.path, self.path)
    self.assertEqual(file.track.artist.name, self.artist)
    self.assertEqual(file.track.title, self.title)
    self.assertEqual(file.test, self.file_test)
    self.assertEqual(file.track.test, self.track_test)
    self.assertEqual(file.track.artist.test, self.artist_test)
예제 #24
0
파일: test_rating.py 프로젝트: pscn/ads
  def testRating(self):
    Factories.clear()
    """ test init """
    rating = RatingFactory.get(0.7)
    rating.test = "init"
    self.assertEqual(rating.playcount, 0)
    self.assertEqual(rating.skipcount, 0)
    self.assertEqual(rating.playfactor, 0)
    self.assertEqual(rating.skipfactor, 0)
    self.assertEqual(rating.rating, 0.5)

    """ test update A """
    ratingA = rating.played()
    ratingA.test = "A"
    """ verify old """
    self.assertEqual(rating.playcount, 0)
    self.assertEqual(rating.skipcount, 0)
    self.assertEqual(rating.playfactor, 0)
    self.assertEqual(rating.skipfactor, 0)
    self.assertEqual(rating.rating, 0.5)
    """ verify new """
    self.assertEqual(ratingA.playcount, 1)
    self.assertEqual(ratingA.skipcount, 0)
    self.assertEqual(ratingA.playfactor, 1.0)
    self.assertEqual(ratingA.skipfactor, 0)

    """ test update B """
    ratingB = ratingA.skipped()
    ratingB.test = "B"
    """ verify old """
    self.assertEqual(ratingA.playcount, 1)
    self.assertEqual(ratingA.skipcount, 0)
    self.assertEqual(ratingA.playfactor, 1.0)
    self.assertEqual(ratingA.skipfactor, 0)
    """ verify new """
    self.assertEqual(ratingB.playcount, 1)
    self.assertEqual(ratingB.skipcount, 1)
    self.assertEqual(ratingB.playfactor, 1.0)
    self.assertEqual(ratingB.skipfactor, 1.0)
    self.assertEqual(ratingB.stable, 0.5)

    """ test update C """
    ratingC = ratingB.played(0.5)
    ratingC.test = "C"
    """ verify old """
    self.assertEqual(ratingB.playcount, 1)
    self.assertEqual(ratingB.skipcount, 1)
    self.assertEqual(ratingB.playfactor, 1.0)
    self.assertEqual(ratingB.skipfactor, 1.0)
    self.assertEqual(ratingB.stable, 0.5)
    """ verify new """
    self.assertEqual(ratingC.playcount, 1)
    self.assertEqual(ratingC.skipcount, 1)
    self.assertEqual(ratingC.playfactor, 1.5)
    self.assertEqual(ratingC.skipfactor, 1.0)

    ratingD = ratingC.skipped(0.5)
    ratingD.test = "D"
    """ verify old """
    self.assertEqual(ratingC.playcount, 1)
    self.assertEqual(ratingC.skipcount, 1)
    self.assertEqual(ratingC.playfactor, 1.5)
    self.assertEqual(ratingC.skipfactor, 1.0)
    """ verify new """
    self.assertEqual(ratingD.playcount, 1)
    self.assertEqual(ratingD.skipcount, 1)
    self.assertEqual(ratingD.playfactor, 1.5)
    self.assertEqual(ratingD.skipfactor, 1.5)
    self.assertEqual(ratingD.stable, 0.5)

    """ references """
    ratingE = RatingFactory.get(ratingD.mix, ratingD.slope, ratingD.playcount,
        ratingD.playfactor, ratingD.skipcount, ratingD.skipfactor,
        ratingD.rating, ratingD.rolling, ratingD.stable)
    self.assertEqual(ratingE.test, ratingD.test)

    ratingF = RatingFactory.by_key(ratingD.key())
    self.assertEqual(ratingD.test, ratingF.test)
예제 #25
0
파일: test_artist.py 프로젝트: pscn/ads
 def testArtist(self):
   Factories.clear()
   artist = ArtistFactory.get(self.artist)
   artist.test = self.artist_test
   self.assertEqual(artist.name, self.artist)
   self.assertEqual(artist.test, self.artist_test)
예제 #26
0
파일: library.py 프로젝트: pscn/ads
  def __init__(self, config):
    Log.__init__(self, self._title)
    self._logger.info(u"init")
    Worker.__init__(self, lifo=False)
    self._config = config
    self._library_filename = self._config.get('Library', 'path',
        join(self._config.configdir(), 'library.pkl'))
    Factories.clear()
    Logger.set_logger(self._logger)

    if self._config.get('TrackRelation', 'use_db', True):
      TrackRelationFactory.use_db()
      TrackRelationFactory.set_path(self._config.get('TrackRelation',
          'path', join(self._config.configdir(), '')))
    else:
      TrackRelationFactory.use_fs()
      TrackRelationFactory.set_path(self._config.get('TrackRelation',
          'path', join(self._config.configdir(), 'track')))
    TrackRelationFactory.set_maxentries(
        self._config.get('TrackRelation', 'maxentries', 500))

    if self._config.get('ArtistRelation', 'use_db', True):
      ArtistRelationFactory.use_db()
      ArtistRelationFactory.set_path(self._config.get('ArtistRelation',
          'path', join(self._config.configdir(), '')))
    else:
      ArtistRelationFactory.use_fs()
      ArtistRelationFactory.set_path(self._config.get('ArtistRelation',
          'path', join(self._config.configdir(), 'artist')))
    ArtistRelationFactory.set_maxentries(
        self._config.get('ArtistRelation', 'maxentries', 500))

    if self._config.get('Lookup', 'QueueResults', 'False') == 'True':
      self._queue_lookup_results = True
    else:
      self._queue_lookup_results = False

    # FIXME:  log if one of those libs is not present
    if self._config.get('Lookup', 'UseLastFM', 'True') == 'True':
      self._lastfm = LastFM(config)
      self._lastfm.start()
      self._thres_lastfm_lookup = self._config.getint('Lookup',
          'ThresholdLastFM', self._thres_lastfm_lookup)

    if self._config.get('Lookup', 'UseEchoNest', 'True') == 'True':
      self._echonest = EchoNest(config)
      self._echonest.start()
      self._thres_echonest_lookup = self._config.getint('Lookup',
          'ThresholdEchoNest', self._thres_echonest_lookup)

    # read, normalize and update ranking factors
    factor = 0.0
    for k in self._factor_ranking.keys():
      self._factor_ranking[k] = self._config.getfloat('Ranking',
          "factor%s" % k, self._factor_ranking[k])
      factor += self._factor_ranking[k]
    for k in self._factor_ranking.keys():
      self._factor_ranking[k] /= factor
      self._config.set('Ranking', "factor%s" % k, self._factor_ranking[k])

    self._relation_decay = self._config.getfloat('Ranking', 'RelationDecay',
        self._relation_decay)

    self._queue_update_factor = self._config.getfloat('Rating',
        'QueueUpdateFactor', self._queue_update_factor)

    self._unplayed_rating = self._config.getfloat('Ranking',
        'UnplayedRating', self._unplayed_rating)

    self._thres_track_lastplayed = self._config.getint('Ranking',
        'ThresholdTrackLastPlayed', self._thres_track_lastplayed)
    self._thres_track_laststarted= self._config.getint('Ranking',
        'ThresholdTrackLastStarted', self._thres_track_laststarted)
    self._thres_track_lastqueued= self._config.getint('Ranking',
        'ThresholdTrackLastQueued', self._thres_track_lastqueued)
    self._thres_artist_lastplayed = self._config.getint('Ranking',
        'ThresholdArtistLastPlayed', self._thres_artist_lastplayed)
    self._thres_artist_laststarted= self._config.getint('Ranking',
        'ThresholdArtistLastStarted', self._thres_artist_laststarted)
    self._thres_artist_lastqueued= self._config.getint('Ranking',
        'ThresholdArtistLastQueued', self._thres_artist_lastqueued)