Skip to content

Instantly share code, notes, and snippets.

@PetarIvancevic
Created October 27, 2017 18:56
Show Gist options
  • Save PetarIvancevic/1f46d205b2c5e16ae6a9e690f1dfa06c to your computer and use it in GitHub Desktop.
Save PetarIvancevic/1f46d205b2c5e16ae6a9e690f1dfa06c to your computer and use it in GitHub Desktop.
Update users similarity scores
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