mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Made it use the sum of votes from choiceGroups when deciding the top 4.
This commit is contained in:
parent
60c125f4ce
commit
79fd1fe95e
1 changed files with 23 additions and 1 deletions
24
index.js
24
index.js
|
@ -224,6 +224,15 @@ function getVoteOrganisedSponsorTimes(sponsorTimes, votes, UUIDs) {
|
||||||
//the sponsor times either chosen to be added to finalSponsorTimeIndexes or chosen not to be added
|
//the sponsor times either chosen to be added to finalSponsorTimeIndexes or chosen not to be added
|
||||||
let finalSponsorTimeIndexesDealtWith = weightedRandomIndexes.choicesDealtWith;
|
let finalSponsorTimeIndexesDealtWith = weightedRandomIndexes.choicesDealtWith;
|
||||||
|
|
||||||
|
let voteSums = weightedRandomIndexes.weightSums;
|
||||||
|
//convert these into the votes
|
||||||
|
for (let i = 0; i < voteSums.length; i++) {
|
||||||
|
if (voteSums[i] != undefined) {
|
||||||
|
//it should use the sum of votes, since anyone upvoting a similar sponsor is upvoting the existence of that sponsor.
|
||||||
|
votes[finalSponsorTimeIndexes[i]] = voteSums;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//find the indexes never dealt with and add them
|
//find the indexes never dealt with and add them
|
||||||
for (let i = 0; i < sponsorTimes.length; i++) {
|
for (let i = 0; i < sponsorTimes.length; i++) {
|
||||||
if (!finalSponsorTimeIndexesDealtWith.includes(i)) {
|
if (!finalSponsorTimeIndexesDealtWith.includes(i)) {
|
||||||
|
@ -257,8 +266,20 @@ function getWeightedRandomChoiceForArray(choiceGroups, weights) {
|
||||||
let finalChoices = [];
|
let finalChoices = [];
|
||||||
//the indexes either chosen to be added to final indexes or chosen not to be added
|
//the indexes either chosen to be added to final indexes or chosen not to be added
|
||||||
let choicesDealtWith = [];
|
let choicesDealtWith = [];
|
||||||
|
//for each choice group, what are the sums of the weights
|
||||||
|
let weightSums = [];
|
||||||
|
|
||||||
for (let i = 0; i < choiceGroups.length; i++) {
|
for (let i = 0; i < choiceGroups.length; i++) {
|
||||||
|
//find weight sums for this group
|
||||||
|
weightSums.push(0);
|
||||||
|
for (let j = 0; j < choiceGroups[i].length; j++) {
|
||||||
|
//only if it is a positive vote, otherwise it is probably just a sponsor time with slightly wrong time
|
||||||
|
if (weights[choiceGroups[i][j]] > 0) {
|
||||||
|
weightSums[weightSums.length - 1] += weights[choiceGroups[i][j]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//create a random choice for this group
|
||||||
let randomChoice = getWeightedRandomChoice(choiceGroups[i], weights, 1)
|
let randomChoice = getWeightedRandomChoice(choiceGroups[i], weights, 1)
|
||||||
finalChoices.push(randomChoice.finalChoices);
|
finalChoices.push(randomChoice.finalChoices);
|
||||||
|
|
||||||
|
@ -269,7 +290,8 @@ function getWeightedRandomChoiceForArray(choiceGroups, weights) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
finalChoices: finalChoices,
|
finalChoices: finalChoices,
|
||||||
choicesDealtWith: choicesDealtWith
|
choicesDealtWith: choicesDealtWith,
|
||||||
|
weightSums: weightSums
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue