Automatisierte Korrektur-Zuteilung

This commit is contained in:
Gregor Kleen 2018-06-29 20:55:06 +02:00
parent 1dce109ac1
commit 89f83925ba
4 changed files with 42 additions and 5 deletions

View File

@ -123,9 +123,12 @@ SelectColumn: Auswahl
CorrDownload: Herunterladen CorrDownload: Herunterladen
CorrSetCorrector: Korrektor zuweisen CorrSetCorrector: Korrektor zuweisen
CorrAutoSetCorrector: Korrekturen verteilen
NatField xyz@Text: #{xyz} muss eine natürliche Zahl sein! NatField xyz@Text: #{xyz} muss eine natürliche Zahl sein!
SubmissionsAlreadyAssigned: Folgende Abgaben waren bereits einem Korrektor zugeteilt und wurden nicht verändert: SubmissionsAlreadyAssigned num@Int64: #{display num} Abgaben waren bereits einem Korrektor zugeteilt und wurden nicht verändert:
UpdatedAssignedCorrectors num@Int64: #{display num} Abgaben wurden dem neuen Korrektor zugeteilt. UpdatedAssignedCorrectorSingle num@Int64: #{display num} Abgaben wurden dem neuen Korrektor zugeteilt.
NoCorrector: Kein Korrektor NoCorrector: Kein Korrektor
RemovedCorrections num@Int64: Korrektur-Daten wurden von #{display num} Abgaben entfernt. RemovedCorrections num@Int64: Korrektur-Daten wurden von #{display num} Abgaben entfernt.
UpdatedAssignedCorrectorsAuto num@Int64: #{display num} Abgaben wurden unter den Korrektoren aufgeteilt.
CouldNotAssignCorrectorsAuto num@Int64: #{display num} Abgaben konnten nicht automatisch zugewiesen werden:

View File

