Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally show points when generating feedback #30

Merged
merged 1 commit into from
Apr 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ export_pdfMark js = do
-- Right newJs -> putStrLn $ show newJs
Left e -> report $ reportInvalid e

export_feedback :: [Judgement] -> IO ()
export_feedback js = do
export_feedback :: FeedbackOpts -> [Judgement] -> IO ()
export_feedback opts js = do
case (mapM interpProps js) of
Right newJs -> putStrLn $ exportFeedback newJs
Right newJs -> putStrLn $ exportFeedback opts newJs
-- Right newJs -> putStrLn $ show newJs
Left e -> report $ reportInvalid e

Expand Down Expand Up @@ -244,8 +244,12 @@ main = do
[] -> noCommand
("parse" : paths) ->
with paths $ putStrLn . pretty
("feedback" : "--with-points" : paths) ->
with paths $ mapM_ (export_feedback $
FeedbackOpts { withPoints = True })
("feedback" : paths) ->
with paths $ mapM_ export_feedback
with paths $ mapM_ (export_feedback $
FeedbackOpts { withPoints = False })
("check" : paths) ->
with paths $ mapM_ check
("valid" : paths) ->
Expand Down
6 changes: 3 additions & 3 deletions src/Export.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Export (exportFeedback, exportHTML, exportCSV, exportHTMLTable, exportResultsTable, exportMD, unify, summary, exportPdfMark) where
module Export (FeedbackOpts(..), exportFeedback, exportHTML, exportCSV, exportHTMLTable, exportResultsTable, exportMD, unify, summary, exportPdfMark) where

import Ast
import Invalid
Expand All @@ -25,8 +25,8 @@ exportHTMLTable js = toHTML $ transp $ htmlTableRemarks js
exportMD :: [Judgement] -> String
exportMD js = mdRemarks js

exportFeedback :: [Judgement] -> String
exportFeedback js = feedbackRemarks js
exportFeedback :: FeedbackOpts -> [Judgement] -> String
exportFeedback opts js = feedbackRemarks opts js

exportResultsTable :: [Judgement] -> String
exportResultsTable js = toCSV ";" $ transp $ resultsTableRemarks js
Expand Down
35 changes: 22 additions & 13 deletions src/Export/Feedback.hs
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