Example #1
0
def prepare_recommend_thread(mongo, mid_list, thread_num):
    print("[prepare_recommend_thread] Starting prepare recommendations...")
    startTime = time.time()

    recommend = MovieRecommend(mongo)
    progressTotal = int(34208 / thread_num) + 1
    count = 0
    bulkSize = 100             # How many documents should we store in memory before inserting them into the database in bulk?
    # List of documents that will be given to the database to be inserted to the collection in bulk.
    bulkPayload = pymongo.bulk.BulkOperationBuilder(mongo.db["movie"], ordered = False)
    skipCount = 0

    for cur_mid in mid_list:
        count += 1
        print("[prepare_recommend_thread] %5d movies processed so far. (%d%%) (%0.2fs)" % (count, int(count * 100 / progressTotal), time.time() - startTime))
        similar_movies = recommend.recommend_movies_for_movie(cur_mid)
        bulkPayload.find({"mid": cur_mid}).update({"$set": {
            "similar_movies": similar_movies
            }})

        if count % bulkSize == 0:
            try:
                bulkPayload.execute()
            except pymongo.errors.OperationFailure as e:
                skipCount += len(e.details["writeErrors"])
            bulkPayload = pymongo.bulk.BulkOperationBuilder(mongo.db["movie"], ordered = False)
    if count % bulkSize > 0:
        try:
            bulkPayload.execute()
        except pymongo.errors.OperationFailure as e:
            skipCount += len(e.details["writeErrors"])

    print("[prepare_recommend_thread] Done.")
Example #2
0
    def process_tag_recommendation(self):
        print(self.historyList[TAG_MODE])

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_based_on_tags_integrated(
            self.historyList[TAG_MODE])
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])
        self.recommendations_screen(recommendations)
Example #3
0
    def process_twitter_recommendation(self, usernameWidget):
        username = usernameWidget.get()
        print(username)

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_for_twitter_integrated(
            username)
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])
        self.recommendations_screen(recommendations)
Example #4
0
    def process_movie_history_recommendation(self):
        print(self.historyList[MOVIE_MODE])

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_based_on_history(
            self.historyList[MOVIE_MODE])
        all_recommendations = recommender.get_titles_by_mids(
            all_recommendations)
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])
        self.recommendations_screen(recommendations)
Example #5
0
    def process_popular_movies(self):
        result = ""

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_based_on_popularity(
        )
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])

        # Process obtained recommendations
        print("\n\nFound Most popular movies ")
        print(recommendations)

        for rec in recommendations:
            result += self.preprocess(rec)
            result += ", "
        return result
Example #6
0
    def process_tag_recommendation(self, tag_list):
        print(tag_list)
        result = ""

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_based_on_tags_integrated(
            tag_list)
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])

        # Process obtained recommendations
        print("\n\nFound recommendations from Tags: ")
        print(recommendations)

        for rec in recommendations:
            result += self.preprocess(rec)
            result += ", "
        return result
Example #7
0
    def process_twitter_recommendation(self, username):
        print(username)

        recommendations = []
        result = ""
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_for_twitter_integrated(
            username)
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])

        # Process obtained recommendations
        print("\n\nFound recommendations from Twitter: ")
        print(recommendations)

        for rec in recommendations:
            result += self.preprocess(rec)
            result += ", "
        return result
Example #8
0
    def process_movie_history_recommendation(self, movie_history_list):
        print(movie_history_list)
        result = ""

        recommendations = []
        recommender = MovieRecommend(self.mongo)
        all_recommendations = recommender.recommend_movies_based_on_history(
            movie_history_list)
        all_recommendations = recommender.get_titles_by_mids(
            all_recommendations)
        total = min(5, len(all_recommendations))
        for i in range(total):
            recommendations.append(all_recommendations[i])

        # Process obtained recommendations
        print("\n\nFound recommendations from Movie History: ")
        print(recommendations)

        for rec in recommendations:
            result += self.preprocess(rec)
            result += ", "
        return result