assignment of submissions halfway done
This commit is contained in:
parent
988ee74fa8
commit
071e8c2de1
2
models
2
models
@ -115,7 +115,7 @@ SheetEdit
|
|||||||
sheet SheetId
|
sheet SheetId
|
||||||
SheetCorrector
|
SheetCorrector
|
||||||
user UserId
|
user UserId
|
||||||
sheet CourseId
|
sheet SheetId
|
||||||
load Load
|
load Load
|
||||||
SheetFile
|
SheetFile
|
||||||
sheet SheetId
|
sheet SheetId
|
||||||
|
|||||||
@ -79,6 +79,7 @@ dependencies:
|
|||||||
- parsec
|
- parsec
|
||||||
- uuid
|
- uuid
|
||||||
- exceptions
|
- exceptions
|
||||||
|
- lens
|
||||||
|
|
||||||
# The library contains all of our application code. The executable
|
# The library contains all of our application code. The executable
|
||||||
# defined below is just a thin wrapper.
|
# defined below is just a thin wrapper.
|
||||||
|
|||||||
@ -15,13 +15,22 @@ module Handler.Utils.Submission
|
|||||||
, sinkSubmission
|
, sinkSubmission
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Import
|
import Import -- hiding ()
|
||||||
|
|
||||||
|
import Control.Lens
|
||||||
|
import Control.Lens.Extras (is)
|
||||||
|
import Utils.Lens
|
||||||
|
|
||||||
import Control.Monad.State hiding (forM_)
|
import Control.Monad.State hiding (forM_)
|
||||||
|
|
||||||
|
import Data.Maybe
|
||||||
|
|
||||||
import Data.Set (Set)
|
import Data.Set (Set)
|
||||||
import qualified Data.Set as Set
|
import qualified Data.Set as Set
|
||||||
|
import Data.Map (Map)
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
|
|
||||||
import Data.Monoid (Monoid, Any(..))
|
import Data.Monoid (Monoid, Any(..))
|
||||||
import Generics.Deriving.Monoid (memptydefault, mappenddefault)
|
import Generics.Deriving.Monoid (memptydefault, mappenddefault)
|
||||||
|
|
||||||
@ -32,6 +41,35 @@ import qualified Database.Esqueleto as E
|
|||||||
import qualified Data.Conduit.List as Conduit
|
import qualified Data.Conduit.List as Conduit
|
||||||
|
|
||||||
|
|
||||||
|
assignSubmissions :: SheetId -> YesodDB UniWorX ()
|
||||||
|
assignSubmissions sid = do
|
||||||
|
correctors <- selectList [SheetCorrectorSheet ==. sid] []
|
||||||
|
let (corrsGroup, normalize -> corrsProp) = partition (is _ByTutorial . sheetCorrectorLoad . entityVal) correctors
|
||||||
|
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
|
||||||
|
-- Uncomment next line for equal chance between tutors, irrespective of the number of students per tutor per submission group
|
||||||
|
-- E.distinctOn [E.don $ tutorial E.^. TutorialTutor] $ do
|
||||||
|
E.on (tutorial E.^. TutorialId E.==. tutorialUser E.^. TutorialUserTutorial)
|
||||||
|
E.on (submissionUser E.^. SubmissionUserUser E.==. tutorialUser E.^. TutorialUserUser)
|
||||||
|
E.where_ (tutorial E.^. TutorialTutor `E.in_` E.valList (map (sheetCorrectorUser . entityVal) corrsGroup))
|
||||||
|
return $ tutorial E.^. TutorialTutor
|
||||||
|
E.on $ user E.?. UserId `E.in_` E.justList tutors
|
||||||
|
E.where_ $ submission E.^. SubmissionSheet E.==. E.val sid
|
||||||
|
E.orderBy [E.rand] -- randomize for fair tutor distribution
|
||||||
|
return (submission E.^. SubmissionId, user E.?. UserId) -- , listToMaybe tutors)
|
||||||
|
let subTutor :: Map SubmissionId (Maybe UserId)
|
||||||
|
subTutor = Map.fromListWith (<|>) $ map (bimap E.unValue E.unValue) subs
|
||||||
|
-- TODO: Continue here --
|
||||||
|
return ()
|
||||||
|
where
|
||||||
|
_Load :: Traversal' (Entity SheetCorrector) Rational
|
||||||
|
_Load = _entityVal . _sheetCorrectorLoad . _ByProportion
|
||||||
|
|
||||||
|
normalize :: [Entity SheetCorrector] -> [Entity SheetCorrector]
|
||||||
|
normalize corrsProp = corrsProp & each . _Load //~ sumOf (each . _Load) corrsProp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data SubmissionSinkState = SubmissionSinkState
|
data SubmissionSinkState = SubmissionSinkState
|
||||||
{ sinkSeenRating :: Any
|
{ sinkSeenRating :: Any
|
||||||
, sinkSubmissionTouched :: Any
|
, sinkSubmissionTouched :: Any
|
||||||
|
|||||||
@ -77,10 +77,16 @@ 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 | ByProportion Rational
|
data Load = ByTutorial { countsToLoad :: Bool } | ByProportion { load :: Rational }
|
||||||
deriving (Show, Read, Eq)
|
deriving (Show, Read, Eq)
|
||||||
derivePersistField "Load"
|
derivePersistField "Load"
|
||||||
|
|
||||||
|
{- Use (is _ByTutorial) instead of this unneeded definition:
|
||||||
|
isByTutorial :: Load -> Bool
|
||||||
|
isByTutorial (ByTutorial {}) = True
|
||||||
|
isByTutorial _ = False
|
||||||
|
-}
|
||||||
|
|
||||||
data Season = Summer | Winter
|
data Season = Summer | Winter
|
||||||
deriving (Show, Read, Eq, Ord, Enum, Bounded, Generic, Typeable)
|
deriving (Show, Read, Eq, Ord, Enum, Bounded, Generic, Typeable)
|
||||||
|
|
||||||
|
|||||||
15
src/Utils/Lens.hs
Normal file
15
src/Utils/Lens.hs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
{-# LANGUAGE NoImplicitPrelude #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
|
{-# LANGUAGE FunctionalDependencies #-}
|
||||||
|
module Utils.Lens where
|
||||||
|
|
||||||
|
import Import.NoFoundation
|
||||||
|
import Control.Lens
|
||||||
|
|
||||||
|
makeClassy_ ''Entity
|
||||||
|
|
||||||
|
makeClassy_ ''SheetCorrector
|
||||||
|
|
||||||
|
makeClassyPrisms ''Load
|
||||||
Reference in New Issue
Block a user