Пример #1
0
    def read_csv_file(self):
        with open(self.__file_name, mode='r', encoding='utf-8-sig') as csvfile:
            movie_file_reader = csv.DictReader(csvfile)
            index = 0
            for row in movie_file_reader:
                movie = Movie(row["Title"], int(row["Year"]))
                movie.description = row["Description"]
                movie.runtime_minutes = int(row["Runtime (Minutes)"])
                self.__total_runtime_minutes += int(row["Runtime (Minutes)"])
                self.__runtime_minutes_number_of_movies += 1
                if row["Rating"] != "N/A":
                    movie.rating = float(row['Rating'])
                    self.__total_rating += float(row['Rating'])
                    self.__rating_number_of_movies += 1
                if row["Votes"] != "N/A":
                    movie.votes = int(row["Votes"])
                    self.__total_votes += int(row["Votes"])
                    self.__votes_number_of_movies += 1
                if row["Revenue (Millions)"] != "N/A":
                    movie.revenue_millions = float(row["Revenue (Millions)"])
                    self.__total_revenue_millions += float(
                        row["Revenue (Millions)"])
                    self.__revenue_millions_number_of_movies += 1
                if row["Metascore"] != "N/A":
                    movie.metascore = int(row["Metascore"])
                    self.__total_metascore += int(row["Metascore"])
                    self.__metascore_number_of_movies += 1

                self.__dataset_of_movies.append(movie)
                self.__dataset_of_directors.add(Director(row["Director"]))
                for actor in row["Actors"].split(","):
                    self.__dataset_of_actors.add(Actor(actor.strip()))
                for genre in row["Genre"].split(","):
                    self.__dataset_of_genres.add(Genre(genre.strip()))
                index += 1
Пример #2
0
def parseMoviesAndRatings():
    inputFile = open("../dataset/movie_rating.txt")    
    lineString = inputFile.readline()
    movieRatingVector = np.zeros(0)
    global missing_count
        
    while(lineString):
        (movie_title,movie_year) = Movie.separateTitleAndYear(lineString.split("\t\t")[0].strip())
        movie_rating = float(lineString.split("\t\t")[1].strip())        
        
        if(not movie_title in Movie.hashByTitle):
            movie = Movie(movie_title,rating=movie_rating)
            missing_count = missing_count + 1
        else:    
            movie = Movie.hashByTitle[movie_title]
        
        movie.rating = movie_rating
        
        movieRatingVector = np.append(movieRatingVector,movie_rating)
        
        lineString = inputFile.readline()     
                
        if(movie.id%100000 == 0):
            print movie      
    
    arrayToSave = np.asarray(movieRatingVector)
    np.savetxt("./movie_rating_vector.csv", arrayToSave, delimiter=",")
def test_rating_out_bounds_upper(movie):
    movie = Movie("Moana", 2016)
    with pytest.raises(ValueError):
        movie.rating = 10.5
def test_rating_type(movie):
    movie = Movie("Moana", 2016)
    with pytest.raises(ValueError):
        movie.rating = "banana"
def test_rating(movie):
    movie = Movie("Moana", 2016)
    movie.rating = 9.5
    assert movie.rating == 9.5