+-- A summary table, useful only when we are comparing two runs. This table
+-- shows a number of different result categories, one per column.
+ascii_summary_table
+ :: Bool -- generate a LaTeX table?
+ -> [ResultTable]
+ -> [PerProgTableSpec]
+ -> Maybe [String]
+ -> ShowS
+ascii_summary_table latex (r1:r2:_) specs mb_restrict
+ | latex = makeLatexTable (rows ++ TableLine : av_rows)
+ | otherwise =
+ makeTable (table_layout (length specs) width)
+ (TableLine : TableRow header : TableLine : rows ++ TableLine : av_rows)
+ where
+ header = BoxString "Program" : map BoxString headings
+
+ (headings, columns, av_cols) = unzip3 (map calc_col specs)
+ av_heads = [BoxString "Min", BoxString "Max", BoxString "Geometric Mean"]
+ baseline = fmToList r1
+ progs = map BoxString (keysFM r1)
+ rows0 = map TableRow (zipWith (:) progs (transpose columns))
+
+ rows1 = restrictRows mb_restrict rows0
+
+ rows | latex = mungeForLaTeX rows1
+ | otherwise = rows1
+
+ av_rows = map TableRow (zipWith (:) av_heads (transpose av_cols))
+ width = 10
+
+ calc_col (SpecP _ heading _ getr gets ok)
+ = (heading, column, [min,max,mean]) -- throw away the baseline result
+ where (_, boxes) = unzip (map calc_one_result baseline)
+ calc_one_result = calc_result [r2] getr gets ok
+ column = map (\(_:b:_) -> b) boxes
+ (_,mean,_) = calc_gmsd column
+ (min,max) = calc_minmax column
+
+restrictRows :: Maybe [String] -> [TableRow] -> [TableRow]
+restrictRows Nothing rows = rows
+restrictRows (Just these) rows = filter keep_it rows
+ where keep_it (TableRow (BoxString s: _)) = s `elem` these
+ keep_it TableLine = True
+ keep_it _ = False
+
+mungeForLaTeX :: [TableRow] -> [TableRow]
+mungeForLaTeX = map transrow
+ where
+ transrow (TableRow boxes) = TableRow (map transbox boxes)
+ transrow row = row
+
+ transbox (BoxString s) = BoxString (foldr transchar "" s)
+ transbox box = box
+
+ transchar '_' s = '\\':'_':s
+ transchar c s = c:s
+
+table_layout n width =
+ (str . rjustify 15) :
+ (\s -> str (space 5) . str (rjustify width s)) :
+ replicate (n-1) (str . rjustify width)
+