From 99d112b31c27f848472791b2867b83b2a01265a0 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Thu, 26 Apr 2018 18:28:26 +0200 Subject: [PATCH] Don't attempt to dequeue corrector who isn't (also) proportional --- src/Handler/Utils/Submission.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Handler/Utils/Submission.hs b/src/Handler/Utils/Submission.hs index 169fbcc05..6c14cb496 100644 --- a/src/Handler/Utils/Submission.hs +++ b/src/Handler/Utils/Submission.hs @@ -50,7 +50,7 @@ instance Exception AssignSubmissionException assignSubmissions :: SheetId -> YesodDB UniWorX () assignSubmissions sid = do correctors <- selectList [SheetCorrectorSheet ==. sid] [] - let (corrsGroup, corrsProp) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors + let (corrsGroup, (filterNonPositive -> corrsProp)) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors countsToLoad' :: UserId -> Bool countsToLoad' uid = fromMaybe (error "Called `countsToLoad'` on entity not element of `corrsGroup`") $ listToMaybe [sheetCorrectorLoad | Entity _ SheetCorrector{..} <- corrsGroup, sheetCorrectorUser == uid] >>= preview _ByTutorial subs <- E.select . E.from $ \(submission `E.LeftOuterJoin` user) -> do @@ -74,7 +74,7 @@ assignSubmissions sid = do subTutor <- fmap fst . flip execStateT (Map.empty, queue) . forM_ (Map.toList subTutor') $ \case (smid, Just tutid) -> do _1 %= Map.insert smid tutid - when (countsToLoad' tutid) $ + when (any ((== tutid) . sheetCorrectorUser . entityVal) corrsProp && countsToLoad' tutid) $ _2 %= delFirst (Just tutid) (smid, Nothing) -> do (q:qs) <- use _2 @@ -87,6 +87,8 @@ assignSubmissions sid = do return () where + filterNonPositive = filter $ (> 0) . load . sheetCorrectorLoad . entityVal + delFirst _ [] = [] delFirst x (y:ys) | x == y = ys