Ejemplo n.º 1
0
 def put(movie_id, title, author, release_year):
     """ Update a movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(movie_id=movie_id,
                               title=title,
                               author=author,
                               release_year=release_year)
     return jsonify({"movie": movie.json})
Ejemplo n.º 2
0
 def put(name, genre, year, affiche):
     """ Update an movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(name=name,
                               genre=genre,
                               year=year,
                               affiche=affiche)
     return jsonify({"movie": movie.json})
Ejemplo n.º 3
0
 def put(title, director, original_language, type, date):
     """ Update a movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(title=title,
                               director=director,
                               original_language=original_language,
                               type=type,
                               date=date)
     return jsonify({"movie": movie.json})
Ejemplo n.º 4
0
 def put(key, title, director, date, genre):
     """ Update a movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(key=key,
                               title=title,
                               director=director,
                               date=date,
                               genre=genre)
     return jsonify({"movie": movie.json})
Ejemplo n.º 5
0
 def put(title, author, length, genre, image, note):
     """ Update an movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(title=title,
                               author=author,
                               length=length,
                               genre=genre,
                               image=image,
                               note=note)
     return jsonify({"movie": movie.json})
Ejemplo n.º 6
0
 def post(name, genre, year, affiche):
     """ Create an movie based on the sent information """
     movie = MovieRepository.create(name=name,
                                    genre=genre,
                                    year=year,
                                    affiche=affiche)
     return jsonify({"movie": movie.json})
Ejemplo n.º 7
0
 def post(key, title, director, date, genre):
     """ Create a movie based on the sent information """
     movie = MovieRepository.create(key=key,
                                    title=title,
                                    director=director,
                                    date=date,
                                    genre=genre)
     return jsonify({"movie": movie.json})
Ejemplo n.º 8
0
 def post(title, author, length, genre, image, note):
     """ Create an movie based on the sent information """
     movie = MovieRepository.create(title=title,
                                    author=author,
                                    length=length,
                                    genre=genre,
                                    image=image,
                                    note=note)
     return jsonify({"movie": movie.json})
Ejemplo n.º 9
0
 def get():
     """ Return all movies in database """
     movies = [movie.json for movie in MovieRepository.get_all()]
     for movie in movies:
         movie["average_mark"] = MovieMeanResource.get(
             movie["movie_id"]).json["average_mark"]
     sorted_movies = sorted(movies,
                            key=lambda movie: movie["average_mark"],
                            reverse=True)
     return jsonify({"movies": sorted_movies})
Ejemplo n.º 10
0
    def get(key):
        """ Return a list of similar movies """
        movie = MovieRepository.getbykey(key)
        #return jsonify({"test":movie.json})

        users_who_rated = RateRepository.get_all_by_movie(key)
        keys_of_users_who_rated = [u.user_rating for u in users_who_rated]
        movies_were_rated = {}
        for user in users_who_rated:
            for m in RateRepository.get_all_by_user(user.user_rating):
                if m.movie_rated in movies_were_rated:
                    movies_were_rated[m.movie_rated].append(user.user_rating)
                else:
                    movies_were_rated[m.movie_rated] = [user.user_rating]
        sim = {}

        #return jsonify({movie:movie for movie in movies_were_rated})
        for m in movies_were_rated.keys():
            users = [
                u for u in movies_were_rated[m] if u in keys_of_users_who_rated
            ]
            sim[m] = sum(
                (RateRepository.get(user, movie.key).rating -
                 RateRepository.average_rating(movie.key)) *
                (RateRepository.get(user, m).rating -
                 RateRepository.average_rating(m)) for user in users) / prod([
                     math.sqrt(0.00001 +
                               (RateRepository.get(user, movie.key).rating -
                                RateRepository.average_rating(movie.key))**2 +
                               (RateRepository.get(user, m).rating -
                                RateRepository.average_rating(m))**2)
                     for user in users
                 ])
            print(sim[m])

        movies_to_be_returned = [
            MovieRepository.getbykey(m) for m in sim.keys() if sim[m] > .8
        ]

        return jsonify(
            {movie.key: movie.json
             for movie in movies_to_be_returned})
Ejemplo n.º 11
0
 def get(name):
     """ Return an movie key information based on his name """
     m = MovieRepository.get(name=name)
     d = {}
     d['name'] = m.name
     d['year'] = m.year
     d['genre'] = m.genre
     d['notes'] = 0
     d['affiche'] = m.affiche
     t = []
     for l in m.notes:
         t.append(l.note)
     if len(t) != 0:
         d['notes'] = sum(t) / len(t)
     else:
         d['notes'] = -1
     return (jsonify(d))
Ejemplo n.º 12
0
 def get(user_id):
     """ Return an user key information based on his id """
     user = UserRepository.get_from_id(user_id=user_id).json
     movie_ids = [
         mark.movie_id for mark in MarkRepository.get_from_user_id(
             user_id=user["user_id"])
     ]
     user["seen_movies"] = [
         MovieRepository.get(movie_id=movie_id).json
         for movie_id in movie_ids
     ]
     for movie in user["seen_movies"]:
         movie["mark"] = MarkRepository.get(
             movie_id=movie["movie_id"],
             user_id=user["user_id"]).json["note"]
         movie["average_mark"] = MovieMeanResource.get(
             movie_id=movie["movie_id"]).json["average_mark"]
     return jsonify({"user": user})
Ejemplo n.º 13
0
 def get():
     """ Return an movie key information based on his name """
     movie = MovieRepository.getAll()
     result = []
     for m in movie:
         d = {}
         d['name'] = m.name
         d['year'] = m.year
         d['genre'] = m.genre
         d['notes'] = 0
         d['affiche'] = m.affiche
         t = []
         for l in m.notes:
             t.append([l.note, l.username])
         c = 0
         if len(t) != 0:
             for i in t:
                 c += i[0]
             d['notes'] = c / len(t)
         else:
             d['notes'] = -1
         d['liste notes'] = t
         result.append((d))
     return (jsonify([l for l in result]))
Ejemplo n.º 14
0
 def post(title, producer, date, actor):
     """ Create a movie based on the sent information """
     movie = MovieRepository.create(
         title=title, producer=producer, date=date, actor=actor
     )
     return jsonify({"movie": movie.json})
Ejemplo n.º 15
0
 def post():
     """ Post the full database """
     movies = MovieRepository.post_all_db()
     return jsonify({"data":"The database was loaded correctfully"})
Ejemplo n.º 16
0
 def get():
     """ Return all movies """
     movies = MovieRepository.get_all()
     return [movie.json for movie in movies]
Ejemplo n.º 17
0
 def get(title):
     """ Return all movies """
     movies = MovieRepository.get_by_title(title)
     return jsonify({movie.title: movie.json for movie in movies})
Ejemplo n.º 18
0
 def get(movie_id):
     """ Return a movie key information based on its id """
     movie = MovieRepository.get(movie_id=movie_id).json
     movie["average_mark"] = MovieMeanResource.get(
         movie["movie_id"]).json["average_mark"]
     return jsonify({"movie": movie})
Ejemplo n.º 19
0
 def post(title, author, release_year):
     """ Create a movie based on the sent information """
     movie = MovieRepository.create(title=title,
                                    author=author,
                                    release_year=release_year)
     return jsonify({"movie": movie.json})
Ejemplo n.º 20
0
 def get(title):
     """ Return an movie key information based on his title """
     movie = MovieRepository.get(title=title)
     return jsonify({"movie": movie.json})
Ejemplo n.º 21
0
 def get(key):
     """ Return a movie key information based on its title """
     movie = MovieRepository.getbykey(key=key)
     return jsonify({"movie": movie.json})
Ejemplo n.º 22
0
 def put(title, producer, date, actor):
     """ Update a movie based on the sent information """
     repository = MovieRepository()
     movie = repository.update(title=title, producer=producer, date=date, actor=actor)
     return jsonify({"movie": movie.json})
Ejemplo n.º 23
0
 def get(title, director):
     """ Return a movie key information based on his name """
     movie = MovieRepository.get(title=title, director=director)
     return jsonify({"movie": movie.json})