-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from DIKU-EDU/feat/oleks/optionally-show-point…
…s-with-feedback Optionally show points when generating feedback
- Loading branch information
Showing
3 changed files
with
33 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,34 @@ | ||
module Export.Feedback (feedbackRemarks) where | ||
module Export.Feedback (FeedbackOpts(..), feedbackRemarks) where | ||
|
||
import Ast | ||
import Export.Generic | ||
|
||
import Prelude hiding ((<>)) | ||
import Text.PrettyPrint | ||
|
||
feedbackRemarks :: [Judgement] -> String | ||
feedbackRemarks = render . vcat . map (formatJudgement 1) | ||
newtype FeedbackOpts | ||
= FeedbackOpts { | ||
withPoints :: Bool | ||
} | ||
|
||
formatJudgement :: Int -> Judgement -> Doc | ||
formatJudgement _ (Feedback (_, t)) = text t | ||
formatJudgement _ (Bonus (_, _, _)) = empty | ||
formatJudgement depth (j @ (Judgement (_, _, _, judgements))) = | ||
feedbackRemarks :: FeedbackOpts -> [Judgement] -> String | ||
feedbackRemarks opts = render . vcat . map (formatJudgement opts 1) | ||
|
||
formatJudgement :: FeedbackOpts -> Int -> Judgement -> Doc | ||
formatJudgement _ _ (Feedback (_, t)) = text t | ||
formatJudgement _ _ (Bonus (_, _, _)) = empty | ||
formatJudgement opts depth (j @ (Judgement (_, _, _, judgements))) = | ||
case isEmpty subj of | ||
True -> empty | ||
False -> formatHeader depth j $+$ text "" $+$ subj $+$ text "" | ||
False -> formatHeader (withPoints opts) depth j | ||
$+$ text "" $+$ subj $+$ text "" | ||
where | ||
subj = vcat $ map (formatJudgement (depth + 1)) judgements | ||
|
||
formatHeader :: Int -> Judgement -> Doc | ||
formatHeader depth j = | ||
(text $ replicate depth '#') <+> lookupTitle j | ||
subj = vcat $ map (formatJudgement opts (depth + 1)) judgements | ||
|
||
formatHeader :: Bool -> Int -> Judgement -> Doc | ||
formatHeader showPoints depth j = | ||
let points = if showPoints | ||
then colon <> space <> | ||
lookupTotal j <> text "/" <> lookupMaxPoints j | ||
else empty | ||
in (text $ replicate depth '#') <+> lookupTitle j <> points |