From 44a52e034fe0f6423daf95d8422bff9080d91566 Mon Sep 17 00:00:00 2001 From: Wolfgang Witt Date: Tue, 2 Feb 2021 21:15:54 +0100 Subject: [PATCH] chore: filter out pre-filled rooms --- src/Handler/Utils/Exam.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Handler/Utils/Exam.hs b/src/Handler/Utils/Exam.hs index 211f27e4a..872d63c35 100644 --- a/src/Handler/Utils/Exam.hs +++ b/src/Handler/Utils/Exam.hs @@ -311,11 +311,14 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences occurrences' :: Map ExamOccurrenceId Natural -- ^ reduce room capacity for every pre-assigned user by 1 - occurrences' = foldl' (flip $ Map.adjust predOrZero) occurrences $ Map.mapMaybe snd users + occurrences' = foldl' (flip $ Map.update predToPositive) occurrences $ Map.mapMaybe snd users + -- FIXME what about capacity-0 in occurrences? + -- what if the first word is too big for the first room? where - predOrZero :: Natural -> Natural - predOrZero 0 = 0 - predOrZero n = pred n + predToPositive :: Natural -> Maybe Natural + predToPositive 0 = Nothing + predToPositive 1 = Nothing + predToPositive n = Just $ pred n occurrences'' :: [(ExamOccurrenceId, Natural)] -- ^ Minimise number of occurrences used