def candidate_generator(movie):
    candidate_dict = dict()
    for genre in movie.genres:
        one_candidates = DataManager.get_instance().get_movies_by_genre(genre, 100, "rating")
        for candidate in one_candidates:
            candidate_dict[candidate.movieId] = candidate
    if movie.movieId in candidate_dict:
        del candidate_dict[movie.movieId]
    return candidate_dict.values()
def get_rec_list(movie_id: int, size: int, model: str):
    movie = DataManager.get_instance().get_movie_by_id(movie_id)
    if movie is None:
        return list()
    candidates = candidate_generator(movie)
    ranked_list = ranker(movie, candidates, model)

    if len(ranked_list) > size:
        return ranked_list[:size]
    return ranked_list
Example #3
0
def get_rec_list(user_id: int, size: int, model: str):
    user = DataManager.get_instance().get_user_by_id(user_id)
    if user is None:
        return list()
    CANDIDATE_SIZE = 800
    candiadtes = DataManager.get_instance().get_movies(CANDIDATE_SIZE,
                                                       "rating")

    if Config.EMB_DATA_SOURCE == Config.DATA_SOURCE_REDIS:
        user_emb_key = "uEmb:" + str(user_id)
        user_emb = RedisClient.get_instance().get(user_emb_key)
        if user_emb is not None:
            user.set_emb(Utility.parse_emb_str(user_emb))

    ranked_list = ranker(user, candiadtes, model)

    if len(ranked_list) > size:
        return ranked_list[:size]
    return ranked_list
def main(args):

    device, cuda = init_random_seeds(args.randomSeed, args.cuda, args.verbose)

    #######################################################################
    ########################## Init Logger ################################
    #######################################################################
    logger = Logger(conditional=args.cvae,
                    perceptual_loss=args.perceptualLoss)

    #######################################################################
    ############### Init data manager to handle data ######################
    #######################################################################
    data_manager = DataManager(dataset_type=args.datasetType,
                               batch_size=args.batchSize,
                               cuda=cuda,
                               verbose=args.verbose)

    #######################################################################
    ############### Init data manager to handle data ######################
    #######################################################################
    model_manager = ModelManager(conditional=args.cvae,
                                 perceptual_loss=args.perceptualLoss,
                                 num_labels=data_manager.get_num_labels(),
                                 dataset_type=args.datasetType,
                                 checkpoint_path=args.checkpointPath,
                                 device=device,
                                 verbose=args.verbose)

    #######################################################################
    ############### Init data manager to handle data ######################
    #######################################################################
    run_manager = RunManager(model_manager=model_manager,
                             data_manager=data_manager,
                             logger=logger,
                             optimizer_type=args.optimizer,
                             lr=args.learningRate,
                             epochs=args.epochs,
                             device=device,
                             verbose=args.verbose)
    # Run
    run_manager.run(args.training)
 def do_get(self, id: int):
     user = DataManager.get_instance().get_user_by_id(id)
     return jsonpickle.dumps(user, unpicklable=False)
 def do_get(self, genre: str, size: int, sortby: str):
     movies = DataManager.get_instance().get_movies_by_genre(
         genre, size, sortby)
     return jsonpickle.encode(movies, unpicklable=False)
Example #7
0
import os
from flask import Flask, request
from service.user_service import *
from service.movie_service import *
from service.recommendation_service import *
from service.rec_for_you_service import *
from service.similiar_movie_service import *
from data_manager.data_manager import DataManager

resource_path = os.path.abspath("../resources/webroot")

DataManager.get_instance().load_data(
    os.path.join(resource_path, "sampledata/movies.csv"),
    os.path.join(resource_path, "sampledata/links.csv"),
    os.path.join(resource_path, "sampledata/ratings.csv"),
    os.path.join(resource_path, "modeldata/item2vecEmb.csv"),
    os.path.join(resource_path, "modeldata/userEmb.csv"), "i2vEmb", "uEmb")
app = Flask(__name__, static_url_path="")


@app.route("/")
def home_page():
    return app.send_static_file("index.html")


@app.route("/getmovie", methods=["GET"])
def get_movie():
    id = request.args.get("id")
    return MovieService.do_get(int(id))

