Exemple #1
0
def get_top_scored_movies(number_of_movies):
    top_scored_movies = []
    session = Session()
    top_scores = session.query(AverageMovieRating).order_by(
        AverageMovieRating.average_rating.desc()).limit(number_of_movies)

    for instance in top_scores:
        movie = session.query(Movies).filter(
            Movies.movie_id == instance.movie_id).first()
        top_scored_movies.append(movie)
    return top_scored_movies
def calculate_and_save_global_average_rating():
    session = Session()
    # calculate average rating from table ratings
    global_average_rating = round(
        session.query(Ratings).value(func.avg(Ratings.rating)), 3)
    # Save average_rating to DB
    save_parameter("average_rating", global_average_rating)
    return global_average_rating
def save_parameter(description, value):
    session = Session()
    management = session.query(Management).filter(
        Management.description == description).first()
    if management is None:
        management = Management(description, value)
    else:
        management.value = value
    session.add(management)
    # commit the record the database
    session.commit()
Exemple #4
0
import sys
import csv

import numpy as np
import progressbar

from dataAccess import Session, Ratings

session = Session()
# Remove limit to use all ratings
ratings_list = session.query(Ratings).limit(10000).all()

user_to_index = {}
for rating in ratings_list:
    if rating.user_id not in user_to_index:
        user_to_index[rating.user_id] = len(user_to_index)

movie_to_index = {}
for rating in ratings_list:
    if rating.movie_id not in movie_to_index:
        movie_to_index[rating.movie_id] = len(movie_to_index)


class Residual:

    __slots__ = ('value', 'current_error', 'prev_error')

    def __init__(self, value, current_error, prev_error):
        self.value = value
        self.current_error = current_error
        self.prev_error = prev_error
import sys

import numpy as np
import progressbar

from dataAccess import Session, Ratings
from dataAccess.entities import RatingsPredictionsBySVD, Sample

session = Session()

session.query(RatingsPredictionsBySVD).delete()
session.commit()

# Remove limit to use all ratings
ratings_list = session.query(Ratings).limit(1000).all()
# ratings_list = session.query(Ratings).all()
samples = session.query(Sample).all()

user_to_index = {}
movie_to_index = {}

for rating in ratings_list:
    if rating.user_id not in user_to_index:
        user_to_index[rating.user_id] = len(user_to_index)
    if rating.movie_id not in movie_to_index:
        movie_to_index[rating.movie_id] = len(movie_to_index)

for sample in samples:
    if sample.user_id not in user_to_index:
        user_to_index[sample.user_id] = len(user_to_index)
    if sample.movie_id not in movie_to_index:
def get_parameter(description):
    session = Session()
    return session.query(Management).filter(
        Management.description == description).first()
Exemple #7
0
def clear_users_similarity_table():
    session = Session()
    session.query(UsersSimilarity).delete()
    session.commit()
Exemple #8
0
def clear_rating_predictions_table():
    session = Session()
    session.query(RatingsPredictions).delete()
    session.commit()
Exemple #9
0
import sys

import numpy as np
import progressbar

from dataAccess import Session, Ratings
from dataAccess.entities import RatingsPredictionsBySVD

session = Session()
# Remove limit to use all ratings
# ratings_list = session.query(Ratings).limit(1000).all()
ratings_list = session.query(Ratings).all()
session.query(RatingsPredictionsBySVD).delete()
session.commit()

user_to_index = {}
for rating in ratings_list:
    if rating.user_id not in user_to_index:
        user_to_index[rating.user_id] = len(user_to_index)

movie_to_index = {}
for rating in ratings_list:
    if rating.movie_id not in movie_to_index:
        movie_to_index[rating.movie_id] = len(movie_to_index)


class Residual:

    __slots__ = ('value', 'current_error', 'prev_error')

    def __init__(self, value, current_error, prev_error):
Exemple #10
0
def clear_average_rating_table():
    session = Session()
    session.query(AverageMovieRating).delete()
    session.commit()