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