Rename certain variables for better clarity

This commit is contained in:
Maciej Pędzich 2023-06-09 18:29:29 +02:00
parent 4710b14405
commit fd0d0f2ff4

View File

@ -36,11 +36,8 @@ const pickPhotosForNewVote = () => {
); );
const fileNamesToExclude = [ const fileNamesToExclude = [
...new Set( firstPick.fileName,
votesWithFirstPick ...new Set(votesWithFirstPick.flatMap(({ photos }) => photos))
.flatMap(({ photos }) => photos)
.concat([firstPick.fileName])
)
]; ];
return !fileNamesToExclude.includes(fileName); return !fileNamesToExclude.includes(fileName);
@ -72,46 +69,53 @@ const updateRatings = () => {
const votesGrouppedByPhotos = twelveMostRecentVotes.reduce((obj, vote) => { const votesGrouppedByPhotos = twelveMostRecentVotes.reduce((obj, vote) => {
const [firstFileName, secondFileName] = vote.photos; const [firstFileName, secondFileName] = vote.photos;
const firstPhoto = db.photos.find(
({ fileName }) => fileName === firstFileName
)!;
const secondPhoto = db.photos.find( const secondPhoto = db.photos.find(
({ fileName }) => fileName === secondFileName ({ fileName }) => fileName === secondFileName
)!; )!;
const firstPhotoOpponentParams = [ const paramsVersusSecondPhoto = [
secondPhoto.rating, secondPhoto.rating,
secondPhoto.rd, secondPhoto.rd,
vote.result vote.result
] as [number, number, number]; ] 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.rating,
firstPhoto.rd, firstPhoto.rd,
1 - vote.result 1 - vote.result
] as [number, number, number]; ] as [number, number, number];
if (obj[firstFileName]) {
obj[firstFileName].push(firstPhotoOpponentParams);
} else {
obj[firstFileName] = [firstPhotoOpponentParams];
}
if (obj[secondFileName]) { if (obj[secondFileName]) {
obj[secondFileName].push(secondPhotoOpponentParams); obj[secondFileName].push(paramsVersusFirstPhoto);
} else { } else {
obj[secondFileName] = [secondPhotoOpponentParams]; obj[secondFileName] = [paramsVersusFirstPhoto];
} }
return obj; return obj;
}, {} as Record<string, [number, number, number][]>); }, {} as Record<string, [number, number, number][]>);
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 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);
} }
}; };