Example #8
0
def extract_osu(osu_file, result_length, frame_duration, sr):
    def to_frames(time):
        #time: time in ms
        # ms = (i * frame_duration)/sr * 1000
        return round(time / 1000 * sr / frame_duration)


#   print(result_length, frame_duration, sr)
#   print(to_frames(100))
#   print(round(100 / 1000 * sr / frame_duration))

    def slider_duration(length, multiplier, beat_length):
        return length / (multiplier * 100) * beat_length

    if '.npy' in osu_file:
        data = np.load(osu_file, allow_pickle=True)
        pulse = np.zeros(result_length)
        motion = np.zeros(result_length)
        PULSE_DURATION = 100  #ms
        OSU_PULSE_REACT = 1.0
        OSU_MOTION_REACT = 1.0
        pulse_vec = np.ones(to_frames(PULSE_DURATION)) * OSU_PULSE_REACT
        # print(len(pulse_vec))
        for event in data:  #event = [time in ms, 0hit or 1slide, duration in ms]
            if event[1] == 0:
                #hit
                start = to_frames(event[0]) - len(pulse_vec) // 2
                if start + len(pulse_vec) > len(pulse):
                    #   print(f'last_time:{event[0]}')
                    break
                # print(len(pulse_vec))
                pulse[start:start + len(pulse_vec)] += pulse_vec
            else:
                #slide
                start = to_frames(event[0])
                motion_vec = OSU_MOTION_REACT * np.ones(to_frames(event[2]))
                # print(f'motion_frames:{len(motion_vec)}')
                if start + len(motion_vec) > len(motion):
                    #   print(f'last_time:{event[0]}')
                    break
                motion[start:start + len(motion_vec)] += motion_vec
        return pulse, motion
    beatmap, _ = DM.get_beatmap(osu_file)
    # (len(self.spec_norm_pulse) * frame_duration + 1)/sr

    #   print(f'duration_ms:{(result_length * frame_duration/sr * 1000)}')

    pulse = np.zeros(result_length)
    motion = np.zeros(result_length)

    PULSE_DURATION = 100  #ms
    OSU_PULSE_REACT = 1.0
    OSU_MOTION_REACT = 1.0
    #   print(f'pulse_frames: {to_frames(PULSE_DURATION)}')
    pulse_vec = np.ones(to_frames(PULSE_DURATION)) * OSU_PULSE_REACT
    hit_objects = beatmap.hit_objects
    timing_objects = beatmap.timing_objects

    slider_multiplier = beatmap.difficult_settings.slider_multiplier
    slider_multiplier_multiplier = 1
    timing_object = timing_objects[0]

    for hit_object in hit_objects:
        while len(timing_objects
                  ) > 0 and hit_object.time >= timing_objects[0].time:
            temp = timing_objects.pop(0)
            if temp.uninherited == 1:
                timing_object = temp
                slider_multiplier_multiplier = 1
            else:
                slider_multiplier_multiplier = 100 / (-temp.beat_length)
        if HitObjectType.SLIDER in hit_object.type:
            start = to_frames(hit_object.time)
            motion_vec = OSU_MOTION_REACT * np.ones(
                to_frames(
                    slider_duration(
                        float(hit_object.length), slider_multiplier_multiplier
                        * slider_multiplier, timing_object.beat_length)))
            #   print(f'motion_frames:{len(motion_vec)},time:{hit_object.time}')
            if start + len(motion_vec) > len(motion):
                # print(f'last_time:{hit_object.time}')
                break
            motion[start:start + len(motion_vec)] += motion_vec
        elif HitObjectType.CIRCLE in hit_object.type:
            start = to_frames(hit_object.time) - len(pulse_vec) // 2
            if start + len(pulse_vec) > len(pulse):
                # print(f'last_time:{hit_object.time}')
                break
            pulse[start:start + len(pulse_vec)] += pulse_vec

    return pulse, motion
Example #9
0
 def do_get(self, movie_id: int):
     movie = DataManager.get_instance().get_movie_by_id(movie_id)
     if movie is not None:
         return jsonpickle.encode(movie, unpicklable=False)
     return ""