Example #1
0
    def get_top_movies(self, top_x, min_ratings):
        movie_rows_list = Movie.read_movie_file()

        movie_list_with_min_ratings = []
        for movie in movie_rows_list:
            movie_id = movie[0]
            movie_name = movie[1]

            ratings_list = self.get_movie_rating_list(movie_id)
            # print("movie_id", movie_id)
            # print("ratings", ratings_list)

            if len(ratings_list) >= min_ratings:
                movie_avg_tup = (movie_id, movie_name, self.get_avg_rating(movie_id))
                movie_list_with_min_ratings.append(movie_avg_tup)

        sorted_list = sorted(movie_list_with_min_ratings, key = lambda x: x[2])
        reversed_list = list(reversed(sorted_list))
        # print(sorted_list)
        # print(reversed_list)

        top_x_list = reversed_list[:top_x]
        #print(top_x_list)

        return top_x_list