Пример #1
0
def recommended_peripheral_items(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']
            sim_items = shelf['SimItems']
            items = []
            if int(id_user) not in prefs:
                return render(request, 'recommendationItems.html', {
                    'user': user,
                    'items': items
                })
            shelf.close()
            getHybridRecommendation(prefs, int(id_user), sim_items)
            rankings = getRecommendedItems(prefs, sim_items, 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})
Пример #2
0
def __vista2_hybrid(username):
    user = User.objects.get(username=username)
    user_id = user.pk

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

    rankings = getHybridRecommendation(prefs, int(user_id), sim_items)
    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