示例#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_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)
示例#3
0
 def __init__(self, trackA, trackB):
   self.trackA = trackA
   self.trackB = trackB
   self.ratingref = RatingFactory.get(0.7, 1.0)
   self.artistRelation = ArtistRelationFactory.get(trackA.artist, trackB.artist)
   self.lastused = now()
   TrackRelationFactory.save(self)
示例#4
0
文件: track.py 项目: pscn/ads
 def __setstate__(self, dict):
   # Logger.info(u"track dict in: %s" % dict)
   artist = ArtistFactory.by_key(dict['artist_key'])
   del dict['artist_key']
   ratingref = RatingFactory.by_key(dict['ratingref_key'])
   del dict['ratingref_key']
   self.__dict__ = dict
   self.artist = artist
   self.ratingref = ratingref
   # Logger.info(u"track.dict out: %s" % self.__dict__)
   TrackFactory.register(self)
示例#5
0
 def __setstate__(self, dict):
   trackA = TrackFactory.by_key(dict['trackA_key'])
   del dict['trackA_key']
   trackB = TrackFactory.by_key(dict['trackB_key'])
   del dict['trackB_key']
   ratingref = RatingFactory.by_key(dict['ratingref_key'])
   del dict['ratingref_key']
   self.__dict__ = dict
   self.trackA = trackA
   self.trackB = trackB
   self.ratingref = ratingref
示例#6
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)
示例#7
0
文件: track.py 项目: pscn/ads
 def __init__(self, artist_name, track_title):
   self.artist = ArtistFactory.get(artist_name)
   self.title = track_title
   self.ratingref = RatingFactory.get(0.6, 0.1)
   self.rating = self.ratingref.rating