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

Support nesting MultipleReportResults in RepeatedReportResults #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 20 additions & 1 deletion src/Stats.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import qualified Data.Strict as Strict
import Data.Traversable (sequenceA)
import Control.Arrow
import Debug.Trace
import GHC.Stack

import Data
import Categorize
Expand Down Expand Up @@ -389,12 +390,13 @@ renderReport opts (MultipleReportResults reports) =
renderReport opts reportdata =
putStr $ doRender opts reportdata

doRender :: ReportOptions -> ReportResults -> String
doRender :: HasCallStack => ReportOptions -> ReportResults -> String
doRender opts reportdata = case roReportFormat opts of
RFText -> renderReportText id reportdata
RFCSV -> renderWithDelimiter "," $ renderXSV reportdata
RFTSV -> renderWithDelimiter "\t" $ renderXSV reportdata

renderReportText :: HasCallStack => (String -> String) -> ReportResults -> String
renderReportText titleMod (ListOfFields title dats) =
underline (titleMod title) ++
tabulate False (map (\(f,v) -> [f,v]) dats)
Expand All @@ -412,6 +414,11 @@ renderReportText titleMod (RepeatedReportResults cat reps) =
intercalate "\n" $ map (\(v,rr) -> renderReportText (titleMod . mod v) rr) reps
where mod v s = s ++ " (" ++ cat ++ " " ++ v ++ ")"

renderReportText titleMod (MultipleReportResults reps) =
intercalate "\n" $ map (renderReportText titleMod) reps

renderReportText _ (DumpResult _) = error "renderReportText: Cannot handle DumpResult"

listOfValues dats =
["Tag","Time","Percentage"] :
map (\(f,t,p) -> [f,t,printf "%.2f" (p*100)]) dats
Expand All @@ -424,6 +431,8 @@ listOfIntervals dats =
["Tag","From","Until","Duration"] :
map (\(t,f,u,d) -> [t,f,u,d]) dats

renderXSV :: HasCallStack => ReportResults -> [[String]]

-- The reporting of "General Information" is not supported for the
-- comma-separated output format.
renderXSV (ListOfFields title dats) =
Expand All @@ -441,6 +450,16 @@ renderXSV (RepeatedReportResults cat reps) = title : fields
title = cat : head (renderXSV (snd (head reps)))
fields = concatMap (\(v,rr) -> map (v:) (tail (renderXSV rr))) reps

-- Also code-smelly; take the first title line as the title line, but it could differ…
-- E.g. arbtt-stats --each-category --for-each=year --filter '$sampleage < 24000:00'
-- (Although there the title line does not differ and the title is simply dropped in the XSV output.)
renderXSV (MultipleReportResults reps) = title : fields
where
title = head (renderXSV (head reps))
fields = concatMap (tail . renderXSV) reps

renderXSV (DumpResult _) = error "renderXSV: Cannot handle DumpResult"

renderWithDelimiter :: String -> [[String]] -> String
renderWithDelimiter delim datasource =
unlines $ map (intercalate delim) datasource
Expand Down