revert data api and fix repeating availabilities

This commit is contained in:
Dobromir Popov
2024-05-28 01:41:42 +03:00
parent f7aeea65b9
commit 57a292a9f3
3 changed files with 49 additions and 11 deletions

View File

@ -956,13 +956,15 @@ async function RankPublishersForShiftWeighted(publishers, scheduledPubsPerDayAnd
p.desiredCompletion = p.currentMonthAssignments / p.desiredShiftsPerMonth;
});
const calculateScore = (p) => {
const calculateScoreAndPenalties = (p) => {
let score = (p.isMale ? weights.gender : 0) -
(p.desiredCompletion * weights.desiredCompletion) +
((1 - p.currentMonthAvailabilityHoursCount / 24) * weights.availability) +
(p.currentMonthAssignments * weights.lastMonthCompletion) -
(p.currentMonthAssignments * weights.currentAssignments);
let penalties = [];
// Apply penalties based on proximity to current day
for (let i = 1; i <= 6; i++) {
const previousDayKey = common.getISODateOnly(addDays(currentDay, -i));
@ -972,21 +974,33 @@ async function RankPublishersForShiftWeighted(publishers, scheduledPubsPerDayAnd
if (flattenRegistry(previousDayKey).includes(p.id)) {
score *= penalty;
penalties.push({ day: previousDayKey, penalty });
}
if (flattenRegistry(nextDayKey).includes(p.id)) {
score *= penalty;
penalties.push({ day: nextDayKey, penalty });
}
}
return score;
return { score, penalties };
};
let ranked = publishers.sort((a, b) => {
const scoreA = calculateScore(a);
const scoreB = calculateScore(b);
return scoreB - scoreA; // Sort descending by score
// Calculate scores and penalties for each publisher
publishers.forEach(p => {
const result = calculateScoreAndPenalties(p);
p.score = result.score;
p.penalties = result.penalties;
});
// Sort publishers based on score
let ranked = publishers.sort((a, b) => b.score - a.score);
// Log the scores and penalties of the top publisher
if (ranked.length > 0) {
console.log(`Top Publisher: ${ranked[0].name}`);
console.log(`Score: ${ranked[0].score}`);
console.log(`Penalties:`, ranked[0].penalties);
}
return ranked;
}