def post_sounds_to_tagrecommendation_service(sound_qs): data_to_post = [] N_SOUNDS_PER_CALL = 10 total_calls = int(ceil(float(len(sound_qs)) / N_SOUNDS_PER_CALL)) print "Sending recommendation data..." idx = 1 for count, sound in enumerate(sound_qs): data_to_post.append( (sound.id, list( sound.tags.select_related("tag").values_list('tag__name', flat=True)))) if (count + 1) % N_SOUNDS_PER_CALL == 0: ids = [element[0] for element in data_to_post] tagss = [element[1] for element in data_to_post] print "\tSending group of sounds %i of %i (%i sounds)" % ( idx, total_calls, len(ids)) idx += 1 TagRecommendation.add_to_index(ids, tagss) data_to_post = [] if data_to_post: ids = [element[0] for element in data_to_post] tagss = [element[1] for element in data_to_post] print "\tSending group of sounds %i of %i (%i sounds)" % ( idx, total_calls, len(ids)) TagRecommendation.add_to_index(ids, tagss) print "Finished!"
def post_sounds_to_tagrecommendation_service(sound_qs): data_to_post = [] N_SOUNDS_PER_CALL = 10 total_calls = int(ceil(float(len(sound_qs))/N_SOUNDS_PER_CALL)) print "Sending recommendation data..." idx = 1 for count, sound in enumerate(sound_qs): data_to_post.append( (sound.id, list(sound.tags.select_related("tag").values_list('tag__name', flat=True))) ) if (count + 1) % N_SOUNDS_PER_CALL == 0: ids = [element[0] for element in data_to_post] tagss = [element[1] for element in data_to_post] print "\tSending group of sounds %i of %i (%i sounds)" % (idx, total_calls, len(ids)) idx += 1 TagRecommendation.add_to_index(ids, tagss) data_to_post = [] if data_to_post: ids = [element[0] for element in data_to_post] tagss = [element[1] for element in data_to_post] print "\tSending group of sounds %i of %i (%i sounds)" % (idx, total_calls, len(ids)) TagRecommendation.add_to_index(ids, tagss) print "Finished!"
def get_id_of_last_indexed_sound(): try: result = TagRecommendation.get_last_indexed_id() return result except Exception, e: return -1
def get_recommended_tags(input_tags, max_number_of_tags=30): cache_key = "recommended-tags-for-%s" % (",".join(sorted(input_tags))) # Don't use the cache when we're debugging if settings.DEBUG: recommended_tags = False else: try: recommended_tags = cache.get(cache_key) except: recommended_tags = False if not recommended_tags: try: recommended_tags = TagRecommendation.recommend_tags(input_tags) if not recommended_tags['tags']: recommended_tags['community'] = "-" try: cache.set(cache_key, recommended_tags, TAGRECOMMENDATION_CACHE_TIME) except: pass except Exception, e: logger.error('Could not get a response from the tagrecommendation service (%s)\n\t%s' % \ (e, traceback.format_exc())) recommended_tags = False
def get_recommended_tags(input_tags, max_number_of_tags=30): hashed_tags = md5(",".join(sorted(input_tags))) cache_key = "recommended-tags-for-%s" % (hashed_tags.hexdigest()) recommended_tags = False # Don't use the cache when we're debugging if not settings.DEBUG: recommended_tags = cache.get(cache_key) if not recommended_tags: recommended_tags = TagRecommendation.recommend_tags(input_tags) if not recommended_tags['tags']: recommended_tags['community'] = "-" cache.set(cache_key, recommended_tags, settings.TAGRECOMMENDATION_CACHE_TIME) return recommended_tags['tags'][:max_number_of_tags], recommended_tags['community']
def get_recommended_tags(input_tags, max_number_of_tags=30): hashed_tags = md5(",".join(sorted(input_tags))) cache_key = "recommended-tags-for-%s" % (hashed_tags.hexdigest()) recommended_tags = False # Don't use the cache when we're debugging if not settings.DEBUG: recommended_tags = cache.get(cache_key) if not recommended_tags: recommended_tags = TagRecommendation.recommend_tags(input_tags) if not recommended_tags['tags']: recommended_tags['community'] = "-" cache.set(cache_key, recommended_tags, TAGRECOMMENDATION_CACHE_TIME) return recommended_tags['tags'][:max_number_of_tags], recommended_tags['community']