datatype Load refactored as discussed

This commit is contained in:
SJost 2018-05-04 18:12:54 +02:00
parent 38e438b774
commit e4c0913c12
5 changed files with 21 additions and 9 deletions

3
models
View File

@ -79,7 +79,7 @@ Lecturer
user UserId user UserId
course CourseId course CourseId
UniqueLecturer user course UniqueLecturer user course
Corrector Corrector -- deprecated
user UserId user UserId
course CourseId course CourseId
load Load load Load
@ -117,6 +117,7 @@ SheetCorrector
user UserId user UserId
sheet SheetId sheet SheetId
load Load load Load
UniqueSheetCorrector user sheet
SheetFile SheetFile
sheet SheetId sheet SheetId
file FileId file FileId

View File

@ -124,7 +124,7 @@ postSubmissionR tid csh shn (SubmissionMode mcid) = do
E.on (user E.^. UserId E.==. submissionEdit E.^. SubmissionEditUser) E.on (user E.^. UserId E.==. submissionEdit E.^. SubmissionEditUser)
E.where_ $ submissionEdit E.^. SubmissionEditSubmission E.==. E.val smid E.where_ $ submissionEdit E.^. SubmissionEditSubmission E.==. E.val smid
E.orderBy [E.desc $ submissionEdit E.^. SubmissionEditTime] E.orderBy [E.desc $ submissionEdit E.^. SubmissionEditTime]
E.limit 10 E.limit 3 -- TODO for Debug Purposes
return $ (user E.^. UserDisplayName, submissionEdit E.^. SubmissionEditTime) return $ (user E.^. UserDisplayName, submissionEdit E.^. SubmissionEditTime)
let lastEdits = map (bimap E.unValue E.unValue) lastEditValues let lastEdits = map (bimap E.unValue E.unValue) lastEditValues
return (sheet,buddies,oldfiles,lastEdits) return (sheet,buddies,oldfiles,lastEdits)

View File

@ -56,9 +56,15 @@ assignSubmissions ::
) )
assignSubmissions sid = do assignSubmissions sid = do
correctors <- selectList [SheetCorrectorSheet ==. sid] [] correctors <- selectList [SheetCorrectorSheet ==. sid] []
let (corrsGroup, (filterNonPositive -> corrsProp)) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors let corrsGroup = filter hasTutorialLoad correctors -- needed as List within Esqueleto
countsToLoad' :: UserId -> Bool let corrsProp = filter hasPositiveLoad correctors
countsToLoad' uid = fromMaybe (error "Called `countsToLoad'` on entity not element of `corrsGroup`") $ listToMaybe [sheetCorrectorLoad | Entity _ SheetCorrector{..} <- corrsGroup, sheetCorrectorUser == uid] >>= preview _ByTutorial let countsToLoad' :: UserId -> Bool
countsToLoad' uid = -- refactor by simply using Map.(!)
fromMaybe (error "Called `countsToLoad'` on entity not element of `corrsGroup`") $
Map.lookup uid loadMap
loadMap :: Map UserId Bool
loadMap = Map.fromList [(sheetCorrectorUser,b) | Entity _ SheetCorrector{ sheetCorrectorLoad = (Load {byTutorial = Just b}), .. } <- corrsGroup]
subs <- E.select . E.from $ \(submission `E.LeftOuterJoin` user) -> do subs <- E.select . E.from $ \(submission `E.LeftOuterJoin` user) -> do
let tutors = E.subList_select . E.from $ \(submissionUser `E.InnerJoin` tutorialUser `E.InnerJoin` tutorial) -> do let tutors = E.subList_select . E.from $ \(submissionUser `E.InnerJoin` tutorialUser `E.InnerJoin` tutorial) -> do
-- Uncomment next line for equal chance between tutors, irrespective of the number of students per tutor per submission group -- Uncomment next line for equal chance between tutors, irrespective of the number of students per tutor per submission group
@ -72,7 +78,7 @@ assignSubmissions sid = do
E.orderBy [E.rand] -- randomize for fair tutor distribution E.orderBy [E.rand] -- randomize for fair tutor distribution
return (submission E.^. SubmissionId, user) -- , listToMaybe tutors) return (submission E.^. SubmissionId, user) -- , listToMaybe tutors)
queue <- liftIO . Rand.evalRandIO . sequence . repeat $ Rand.weightedMay [ (sheetCorrectorUser, load sheetCorrectorLoad) | Entity _ SheetCorrector{..} <- corrsProp] queue <- liftIO . Rand.evalRandIO . sequence . repeat $ Rand.weightedMay [ (sheetCorrectorUser, byProportion sheetCorrectorLoad) | Entity _ SheetCorrector{..} <- corrsProp]
let subTutor' :: Map SubmissionId (Maybe UserId) let subTutor' :: Map SubmissionId (Maybe UserId)
subTutor' = Map.fromListWith (<|>) $ map (over (_2.traverse) entityKey . over _1 E.unValue) subs subTutor' = Map.fromListWith (<|>) $ map (over (_2.traverse) entityKey . over _1 E.unValue) subs
@ -95,7 +101,8 @@ assignSubmissions sid = do
unassigendSubmissions = Map.keysSet subTutor' \\ assignedSubmissions unassigendSubmissions = Map.keysSet subTutor' \\ assignedSubmissions
return (assignedSubmissions, unassigendSubmissions) return (assignedSubmissions, unassigendSubmissions)
where where
filterNonPositive = filter $ (> 0) . load . sheetCorrectorLoad . entityVal hasPositiveLoad = (> 0) . byProportion . sheetCorrectorLoad . entityVal
hasTutorialLoad = isJust . byTutorial . sheetCorrectorLoad . entityVal

View File

@ -77,7 +77,11 @@ data ExamStatus = Attended | NoShow | Voided
deriving (Show, Read, Eq, Ord, Enum, Bounded) deriving (Show, Read, Eq, Ord, Enum, Bounded)
derivePersistField "ExamStatus" derivePersistField "ExamStatus"
data Load = ByTutorial { countsToLoad :: Bool } | ByProportion { load :: Rational } -- | Specify a corrector's workload
data Load -- = ByTutorial { countsToLoad :: Bool } | ByProportion { load :: Rational }
= Load { byTutorial :: Maybe Bool -- ^ Just all from Tutorial, True if counting towards overall workload
, byProportion :: Rational -- ^ workload proportion of all submission not assigned to tutorial leaders
}
deriving (Show, Read, Eq) deriving (Show, Read, Eq)
derivePersistField "Load" derivePersistField "Load"

View File

@ -12,4 +12,4 @@ makeClassy_ ''Entity
makeClassy_ ''SheetCorrector makeClassy_ ''SheetCorrector
makeClassyPrisms ''Load -- makeClassy_ ''Load