Apply 5 suggestion(s) to 1 file(s)

This commit is contained in:
Wolfgang Witt 2021-02-26 16:32:18 +00:00
parent 85e3941538
commit 6ae1aeaeb0

View File

@ -274,11 +274,11 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
= case rule of = case rule of
ExamRoomRandom ExamRoomRandom
-> ( Nothing -> ( Nothing
, Map.union (Map.map snd assignedUsers) randomlyAssignedUsers , Map.union (view _2 <$> assignedUsers) randomlyAssignedUsers
) )
where where
assignedUsers,unassignedUsers :: Map UserId (User, Maybe ExamOccurrenceId) assignedUsers,unassignedUsers :: Map UserId (User, Maybe ExamOccurrenceId)
(assignedUsers, unassignedUsers) = Map.partition (isJust . snd) users (assignedUsers, unassignedUsers) = Map.partition (has $ _2 . _Just) users
shuffledUsers :: [UserId] shuffledUsers :: [UserId]
shuffledUsers = shuffle' (Map.keys unassignedUsers) (length unassignedUsers) (mkStdGen seed) shuffledUsers = shuffle' (Map.keys unassignedUsers) (length unassignedUsers) (mkStdGen seed)
occurrencesMap :: Map ExamOccurrenceId Natural occurrencesMap :: Map ExamOccurrenceId Natural
@ -292,9 +292,9 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
currentRatios :: Map ExamOccurrenceId (Ratio Natural) currentRatios :: Map ExamOccurrenceId (Ratio Natural)
currentRatios = Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched $ const (%)) currentOccurrences occurrencesMap currentRatios = Map.merge Map.dropMissing Map.dropMissing (Map.zipWithMatched $ const (%)) currentOccurrences occurrencesMap
biggestOutlier :: ExamOccurrenceId biggestOutlier :: ExamOccurrenceId
biggestOutlier = fst $ List.maximumBy (\a b -> compare (snd a) (snd b)) $ Map.toList currentRatios biggestOutlier = fst . List.maximumBy (comparing $ view _2) $ Map.toList currentRatios
extraCapacity :: Natural extraCapacity :: Natural
extraCapacity = sum (map snd occurrences'') - fromIntegral (length unassignedUsers) extraCapacity = sumOf (folded . _2) occurrences'' - fromIntegral (length unassignedUsers)
finalOccurrences :: [(ExamOccurrenceId, Natural)] finalOccurrences :: [(ExamOccurrenceId, Natural)]
finalOccurrences = Map.toList $ decreaseBiggestOutlier extraCapacity occurrencesMap finalOccurrences = Map.toList $ decreaseBiggestOutlier extraCapacity occurrencesMap
-- fill in users in a random order -- fill in users in a random order
@ -454,7 +454,7 @@ examAutoOccurrence (hash -> seed) rule ExamAutoOccurrenceConfig{..} occurrences
prevMin <- ST.readArray minima i prevMin <- ST.readArray minima i
let cost = prevMin + widthCost l potWidth w + breakCost' let cost = prevMin + widthCost l potWidth w + breakCost'
remainingWords = offsets Array.! Map.size wordMap - offsets Array.! i remainingWords = offsets Array.! Map.size wordMap - offsets Array.! i
remainingLineSpace = sum (map snd $ drop lineIx lineLengths) remainingLineSpace = sumOf (folded . _2) $ drop lineIx lineLengths
breakCost' breakCost'
| remainingWords > remainingLineSpace | remainingWords > remainingLineSpace
= PosInf = PosInf