Fix unlocked segments being ignored

This commit is contained in:
Ajay
2022-01-06 14:58:46 -05:00
parent be441a314f
commit 75cad434b6

View File

@@ -167,7 +167,7 @@ async function getSegmentsFromDBByVideoID(videoID: VideoID, service: Service): P
// amountOfChoices specifies the maximum amount of choices to return, 1 or more. // amountOfChoices specifies the maximum amount of choices to return, 1 or more.
// Choices are unique // Choices are unique
// If a predicate is given, it will only filter choices following it, and will leave the rest in the list // If a predicate is given, it will only filter choices following it, and will leave the rest in the list
function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOfChoices: number, predicate?: (choice: T) => void): T[] { function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOfChoices: number, filterLocked = false, predicate?: (choice: T) => void): T[] {
//trivial case: no need to go through the whole process //trivial case: no need to go through the whole process
if (amountOfChoices >= choices.length) { if (amountOfChoices >= choices.length) {
return choices; return choices;
@@ -184,7 +184,7 @@ function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOf
filteredChoices = splitArray[0]; filteredChoices = splitArray[0];
forceIncludedChoices = splitArray[1]; forceIncludedChoices = splitArray[1];
if (filteredChoices.some((value) => value.locked)) { if (filterLocked && filteredChoices.some((value) => value.locked)) {
filteredChoices = filteredChoices.filter((value) => value.locked); filteredChoices = filteredChoices.filter((value) => value.locked);
} }
} }
@@ -234,12 +234,12 @@ async function chooseSegments(videoID: VideoID, service: Service, segments: DBSe
? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service)) ? await QueryCacher.get(fetchData, skipSegmentGroupsKey(videoID, service))
: await fetchData(); : await fetchData();
// Filter for only 1 item for POI categories // Filter for only 1 item for POI categories and Full video
return getWeightedRandomChoice(groups, 1, (choice) => choice.segments[0].actionType === ActionType.Full let chosenGroups = getWeightedRandomChoice(groups, 1, true, (choice) => choice.segments[0].actionType === ActionType.Full);
|| getCategoryActionType(choice.segments[0].category) === CategoryActionType.POI) chosenGroups = getWeightedRandomChoice(chosenGroups, 1, true, (choice) => getCategoryActionType(choice.segments[0].category) === CategoryActionType.POI);
.map(//randomly choose 1 good segment per group and return them return chosenGroups.map(//randomly choose 1 good segment per group and return them
group => getWeightedRandomChoice(group.segments, 1)[0] group => getWeightedRandomChoice(group.segments, 1)[0]
); );
} }
//This function will find segments that are contained inside of eachother, called similar segments //This function will find segments that are contained inside of eachother, called similar segments