@ -54,6 +54,8 @@ import Text.Blaze.Html (preEscapedToHtml)
import Database.Persist.Sql (updateWhereCount) import Database.Persist.Sql (updateWhereCount)
import Data.List (genericLength)
type CorrectionsWhere = forall query expr backend . (E.Esqueleto query expr backend) => type CorrectionsWhere = forall query expr backend . (E.Esqueleto query expr backend) =>
@ -172,6 +174,7 @@ makeCorrectionsTable whereClause colChoices psValidator = do
data ActionCorrections = CorrDownload data ActionCorrections = CorrDownload
| CorrSetCorrector | CorrSetCorrector
| CorrAutoSetCorrector
deriving (Eq, Ord, Read, Show, Enum, Bounded) deriving (Eq, Ord, Read, Show, Enum, Bounded)
instance PathPiece ActionCorrections where instance PathPiece ActionCorrections where
fromPathPiece = readFromPathPiece fromPathPiece = readFromPathPiece
@ -180,9 +183,11 @@ instance PathPiece ActionCorrections where
instance RenderMessage UniWorX ActionCorrections where instance RenderMessage UniWorX ActionCorrections where
renderMessage m ls CorrDownload = renderMessage m ls MsgCorrDownload renderMessage m ls CorrDownload = renderMessage m ls MsgCorrDownload
renderMessage m ls CorrSetCorrector = renderMessage m ls MsgCorrSetCorrector renderMessage m ls CorrSetCorrector = renderMessage m ls MsgCorrSetCorrector
renderMessage m ls CorrAutoSetCorrector = renderMessage m ls MsgCorrAutoSetCorrector
data ActionCorrectionsData = CorrDownloadData data ActionCorrectionsData = CorrDownloadData
| CorrSetCorrectorData (Maybe UserId) | CorrSetCorrectorData (Maybe UserId)
| CorrAutoSetCorrectorData SheetId
correctionsR :: _ -> _ -> _ -> Map ActionCorrections (MForm (HandlerT UniWorX IO) (FormResult ActionCorrectionsData, Widget)) -> Handler TypedContent correctionsR :: _ -> _ -> _ -> Map ActionCorrections (MForm (HandlerT UniWorX IO) (FormResult ActionCorrectionsData, Widget)) -> Handler TypedContent
correctionsR whereClause (formColonnade -> displayColumns) psValidator actions = do correctionsR whereClause (formColonnade -> displayColumns) psValidator actions = do
@ -211,7 +216,7 @@ correctionsR whereClause (formColonnade -> displayColumns) psValidator actions =
let unassigned = Set.fromList subs `Set.difference` Set.fromList (entityKey <$> alreadyAssigned) let unassigned = Set.fromList subs `Set.difference` Set.fromList (entityKey <$> alreadyAssigned)
when (not $ null unassigned) $ do when (not $ null unassigned) $ do
num <- updateWhereCount [SubmissionId <-. Set.toList unassigned] [SubmissionRatingBy =. Just uid] num <- updateWhereCount [SubmissionId <-. Set.toList unassigned] [SubmissionRatingBy =. Just uid]
addMessageI "success" $ MsgUpdatedAssignedCorrectors num addMessageI "success" $ MsgUpdatedAssignedCorrectorSingle num
redirect currentRoute redirect currentRoute
FormSuccess (CorrSetCorrectorData Nothing, subs') -> do FormSuccess (CorrSetCorrectorData Nothing, subs') -> do
subs <- mapM decrypt $ Set.toList subs' subs <- mapM decrypt $ Set.toList subs'
@ -223,6 +228,24 @@ correctionsR whereClause (formColonnade -> displayColumns) psValidator actions =
] ]
addMessageI "success" $ MsgRemovedCorrections num addMessageI "success" $ MsgRemovedCorrections num
redirect currentRoute redirect currentRoute
FormSuccess (CorrAutoSetCorrectorData shid, subs') -> do
subs <- mapM decrypt $ Set.toList subs'
runDB $ do
alreadyAssigned <- selectList [SubmissionId <-. subs, SubmissionRatingBy !=. Nothing] []
when (not $ null alreadyAssigned) $ do
mr <- (toHtml . ) <$> getMessageRender
alreadyAssigned' <- forM alreadyAssigned $ \Entity{..} -> (, entityVal) <$> (encrypt entityKey :: DB CryptoFileNameSubmission)
addMessage "warn" =<< withUrlRenderer ($(ihamletFile "templates/messages/submissionsAlreadyAssigned.hamlet") mr)
let unassigned = Set.fromList subs `Set.difference` Set.fromList (entityKey <$> alreadyAssigned)
when (not $ null unassigned) $ do
(assigned, unassigned) <- assignSubmissions shid (Just unassigned)
when (not $ null assigned) $
addMessageI "success" $ MsgUpdatedAssignedCorrectorsAuto (fromIntegral $ Set.size assigned)
when (not $ null unassigned) $ do
mr <- (toHtml . ) <$> getMessageRender
unassigned' <- forM (Set.toList unassigned) $ \sid -> (encrypt sid :: DB CryptoFileNameSubmission)
addMessage "warn" =<< withUrlRenderer ($(ihamletFile "templates/messages/submissionsNotAssignedAuto.hamlet") mr)
redirect currentRoute
fmap toTypedContent . defaultLayout $ do fmap toTypedContent . defaultLayout $ do
setTitleI MsgCourseCorrectionsTitle setTitleI MsgCourseCorrectionsTitle
@ -257,6 +280,11 @@ assignAction selId = ( CorrSetCorrector
fmap CorrSetCorrectorData <$> (traverse.traverse) decrypt cId fmap CorrSetCorrectorData <$> (traverse.traverse) decrypt cId
) )
autoAssignAction :: SheetId -> ActionCorrections'
autoAssignAction shid = ( CorrAutoSetCorrector
, return (pure $ CorrAutoSetCorrectorData shid, mempty)
)
getCorrectionsR, postCorrectionsR :: Handler TypedContent getCorrectionsR, postCorrectionsR :: Handler TypedContent
getCorrectionsR = postCorrectionsR getCorrectionsR = postCorrectionsR
postCorrectionsR = do postCorrectionsR = do
@ -310,4 +338,5 @@ postSSubsR tid csh shn = do
correctionsR whereClause colonnade psValidator $ Map.fromList correctionsR whereClause colonnade psValidator $ Map.fromList
[ downloadAction [ downloadAction
, assignAction (Right shid) , assignAction (Right shid)
, autoAssignAction shid
] ]

View File

@ -1,4 +1,4 @@
_{MsgSubmissionsAlreadyAssigned} _{MsgSubmissionsAlreadyAssigned (genericLength alreadyAssigned')}
<ul> <ul>
$forall (cID, _) <- alreadyAssigned' $forall (cID, _) <- alreadyAssigned'

View File

@ -0,0 +1,5 @@
_{MsgCouldNotAssignCorrectorsAuto (genericLength unassigned')}
<ul>
$forall cID <- unassigned'
<li><pre>#{toPathPiece cID}