diff --git a/backend/src/main/java/com/recipeapp/planning/PlanningService.java b/backend/src/main/java/com/recipeapp/planning/PlanningService.java index aeff635..4a4ae85 100644 --- a/backend/src/main/java/com/recipeapp/planning/PlanningService.java +++ b/backend/src/main/java/com/recipeapp/planning/PlanningService.java @@ -216,10 +216,6 @@ public class PlanningService { private double scoreFromSimulatedSlots(List slots, VarietyScoreConfig config, Set recentlyCookedIds) { List checkedTagTypes = config.getRepeatTagTypes(); - double wTagRepeat = config.getWTagRepeat().doubleValue(); - double wIngredientOverlap = config.getWIngredientOverlap().doubleValue(); - double wRecentRepeat = config.getWRecentRepeat().doubleValue(); - double wPlanDuplicate = config.getWPlanDuplicate().doubleValue(); // 1. Tag-type repeats on consecutive days Map> tagDays = new LinkedHashMap<>(); @@ -259,11 +255,16 @@ public class PlanningService { .mapToLong(c -> c - 1) .sum(); + return applyPenalties(tagRepeatCount, ingredientOverlapCount, recentRepeatCount, duplicatePenaltyCount, config); + } + + private double applyPenalties(long tagRepeats, long ingredientOverlaps, long recentRepeats, + long duplicates, VarietyScoreConfig config) { double score = MAX_VARIETY_SCORE; - score -= tagRepeatCount * wTagRepeat; - score -= ingredientOverlapCount * wIngredientOverlap; - score -= recentRepeatCount * wRecentRepeat; - score -= duplicatePenaltyCount * wPlanDuplicate; + score -= tagRepeats * config.getWTagRepeat().doubleValue(); + score -= ingredientOverlaps * config.getWIngredientOverlap().doubleValue(); + score -= recentRepeats * config.getWRecentRepeat().doubleValue(); + score -= duplicates * config.getWPlanDuplicate().doubleValue(); return Math.max(0, Math.min(MAX_VARIETY_SCORE, score)); } @@ -281,10 +282,6 @@ public class PlanningService { .orElse(VarietyScoreConfig.defaults(plan.getHousehold())); List checkedTagTypes = config.getRepeatTagTypes(); - double wTagRepeat = config.getWTagRepeat().doubleValue(); - double wIngredientOverlap = config.getWIngredientOverlap().doubleValue(); - double wRecentRepeat = config.getWRecentRepeat().doubleValue(); - double wPlanDuplicate = config.getWPlanDuplicate().doubleValue(); int historyDays = config.getHistoryDays(); // 1. Tag-type repeats on consecutive days @@ -352,13 +349,7 @@ public class PlanningService { } } - // Calculate score - double score = MAX_VARIETY_SCORE; - score -= tagRepeats.size() * wTagRepeat; - score -= overlaps.size() * wIngredientOverlap; - score -= recentRepeats.size() * wRecentRepeat; - score -= duplicatePenaltyCount * wPlanDuplicate; - score = Math.max(0, Math.min(MAX_VARIETY_SCORE, score)); + double score = applyPenalties(tagRepeats.size(), overlaps.size(), recentRepeats.size(), duplicatePenaltyCount, config); return new VarietyScoreResponse(score, tagRepeats, overlaps, recentRepeats, duplicatesInPlan); }