mirror of
https://github.com/maciejpedzich/racemash.git
synced 2024-11-27 16:15:47 +01:00
Rename certain variables for better clarity
This commit is contained in:
parent
4710b14405
commit
fd0d0f2ff4
@ -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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user