feat(v2): add Top10 selection with soft group diversity, hard 10-item cap
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
749be7dbae
commit
d3917707e0
@@ -0,0 +1,34 @@
|
||||
function selectTop(scored, topN, config) {
|
||||
const eligible = scored.filter((item) => !item.excludedFromTop10);
|
||||
const excluded = scored.filter((item) => item.excludedFromTop10);
|
||||
|
||||
const sorted = [...eligible].sort((a, b) => b.score - a.score);
|
||||
|
||||
const groupCap = Math.max(1, Math.ceil(topN * 0.5));
|
||||
const groupCounts = {};
|
||||
const firstPass = [];
|
||||
const deferred = [];
|
||||
|
||||
for (const item of sorted) {
|
||||
const count = groupCounts[item.group] || 0;
|
||||
if (count < groupCap && firstPass.length < topN) {
|
||||
firstPass.push(item);
|
||||
groupCounts[item.group] = count + 1;
|
||||
} else {
|
||||
deferred.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
let selected = firstPass;
|
||||
if (selected.length < topN) {
|
||||
selected = selected.concat(deferred.slice(0, topN - selected.length));
|
||||
}
|
||||
selected = selected.slice(0, topN);
|
||||
|
||||
const selectedIds = new Set(selected.map((item) => item.ticket.id));
|
||||
const notSelected = sorted.filter((item) => !selectedIds.has(item.ticket.id));
|
||||
|
||||
return { selected, excluded: excluded.concat(notSelected) };
|
||||
}
|
||||
|
||||
module.exports = { selectTop };
|
||||
Reference in New Issue
Block a user