def test_secondary(self): score = ContentRetriever.computeInitialScore(isPrimeMatch=False,\ numSecond=2, \ views=0, \ comments=0, \ favs=0) self.assertEqual(2 * ContentRetriever.SECOND_SCORE, score)
def test_view(self): score = ContentRetriever.computeInitialScore(isPrimeMatch=False,\ numSecond=0, \ views=100, \ comments=0, \ favs=0) self.assertEqual(ContentRetriever.VIEW_SCORE_ONE, score)
def test_primary(self): score = ContentRetriever.computeInitialScore(isPrimeMatch=True,\ numSecond=0, \ views=0, \ comments=0, \ favs=0) self.assertEqual(ContentRetriever.PRIME_SCORE, score)
def test_inputcase(self): score = ContentRetriever.computeInitialScore(isPrimeMatch=False,\ numSecond='5', \ views=99, \ comments='10', \ favs=51) expected = 4 * ContentRetriever.SECOND_SCORE + \ ContentRetriever.VIEW_SCORE_ONE + \ ContentRetriever.FAV_SCORE_ONE self.assertEqual(expected, score)
def test_anothernormalcase(self): score = ContentRetriever.computeInitialScore(isPrimeMatch=True,\ numSecond=2, \ views=99, \ comments=10, \ favs=51) expected = ContentRetriever.PRIME_SCORE + \ 2 * ContentRetriever.SECOND_SCORE + \ ContentRetriever.VIEW_SCORE_ONE + \ ContentRetriever.FAV_SCORE_ONE self.assertEqual(expected, score)
def computeVideoScore(entry, mood): prime_term = getPrimeTerm(mood) sec_terms = getSecTerm(mood) entryid = _parseId(entry) comment_feed = None num_comments = 0 try: comment_feed = yt.GetYouTubeVideoCommentFeed(video_id=entryid) num_comments = len(comment_feed.entry) except Exception: print 'no comments' num_views = 0 try: num_views = entry.statistics.view_count except Exception: print 'no views' num_favs = 0 try: num_favs = entry.statistics.favorite_count except Exception: print 'no fav' title = entry.title.text des = entry.media.description.text des = des if des != None else '' isPrimeMatch = prime_term in title num_sec = 0 for term in sec_terms: if term in title or term in des: num_sec += 1 initial_score = \ ContentRetriever.computeInitialScore(isPicture=False, \ isPrimeMatch=isPrimeMatch, \ numSecond = num_sec, \ views=num_views, \ comments=num_comments, \ favs=num_favs) return initial_score
def computePictureScore(pid, mood): prime_term = getPrimeTerm(mood) sec_terms = getSecTerm(mood) photo = flickr.photos_getInfo(photo_id=pid) attrib = photo[0].attrib num_views = attrib['views'] num_favs = attrib['isfavorite'] comments = flickr.photos_comments_getList(photo_id=pid) com = comments[0] num_comments = len(com) pic = photo[0] num_sec = 0 isPrimeMatch = False for tag in pic.find('tags'): if tag.attrib['raw'] == prime_term: isPrimeMatch = True for sec_term in sec_terms: if (sec_term == tag.attrib['raw']): num_sec = num_sec + 1 initial_score = \ ContentRetriever.computeInitialScore(isPrimeMatch=isPrimeMatch,\ numSecond=num_sec, \ views=num_views, \ comments=num_comments, \ favs=num_favs) '''print 'score = ' + str(initial_score) + \ ', pm: ' + str(isPrimeMatch) + \ ', sec: ' + str(num_sec) + \ ', view: ' + str(num_views) + \ ', com: ' + str(num_comments) + \ ', fav: ' + str(num_favs) ''' return initial_score