Ejemplo n.º 1
0
def recomendar_animes_usuario(request):
    mensaje = None
    if request.method=='GET':
        form = UsuarioForm(request.GET, request.FILES)
        if form.is_valid():
            idUser = form.cleaned_data['id']
            
            try:
                user = get_object_or_404(InformacionUsuario, pk=idUser)
            except Http404:
                mensaje = 'No existe ningún usuario con el ID seleccionado'
                return render(request, 'busquedaporusuarios.html', {'form':form, 'mensaje':mensaje})
                 
            shelf = shelve.open("ProyectoAII/dataRS1.dat")
            Prefs = shelf['Prefs']
            shelf.close()
            rankings = getRecommendations(Prefs,int(idUser))
            recommended = rankings[:2]
            anime = []
            scores = []
            for re in recommended:
                anime = Anime.objects.filter(pk=re[1])
                scores.append(re[0])
            animes = zip(anime,scores)
            
            animes_cal = []
            for a in Calificacion.objects.filter(usuario=user):
                animes_cal.append(a)
            
            return render(request,'recomendacionanimes.html', {'user': user, 'animes_recom': animes, 'animes_cal': animes_cal})
    form = UsuarioForm()
    return render(request,'busquedaporusuarios.html', {'form': form})
Ejemplo n.º 2
0
def recomendarUsuariosAJugadores(request):
    items = None
    jugador = None
    form = ItemForm()
    if request.method == 'POST':
        form = ItemForm(request.POST)
        if form.is_valid():
            idJugador = form.cleaned_data['id']
            jugador = get_object_or_404(Jugador, pk=idJugador)
            shelf = shelve.open("dataRS.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            try:
                ItemsPrefs[int(idJugador)]
            except KeyError:
                return redirect('/error')
            rankings = getRecommendations(ItemsPrefs, int(idJugador))
            recommended = rankings[:3]
            usuarios = []
            similar = []
            for re in recommended:
                usuarios.append(Usuario.objects.get(pk=re[1]))
                similar.append(re[0])
            items = zip(usuarios, similar)
    return render(request, 'searchRecommendUsuarios.html', {
        'form': form,
        'jugador': jugador,
        'items': items
    })
Ejemplo n.º 3
0
def recomendarJugadoresUsuario(request):
    items = None
    idUsuario = None
    usuario = None
    form = UserForm()
    if request.method == 'POST':
        form = UserForm(request.POST)
        if form.is_valid():
            idUsuario = form.cleaned_data['id']
            shelf = shelve.open("dataRS.dat")
            Prefs = shelf['Prefs']
            shelf.close()
            try:
                usuario = Usuario.objects.get(id=int(idUsuario))
            except:
                return redirect('/error')
            puntuaciones = getRecommendations(Prefs, int(idUsuario))
            recommended = puntuaciones[:3]
            jugadores = []
            scores = []
            for re in recommended:
                jugadores.append(Jugador.objects.get(pk=re[1]))
                scores.append(re[0])
            items = zip(jugadores, scores)
    return render(request, 'searchRecommendJugadores.html', {
        'user': usuario,
        'items': items,
        'form': form
    })
Ejemplo n.º 4
0
def recommended_peripheral_user(request):
    if request.method == 'GET':
        form = UserForm(request.GET, request.FILES)
        if form.is_valid():
            id_user = form.cleaned_data['id']
            user = get_object_or_404(User, pk=id_user)
            shelf = shelve.open("dataRS.dat")
            prefs = shelf['Prefs']
            items = []
            if int(id_user) not in prefs:
                return render(request, 'recommendationItems.html', {
                    'user': user,
                    'items': items
                })
            shelf.close()
            rankings = getRecommendations(prefs, int(id_user))
            recommended = rankings[:
                                   20]  # Change number of similar items recommended
            peripherals = []
            scores = []
            for re in recommended:
                peripherals.append(Peripheral.objects.get(pk=re[1]))
                scores.append(re[0])
            items = zip(peripherals, scores)
            return render(request, 'recommendationItems.html', {
                'user': user,
                'items': items
            })
    form = UserForm()
    return render(request, 'searchUser.html', {'form': form})
Ejemplo n.º 5
0
def recommended_users_peripherals(request):
    if request.method == 'GET':
        form = PeripheralForm(request.GET, request.FILES)
        if form.is_valid():
            id_peripheral = form.cleaned_data['id']
            peripheral = get_object_or_404(Peripheral, pk=id_peripheral)
            shelf = shelve.open("dataRS.dat")
            prefs = shelf['ItemsPrefs']
            shelf.close()
            items = []
            if int(id_peripheral) not in prefs:
                return render(request, 'recommendationUsers.html', {
                    'peripheral': peripheral,
                    'items': items
                })
            rankings = getRecommendations(prefs, int(id_peripheral))
            recommended = rankings[:3]  # number of recommended items
            peripherals = []
            scores = []
            for re in recommended:
                peripherals.append(User.objects.get(pk=re[1]))
                scores.append(re[0])
            items = zip(peripherals, scores)
            return render(request, 'recommendationUsers.html', {
                'peripheral': peripheral,
                'items': items
            })
    form = PeripheralForm()
    return render(request, 'searchPeripheral.html', {'form': form})
Ejemplo n.º 6
0
def __vista2_users(username):
    user = User.objects.get(username=username)
    user_id = user.pk

    shelf = shelve.open("dataRS.dat")
    prefs = shelf['Prefs']
    shelf.close()

    rankings = getRecommendations(prefs, int(user_id))
    recommended = rankings[:10]  # Change number of similar items recommended

    scores = []
    peripherals = []
    for re in recommended:
        peripherals.append(Peripheral.objects.get(pk=re[1]))
        scores.append(re[0])
    items = zip(peripherals, scores)
    return items
Ejemplo n.º 7
0
def recommendedBooksUser(request):
    if request.method=='GET':
        form = UserForm(request.GET, request.FILES)
        if form.is_valid():
            idUser = form.cleaned_data['id']
            user = get_object_or_404(Usuario, pk=idUser)
            shelf = shelve.open("dataRS.dat")
            Prefs = shelf['Prefs']
            shelf.close()
            rankings = getRecommendations(Prefs,int(idUser))
            recommended = rankings[:2]
            books = []
            scores = []
            for re in recommended:
                books.append(Libro.objects.get(pk=re[1]))
                scores.append(re[0])
            items= zip(books,scores)
            return render(request,'recommendationItems.html', {'user': user, 'items': items})
    form = UserForm()
    return render(request,'search_user.html', {'form': form})
Ejemplo n.º 8
0
def recommendedUsersFilms(request):
    if request.method == 'GET':
        form = FilmForm(request.GET, request.FILES)
        if form.is_valid():
            idFilm = form.cleaned_data['id']
            film = get_object_or_404(Film, pk=idFilm)
            shelf = shelve.open("dataRS.dat")
            Prefs = shelf['ItemsPrefs']
            shelf.close()
            rankings = getRecommendations(Prefs, int(idFilm))
            recommended = rankings[:3]
            films = []
            scores = []
            for re in recommended:
                films.append(UserInformation.objects.get(pk=re[1]))
                scores.append(re[0])
            items = zip(films, scores)
            return render(request, 'recommendationUsers.html', {
                'film': film,
                'items': items
            })
    form = FilmForm()
    return render(request, 'search_film.html', {'form': form})