Ejemplo n.º 1
0
def buscar_animessimilares(request):
    anime = None
    mensaje = None
    if request.method=='GET':
        form = UsuarioForm(request.GET, request.FILES)
        if form.is_valid():
            idAnime = form.cleaned_data['id']
            
            try:
                anime = get_object_or_404(Anime, pk=idAnime)
            except Http404:
                mensaje = 'No existe ningún anime con el ID seleccionado'
                return render(request, 'buscaranimessimilares.html', {'form':form, 'mensaje':mensaje})
                
            shelf = shelve.open("ProyectoAII/dataRS1.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, int(idAnime),n=3)
            anime = []
            similar = []
            for re in recommended:
                anime.append(Anime.objects.get(pk=re[1]))
                similar.append(re[0])
            animes= zip(anime,similar)

            return render(request,'animessimilares.html', {'anime': anime,'animes': animes})
        
    form = AnimeForm()
    return render(request,'buscaranimessimilares.html', {'form': form})  
Ejemplo n.º 2
0
def pilotoSimilar(request):
    piloto = None
    if request.method == 'POST':
        form = BusquedaDePilotoSimilar(request.POST)
        if form.is_valid():
            idPiloto = form.cleaned_data['id']
            piloto = get_object_or_404(Piloto, id=idPiloto)
            shelf = shelve.open("votacionesPilotosRS.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, int(idPiloto), n=3)
            pilotos = []
            similar = []
            for re in recommended:
                pilotos.append(Piloto.objects.get(pk=re[1]))
                similar.append(re[0])
            items = zip(pilotos, similar)
            print(items)
            return render(request, 'buscar_piloto_similar.html', {
                'piloto': piloto,
                'pilotos': items,
                'formulario': form
            })
    form = BusquedaDePilotoSimilar()
    return render(request, 'buscar_piloto_similar.html', {'formulario': form})
Ejemplo n.º 3
0
def jugadoresSimilares(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')
            recommended = topMatches(ItemsPrefs, int(idJugador), n=5)
            jugadores = []
            similar = []
            for re in recommended:
                jugadores.append(Jugador.objects.get(pk=re[1]))
                similar.append(re[0])
            items = zip(jugadores, similar)
    return render(request, 'searchSimilarJugadores.html', {
        'form': form,
        'jugador': jugador,
        'items': items
    })
Ejemplo n.º 4
0
def similarFilms(request):
    film = None
    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")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, int(idFilm),n=3)
            items=[]
            for re in recommended:
                item = Film.objects.get(pk=int(re[1]))
                items.append(item)
            return render(request,'similarFilms.html', {'film': film,'films': items})
    form = FilmForm()
    return render(request,'search_film.html', {'form': form})
Ejemplo n.º 5
0
def similarBooks(request):
    book = None
    if request.method=='GET':
        form = BookForm(request.GET, request.FILES)
        if form.is_valid():
            idBook = form.cleaned_data['isbn']
            book = get_object_or_404(Book, pk=idBook)
            shelf = shelve.open("dataRS.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, idBook, n=2)
            items=[]
            for re in recommended:
                item = Book.objects.get(ISBN=re[1])
                items.append(item)
            return render(request,'similarBooks.html', {'book': book,'books': items})
    form = BookForm()
    return render(request,'search_book.html', {'form': form})
Ejemplo n.º 6
0
def usuariosParecidos(request):
    punt = None
    if request.method == 'GET':
        form = UserForm(request.GET, request.FILES)
        if form.is_valid():
            idUser = form.cleaned_data['id']
            punt = Rating.objects.filter(user=idUser)
            shelf = shelve.open("dataRS.dat")
            ItemsPrefs = shelf['Prefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, int(idUser), n=3)
            users = []
            similar = []
            for re in recommended:
                users.append(Rating.objects.filter(user=re[1]).first())
                similar.append(re[0])
            items = zip(users, similar)
            return render(request, 'similarUsers.html', {'idUser':idUser,'punt': punt, 'users': items})
    form = UserForm()
    return render(request, 'search_user.html', {'form': form})
Ejemplo n.º 7
0
def similarBooks(request):
    book = None
    if request.method=='GET':
        form = BookForm(request.GET, request.FILES)
        if form.is_valid():
            idBook = form.cleaned_data['id']
            book = get_object_or_404(Libro, pk=idBook)
            shelf = shelve.open("dataRS.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, int(idBook),n=2)
            books = []
            similar = []
            for re in recommended:
                books.append(Libro.objects.get(pk=re[1]))
                similar.append(re[0])
            items= zip(books,similar)
            return render(request,'similarBooks.html', {'book': book,'books': items})
    form = BookForm()
    return render(request,'search_book.html', {'form': form})
Ejemplo n.º 8
0
def similarFilms(request):
    film = None
    if request.method == 'GET':
        form = FilmForm(request.GET, request.FILES)
        if form.is_valid():
            idFilm = int(form.cleaned_data['id'])
            film = get_object_or_404(Film, idMovie=idFilm)
            shelf = shelve.open("Cine\\dataRS.dat")
            ItemsPrefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(ItemsPrefs, idFilm, n=3)
            items = []
            for re in recommended:
                item = Film.objects.get(idMovie=re[1])
                items.append(item)
            return render_to_response('similarFilms.html', {
                'film': film,
                'films': items
            },
                                      context_instance=RequestContext(request))
    form = FilmForm()
    return render_to_response('search_film.html', {'form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 9
0
def similar_items(request):
    peripheral_id = request.GET.get('itemId')
    peripheral = Peripheral.objects.get(pk=peripheral_id)

    shelf = shelve.open("dataRS.dat")
    items_prefs = shelf['ItemsPrefs']
    shelf.close()

    recommended = topMatches(items_prefs, int(peripheral_id),
                             n=9)  # n: number of similar items

    similar = []
    peripherals = []
    for re in recommended:
        peripherals.append(Peripheral.objects.get(pk=re[1]))
        similar.append(re[0])
    items = zip(peripherals, similar)

    list_items = list(items)
    return render(request, 'vista2.html', {
        'user': peripheral.name,
        'items': list_items
    })
Ejemplo n.º 10
0
def similar_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")
            items_prefs = shelf['ItemsPrefs']
            shelf.close()
            recommended = topMatches(items_prefs, int(id_peripheral),
                                     n=20)  # n: number of similar items
            peripherals = []
            similar = []
            for re in recommended:
                peripherals.append(Peripheral.objects.get(pk=re[1]))
                similar.append(re[0])
            items = zip(peripherals, similar)
            return render(request, 'similarPeripherals.html', {
                'peripheral': peripheral,
                'peripherals': items
            })
    form = PeripheralForm()
    return render(request, 'searchPeripheral.html', {'form': form})