From 640326ca5de12c21f87fe728bde69c21d8444320 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sun, 20 Oct 2019 11:02:32 +0200 Subject: [PATCH] fix(assign-submissions): avoid division by zero --- src/Handler/Utils/Submission.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index 4df32cd24..8304c1ec8 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -197,6 +197,10 @@ planSubmissions sid restriction = do proportionSum = getSum . foldMap corrProportion . fromMaybe Map.empty $ correctors !? sheetId where corrProportion (_, CorrectorExcused) = mempty corrProportion (Load{..}, _) = Sum byProportion + relativeProportion :: Rational -> Rational + relativeProportion prop + | proportionSum == 0 = 0 + | otherwise = prop / proportionSum extra | Just (Load{..}, corrState) <- correctors !? sheetId >>= Map.lookup corrector = sum @@ -208,7 +212,7 @@ planSubmissions sid restriction = do return . negate . fromIntegral . Map.size $ Map.filter (\(mCorr, tutors, sheetId') -> mCorr == Just corrector && sheetId == sheetId' && Map.member corrector tutors) submissionState , fromMaybe 0 $ do guard $ corrState /= CorrectorExcused - return . negate $ (byProportion / proportionSum) * fromIntegral sheetSize + return . negate $ relativeProportion byProportion * fromIntegral sheetSize ] | otherwise = assigned