#NEWLINE# def deEffectData( infilePath , outfilePath , utils , userMovieRating ) : #NEWLINE# #INDENT# infile = open ( infilePath , 'r' ) #NEWLINE# lineCounter = 0 #NEWLINE# usersDict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# moviesDict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# globalSum = 0 #NEWLINE# umr = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for line in infile : #NEWLINE# #INDENT# if ( line != '\n' ) : #NEWLINE# #INDENT# lineCounter += 1 #NEWLINE# line = line . replace ( '\n' , '' ) #NEWLINE# columns = line . split ( '\t' ) #NEWLINE# user = columns [ 0 ] #NEWLINE# movie = columns [ 1 ] #NEWLINE# rating = float ( columns [ 2 ] ) #NEWLINE# if ( usersDict . get ( user ) == None ) : #NEWLINE# #INDENT# usersDict [ user ] = [ ] #NEWLINE# #UNINDENT# usersDict [ user ] . append ( rating ) #NEWLINE# if ( moviesDict . get ( movie ) == None ) : #NEWLINE# #INDENT# moviesDict [ movie ] = [ ] #NEWLINE# #UNINDENT# moviesDict [ movie ] . append ( rating ) #NEWLINE# if ( user not in umr ) : #NEWLINE# #INDENT# umr [ user ] = ( [ movie ] , [ globalMean ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( user in umr ) : #NEWLINE# #INDENT# umr [ user ] [ 0 ] . append ( movie ) #NEWLINE# umr [ user ] [ 1 ] . append ( rating ) #NEWLINE# #UNINDENT# #UNINDENT# globalSum += rating #NEWLINE# #UNINDENT# #UNINDENT# userMovieRating = umr #NEWLINE# infile . close ( ) #NEWLINE# globalMean = ( globalSum / lineCounter ) #NEWLINE# movieMeanDict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# userMeanDict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for i in usersDict : #NEWLINE# #INDENT# userMeanDict [ i ] = listAverager ( usersDict . get ( i ) ) #NEWLINE# #UNINDENT# for i in moviesDict : #NEWLINE# #INDENT# movieMeanDict [ i ] = listAverager ( moviesDict . get ( i ) ) #NEWLINE# #UNINDENT# infile = open ( infilePath , 'r' ) #NEWLINE# outfile = open ( outfilePath , 'w' ) #NEWLINE# for line in infile : #NEWLINE# #INDENT# line = line . replace ( '\n' , '' ) #NEWLINE# columns = line . split ( '\t' ) #NEWLINE# user = columns [ 0 ] #NEWLINE# movie = columns [ 1 ] #NEWLINE# newRating = ( globalMean - float ( columns [ 2 ] ) ) #NEWLINE# outfile . write ( ( ( ( ( ( user + '\t' ) + movie ) + '\t' ) + str ( newRating ) ) + '\n' ) ) #NEWLINE# #UNINDENT# infile . close ( ) #NEWLINE# outfile . close ( ) #NEWLINE# userFile = open ( utils . EFFECTS_USER_PATH , 'w' ) #NEWLINE# for i in userMeanDict : #NEWLINE# #INDENT# userFile . write ( ( ( ( str ( i ) + '\t' ) + str ( userMeanDict . get ( i ) ) ) + '\n' ) ) #NEWLINE# #UNINDENT# userFile . close ( ) #NEWLINE# movieFile = open ( utils . EFFECTS_MOVIE_PATH , 'w' ) #NEWLINE# for i in movieMeanDict : #NEWLINE# #INDENT# movieFile . write ( ( ( ( str ( i ) + '\t' ) + str ( movieMeanDict . get ( i ) ) ) + '\n' ) ) #NEWLINE# #UNINDENT# movieFile . close ( ) #NEWLINE# globalFile = open ( utils . EFFECTS_GLOBAL_PATH , 'w' ) #NEWLINE# globalFile . write ( str ( globalMean ) ) #NEWLINE# globalFile . close ( )