def _populate_video_counters(videos): if not isinstance(videos, types.ListType): videos = [videos] counters = [] cnt_to_video = {} for video in videos: counters_map = VideoModels.counters_map(video) for (k, v) in counters_map.iteritems(): counters.append(k) cnt_to_video[k] = video results = fastcounter.get_counts(counters) for i in xrange(0, len(counters)): cntr = counters[i] video = cnt_to_video[cntr] counters_map = VideoModels.counters_map(video) video[counters_map[cntr]] = results[i]
def _score_videos(videos): for v in videos: v["final_score"] = VideoModels.score(v) return sorted(videos, key=lambda video: -video["final_score"])