Created
October 27, 2017 18:56
-
-
Save PetarIvancevic/1f46d205b2c5e16ae6a9e690f1dfa06c to your computer and use it in GitHub Desktop.
Update users similarity scores
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function updateUserSimilarityScores (username) { | |
const users = await db.user.getVals() | |
const mainUser = await db.user.get(username) | |
mainUser.reviews = await getUserMovieReviews(mainUser) | |
const mainUserMovies = _.map(mainUser.reviews, 'movieId') | |
return Promise.map(users, async function (user) { | |
user.reviews = await getUserMutualMovieReviews(user, mainUserMovies) | |
if (user.username === mainUser.username) { | |
return | |
} | |
const clonedUsers = filterUserMutualMovies(mainUser, user) | |
return db.similarity.put([user.username, mainUser.username].sort().join('-'), { | |
euclideanDistance: algorithms.euclideanDistance(clonedUsers[0], clonedUsers[1]), | |
pcc: algorithms.pcc(clonedUsers[0], clonedUsers[1]), | |
users: [user.username, mainUser.username].sort(), | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment