コード例 #1
0
ファイル: views.py プロジェクト: ecatkins/instabilly
    def post(self, request):
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            username = registration_form.cleaned_data['username']
            password = registration_form.cleaned_data['password']
            first_name = registration_form.cleaned_data['first_name']
            last_name = registration_form.cleaned_data['last_name']
            email = registration_form.cleaned_data['email']
            hashed_password = make_password(password)
            user = User(username=username, password=hashed_password, first_name=first_name, last_name=last_name, email=email)
            user.save()
            request.session['session_id'] = user.pk
            follow_list = FollowList(user=user)
            follow_list.save()
            user_activation = UserActivationCode(user=user)
            user_activation.save()
            profile = UserProfile(user=user, updated_genres=datetime.datetime.now())
            profile.save()
            request.session['post_oauth'] = 'timeline'

            ##testing email#######
            subject = "Confirm your registration"
            message = "You're almost there! Copy and paste this code into the activation page: {}".format(user_activation.code)
            from_email = settings.EMAIL_HOST_USER
            to_list = [user.email, settings.EMAIL_HOST_USER]
            send_mail(subject, message, from_email, to_list, fail_silently=True)
            print("sent mail!!!")
            return redirect("activation")
            ####email########
            return redirect("oauth")
        else:
            errors = registration_form.errors.as_json()
            return render(request, 'spotify/home.html', {"login_form": UserForm(), "registration_form": registration_form,"registration_error": "Invalid Registration Details"})
コード例 #2
0
ファイル: views.py プロジェクト: ecatkins/instabilly
    def post(self, request):
        registration_form = RegistrationForm(request.POST)
        if registration_form.is_valid():
            username = registration_form.cleaned_data['username']
            password = registration_form.cleaned_data['password']
            first_name = registration_form.cleaned_data['first_name']
            last_name = registration_form.cleaned_data['last_name']
            email = registration_form.cleaned_data['email']
            hashed_password = make_password(password)
            user = User(username=username,
                        password=hashed_password,
                        first_name=first_name,
                        last_name=last_name,
                        email=email)
            user.save()
            request.session['session_id'] = user.pk
            follow_list = FollowList(user=user)
            follow_list.save()
            user_activation = UserActivationCode(user=user)
            user_activation.save()
            profile = UserProfile(user=user,
                                  updated_genres=datetime.datetime.now())
            profile.save()
            request.session['post_oauth'] = 'timeline'

            ##testing email#######
            subject = "Confirm your registration"
            message = "You're almost there! Copy and paste this code into the activation page: {}".format(
                user_activation.code)
            from_email = settings.EMAIL_HOST_USER
            to_list = [user.email, settings.EMAIL_HOST_USER]
            send_mail(subject,
                      message,
                      from_email,
                      to_list,
                      fail_silently=True)
            print("sent mail!!!")
            return redirect("activation")
            ####email########
            return redirect("oauth")
        else:
            errors = registration_form.errors.as_json()
            return render(
                request, 'spotify/home.html', {
                    "login_form": UserForm(),
                    "registration_form": registration_form,
                    "registration_error": "Invalid Registration Details"
                })
コード例 #3
0
def followlist():
    all_users = User.objects.all()
    for user in all_users:
        new_followlist = FollowList(user=user)
        new_followlist.save()
コード例 #4
0
ファイル: recommendation.py プロジェクト: ecatkins/instabilly
def create_playlist(user, num_neighbors, follow_effect, number_songs,
                    recency_effect, rating_effect, duplicate_artist_effect,
                    existing_playlist_effect):
    '''Pass: the active user, number of neighbors to inform recommendation and
	 number of songs desired in playlist
	 Returns: Array of song objects '''
    #Ensures that the neighbors are limited while the userbase is small
    num_neighbors = int(min(num_neighbors, User.objects.all().count() / 2))
    follow_list = [
        follower for follower in FollowList(user=user).following.all()
        if follower.song_set.exists()
    ]
    num_follow = int(num_neighbors * follow_effect)
    num_reduced_neighbors = num_neighbors - num_follow

    if num_reduced_neighbors == 0:
        neighbors = None
    else:
        neighbors = get_neighbors(user, num_reduced_neighbors)

    if num_follow > 0:
        following = get_following(neighbors, num_follow, follow_list)
        if neighbors == None:
            following_and_neighbors = following
        else:
            following_and_neighbors = following + neighbors
    else:
        following_and_neighbors = neighbors

    playlist = []

    user_songs = get_user_song_array(following_and_neighbors)
    song_choice = return_tracks_with_recency_bias(user_songs, number_songs,
                                                  recency_effect)

    ### Weighting factor 1, similarity to current user
    distances = [1 / (x[1] + 0.01) for x in following_and_neighbors]
    for song_number in song_choice:
        if len(playlist) < number_songs:
            recommendation_array = []
            replication_array = []
            existing_playlist_array = []
            duplicate_song_array = []
            for user_song in song_number:
                ### Weighting factor 2, user previous recommendations of artist
                recommendation = ArtistRating.objects.filter(
                    user=user, artist=user_song.song.artists)
                if len(recommendation) == 1:
                    score = float(recommendation[0].score)
                else:
                    score = 0.5
                #Adjusts for effect
                score = score - (score - 0.5) * (1 - rating_effect)
                recommendation_array.append(score)
                ### Weighting factor 3, no duplicate artists in playlist
                if duplicate_artist(playlist, user_song) == True:
                    replication_array.append(1 - (duplicate_artist_effect))
                else:
                    replication_array.append(1)
                ### Weighting factor 4, already in user playlist
                existing = UserSong.objects.filter(user=user,
                                                   song=user_song.song)
                if len(existing) > 0:
                    song = UserSong.objects.filter(user=user,
                                                   song=user_song.song)
                    existing_playlist_array.append(1 -
                                                   existing_playlist_effect)
                else:
                    existing_playlist_array.append(1)
                ### Final check to ensure no duplicate songs
                if duplicate_song(playlist, user_song) == True:
                    duplicate_song_array.append(0)
                else:
                    duplicate_song_array.append(1)
            #Multiply arrays
            final_weighting_array = []
            #change len(distances) to len(neighbors)
            for x in range(len(distances)):
                # print(x)
                final_weighting = distances[x] * recommendation_array[
                    x] * replication_array[x] * existing_playlist_array[
                        x] * duplicate_song_array[x]
                final_weighting_array.append(final_weighting)
            # Needs fixing to ensure that playlist is of conistent length
            if sum(final_weighting_array) == 0:
                continue
            ### select song

            choice = weighted_choice(final_weighting_array)
            playlist.append(song_number[choice])
        else:
            break

        # for i, item in enumerate(song_number):
        # 	print("SONG")
        # 	print(item.song.artists.name,item.song.track_name)
        # 	print("DISTANCE")
        # 	print(distances[i])
        # 	print("RECOMMENDATION")
        # 	print(recommendation_array[i])
        # 	print("REPLICATE ARTIST")
        # 	print(replication_array[i])
        # 	print("EXISTING PLAYLIST")
        # 	print(existing_playlist_array[i])
        # 	print("DUPLICATE SONG")
        # 	print(duplicate_song_array[i])
        # 	print("FINAL WEIGHTING")
        # 	print(final_weighting_array[i])
        # 	print("")

        # print("WINNER")
        # print(song_number[choice].song.artists.name,song_number[choice].song.track_name)
        # print("")

    return playlist