From 65bbd8081f6fc22077feb56ef66df3c0eb9c8bfd Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Fri, 25 Sep 2015 22:53:51 -0400 Subject: [PATCH] Add function for totaling report --- lib/Grade/Grade.hs | 6 +++++- lib/Grade/Print.hs | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Grade/Grade.hs b/lib/Grade/Grade.hs index 9ffab2e..35ffbe0 100644 --- a/lib/Grade/Grade.hs +++ b/lib/Grade/Grade.hs @@ -1,7 +1,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# OPTIONS_GHC -Wall #-} -module Grade.Grade (gradeOne) where +module Grade.Grade (gradeOne, totalReport) where import Control.Lens import Data.Either @@ -42,3 +42,7 @@ gradeOne (Defs defs _) (DF dfss) = Right _ -> Left [e] where processSec (sn,s) = bimap (RESectionError sn . pure . SEScoreError) id $ processDFS s + +totalReport :: ReportFile -> (Double,Double) +totalReport (RF secs) = foldr (\(RFS _ ss sm _ _) (e,t) -> (ss+e,sm+t)) (0.0,0.0) secs + diff --git a/lib/Grade/Print.hs b/lib/Grade/Print.hs index f5a8af9..474ed59 100644 --- a/lib/Grade/Print.hs +++ b/lib/Grade/Print.hs @@ -9,6 +9,7 @@ import Numeric import Text.PrettyPrint.Free import Grade.Types +import Grade.Grade printSectionError :: (loc -> Doc e) -> SectionError loc -> Doc e printSectionError pl (SEUndefinedDing dn dl) = @@ -46,10 +47,8 @@ printSection (RFS st ss smax sdc sgc) = 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 printReport :: ReportFile -> Doc e printReport r@(RF s) = vcat (map printSection s) <> line - <> "TOTAL:" <+> (uncurry printGrade $ total r) <> line + <> "TOTAL:" <+> (uncurry printGrade $ totalReport r) <> line -- 2.50.1