From 0670ea9ada2f44ffa1e65b8ea0003124da39145e Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Mon, 21 Sep 2015 11:59:52 -0400 Subject: [PATCH] Improve suppression of Additional Grader Comments Rather than emitting any time there's a comment block at all, scan to see if there are any non-whitespace bytes. Since the skeleton files always contain empty comment blocks, this should help in the case when graders do not delete them. --- lib/Grade/Parse.hs | 2 +- lib/Grade/Print.hs | 12 +++++++----- lib/Grade/Types.hs | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/Grade/Parse.hs b/lib/Grade/Parse.hs index fa6b2ba..df50f09 100644 --- a/lib/Grade/Parse.hs +++ b/lib/Grade/Parse.hs @@ -137,7 +137,7 @@ parseData defs = do T.string commentStart *> T.newline *> toUtf8 (T.sliced (T.manyTill T.anyChar (T.lookAhead cend))) <* cend _ <- T.whiteSpace - ((sn, ExDFS $ DFS smeta sat sc ds mcs) :) + ((sn, ExDFS $ DFS smeta sat sc ds (maybe "" id mcs)) :) <$> (modify (M.delete sn) >> go (M.insert sn () already)) cend = T.string commentEnd *> T.newline diff --git a/lib/Grade/Print.hs b/lib/Grade/Print.hs index fd85d5d..4ab609a 100644 --- a/lib/Grade/Print.hs +++ b/lib/Grade/Print.hs @@ -2,7 +2,9 @@ module Grade.Print where +import qualified Data.Char as C import qualified Data.Set as S +import qualified Data.Text as T import Numeric import Text.PrettyPrint.Free @@ -35,14 +37,14 @@ printGrade e t = brackets (p e <> "/" <> p t) <+> parens ((p $ e / t * 100.0) <> p x = text $ showFFloat (Just 1) x "" printSection :: ReportFileSection -> Doc e -printSection (RFS st ss smax sdc msgc) = +printSection (RFS st ss smax sdc sgc) = pretty st <> ":" <+> printGrade ss smax <> line `above` indent 1 (vcat (punctuate empty (map pretty sdc)) - <> maybe empty - (\x -> (if null sdc then empty else line) - <> "Additional Grader Comments:" <> line `above` indent 1 (pretty x)) - msgc) + <> (if null sdc then empty else line) <> magc sgc) + where + magc x = if T.any (not . C.isSpace) x then agc x else empty + agc x = "Additional Grader Comments:" <> line `above` indent 1 (pretty x) total :: ReportFile -> (Double,Double) total (RF secs) = foldr (\(RFS _ ss sm _ _) (e,t) -> (ss+e,sm+t)) (0.0,0.0) secs diff --git a/lib/Grade/Types.hs b/lib/Grade/Types.hs index 57b3a2c..8addb14 100644 --- a/lib/Grade/Types.hs +++ b/lib/Grade/Types.hs @@ -151,7 +151,7 @@ data DataFileSection sat sdt loc = DFS , _dfs_sec_arg :: sat , _dfs_loc :: loc , _dfs_dings :: [DataFileDing sdt loc] - , _dfs_grader_comments :: Maybe Text + , _dfs_grader_comments :: Text } deriving (Typeable) $(LTH.makeLenses ''DataFileSection) @@ -191,7 +191,7 @@ data ReportFileSection = RFS , _rfs_score :: Double , _rfs_max :: Double , _rfs_dingtext :: [Text] - , _rfs_comments :: Maybe Text + , _rfs_comments :: Text } deriving (Show, Typeable) $(LTH.makeLenses ''ReportFileSection) -- 2.50.1