From fd0d0f2ff4bb02a7dc6a917609b5d998d29f89f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20P=C4=99dzich?= Date: Fri, 9 Jun 2023 18:29:29 +0200 Subject: [PATCH] Rename certain variables for better clarity --- src/composables/useVote.ts | 48 +++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/composables/useVote.ts b/src/composables/useVote.ts index fe37284..d340c95 100644 --- a/src/composables/useVote.ts +++ b/src/composables/useVote.ts @@ -36,11 +36,8 @@ const pickPhotosForNewVote = () => { ); const fileNamesToExclude = [ - ...new Set( - votesWithFirstPick - .flatMap(({ photos }) => photos) - .concat([firstPick.fileName]) - ) + firstPick.fileName, + ...new Set(votesWithFirstPick.flatMap(({ photos }) => photos)) ]; return !fileNamesToExclude.includes(fileName); @@ -72,46 +69,53 @@ const updateRatings = () => { const votesGrouppedByPhotos = twelveMostRecentVotes.reduce((obj, vote) => { const [firstFileName, secondFileName] = vote.photos; - const firstPhoto = db.photos.find( - ({ fileName }) => fileName === firstFileName - )!; - const secondPhoto = db.photos.find( ({ fileName }) => fileName === secondFileName )!; - const firstPhotoOpponentParams = [ + const paramsVersusSecondPhoto = [ secondPhoto.rating, secondPhoto.rd, vote.result ] as [number, number, number]; - const secondPhotoOpponentParams = [ + if (obj[firstFileName]) { + obj[firstFileName].push(paramsVersusSecondPhoto); + } else { + obj[firstFileName] = [paramsVersusSecondPhoto]; + } + + const firstPhoto = db.photos.find( + ({ fileName }) => fileName === firstFileName + )!; + + const paramsVersusFirstPhoto = [ firstPhoto.rating, firstPhoto.rd, 1 - vote.result ] as [number, number, number]; - if (obj[firstFileName]) { - obj[firstFileName].push(firstPhotoOpponentParams); - } else { - obj[firstFileName] = [firstPhotoOpponentParams]; - } - if (obj[secondFileName]) { - obj[secondFileName].push(secondPhotoOpponentParams); + obj[secondFileName].push(paramsVersusFirstPhoto); } else { - obj[secondFileName] = [secondPhotoOpponentParams]; + obj[secondFileName] = [paramsVersusFirstPhoto]; } return obj; }, {} as Record); - for (const [photoFileName, votes] of Object.entries(votesGrouppedByPhotos)) { + for (const [photoFileName, voteHistory] of Object.entries( + votesGrouppedByPhotos + )) { const photo = db.photos.find(({ fileName }) => fileName === photoFileName)!; - const newRatingParams = glicko2(photo.rating, photo.rd, photo.vol, votes); + const updatedRatingParams = glicko2( + photo.rating, + photo.rd, + photo.vol, + voteHistory + ); - Object.assign(photo, newRatingParams); + Object.assign(photo, updatedRatingParams); } };