#NEWLINE# def affinities_betwen( profile1 , profile2 ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# key1 = defaultfilters . slugify ( ( '%s and %s affinities' % ( profile1 . pk , profile2 . pk ) ) ) #NEWLINE# key2 = defaultfilters . slugify ( ( '%s and %s affinities' % ( profile2 . pk , profile1 . pk ) ) ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# return '?' #NEWLINE# #UNINDENT# result1 = cache . get ( key1 ) #NEWLINE# if result1 : #NEWLINE# #INDENT# return result1 #NEWLINE# #UNINDENT# result2 = cache . get ( key2 ) #NEWLINE# if result2 : #NEWLINE# #INDENT# return result2 #NEWLINE# #UNINDENT# factors = [ ] #NEWLINE# profile1_tracks_count = profile1 . tiny_playlist . tracks . count ( ) #NEWLINE# profile2_tracks_count = profile2 . tiny_playlist . tracks . count ( ) #NEWLINE# if ( profile1_tracks_count and profile2_tracks_count ) : #NEWLINE# #INDENT# comon_tracks_count = float ( Track . objects . filter ( playlist = profile1 . tiny_playlist ) . filter ( playlist = profile2 . tiny_playlist ) . count ( ) ) #NEWLINE# comon_tracks_factor = ( ( comon_tracks_count / profile1_tracks_count ) + ( comon_tracks_count / profile2_tracks_count ) ) #NEWLINE# factors . append ( comon_tracks_factor ) #NEWLINE# #UNINDENT# profile1_artists_count = profile1 . fanof_artists . count ( ) #NEWLINE# profile2_artists_count = profile2 . fanof_artists . count ( ) #NEWLINE# if ( profile1_artists_count and profile2_artists_count ) : #NEWLINE# #INDENT# comon_artists_count = float ( Artist . objects . filter ( fans = profile1 ) . filter ( fans = profile2 ) . count ( ) ) #NEWLINE# comon_artists_factor = ( ( comon_artists_count / profile1_artists_count ) + ( comon_artists_count / profile2_artists_count ) ) #NEWLINE# factors . append ( comon_artists_factor ) #NEWLINE# #UNINDENT# profile1_playlists_count = profile1 . fanof_playlists . count ( ) #NEWLINE# profile2_playlists_count = profile2 . fanof_playlists . count ( ) #NEWLINE# if ( profile1_playlists_count and profile2_playlists_count ) : #NEWLINE# #INDENT# comon_playlists_count = float ( Playlist . objects . filter ( fans = profile1 ) . filter ( fans = profile2 ) . count ( ) ) #NEWLINE# comon_playlists_factor = ( ( comon_playlists_count / profile1_playlists_count ) + ( comon_playlists_count / profile2_playlists_count ) ) #NEWLINE# factors . append ( comon_playlists_factor ) #NEWLINE# #UNINDENT# if len ( factors ) : #NEWLINE# #INDENT# percent = int ( ( ( sum ( factors ) / len ( factors ) ) * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# percent = 0 #NEWLINE# #UNINDENT# if ( percent > 100 ) : #NEWLINE# #INDENT# percent = 100 #NEWLINE# #UNINDENT# if ( ( profile1_playlists_count == 0 ) and ( profile1_artists_count == 0 ) and ( profile1_tracks_count == 0 ) ) : #NEWLINE# #INDENT# percent = 0 #NEWLINE# #UNINDENT# return percent