2015-08-17 23:32:00 +02:00
|
|
|
module Main where
|
|
|
|
|
2015-08-23 08:14:47 +02:00
|
|
|
import GEval.Core
|
2019-08-11 21:40:11 +02:00
|
|
|
import GEval.EvaluationScheme
|
2019-01-10 22:53:43 +01:00
|
|
|
import GEval.Common
|
2015-08-23 08:14:47 +02:00
|
|
|
import GEval.OptionsParser
|
2018-07-10 16:22:28 +02:00
|
|
|
import GEval.ParseParams
|
2020-01-28 20:32:09 +01:00
|
|
|
import GEval.Formatting
|
2015-08-17 23:32:00 +02:00
|
|
|
|
2015-08-23 08:14:47 +02:00
|
|
|
import System.Environment
|
2015-08-22 00:00:46 +02:00
|
|
|
import Options.Applicative
|
|
|
|
|
2018-06-08 12:38:45 +02:00
|
|
|
import System.IO
|
|
|
|
import System.Exit
|
|
|
|
|
2018-06-28 14:49:44 +02:00
|
|
|
import Data.Conduit.SmartSource
|
|
|
|
|
2020-01-04 20:48:36 +01:00
|
|
|
import Data.SplitIntoCrossTabs
|
|
|
|
|
2018-06-28 16:22:22 +02:00
|
|
|
import System.FilePath
|
|
|
|
|
2018-07-10 16:22:28 +02:00
|
|
|
import Data.List (intercalate, sort)
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
import Data.Map.Strict as M
|
2020-01-04 20:48:36 +01:00
|
|
|
import qualified Data.Map.Lazy as LM
|
2018-07-10 16:22:28 +02:00
|
|
|
import Data.Set as S
|
2018-06-28 16:22:22 +02:00
|
|
|
|
2020-01-27 22:06:33 +01:00
|
|
|
import Data.Conduit.Bootstrap (defaultConfidenceLevel, getConfidenceBounds)
|
|
|
|
|
2015-08-17 23:32:00 +02:00
|
|
|
main :: IO ()
|
|
|
|
main = do
|
2015-08-22 20:28:10 +02:00
|
|
|
args <- getArgs
|
2015-09-12 15:36:50 +02:00
|
|
|
result <- runGEvalGetOptions args
|
2015-08-22 20:28:10 +02:00
|
|
|
case result of
|
|
|
|
Left parseResult -> handleParseResult parseResult >> return ()
|
2018-06-08 12:38:45 +02:00
|
|
|
Right (opts, Just results) -> showTheResult opts results
|
2015-09-12 15:36:50 +02:00
|
|
|
Right (_, Nothing) -> return ()
|
|
|
|
|
2019-11-02 12:09:09 +01:00
|
|
|
showTheResult :: GEvalOptions -> [(SourceSpec, [MetricResult])] -> IO ()
|
2018-06-28 14:49:44 +02:00
|
|
|
showTheResult opts [(_, vals)] = showTheResult' opts vals
|
2018-06-28 16:22:22 +02:00
|
|
|
showTheResult opts [] = error "no output given"
|
|
|
|
showTheResult opts multipleResults = showTable opts multipleResults
|
|
|
|
|
2019-11-02 12:09:09 +01:00
|
|
|
showTable :: GEvalOptions -> [(SourceSpec, [MetricResult])] -> IO ()
|
2018-06-28 16:22:22 +02:00
|
|
|
showTable opts multipleResults = do
|
2018-07-10 16:22:28 +02:00
|
|
|
let params = Prelude.map (\(ss, _) -> parseParamsFromSourceSpec ss) multipleResults
|
|
|
|
|
|
|
|
let paramNames =
|
|
|
|
sort
|
|
|
|
$ S.toList
|
|
|
|
$ S.unions
|
|
|
|
$ Prelude.map (\(OutputFileParsed _ m) -> M.keysSet m)
|
|
|
|
$ params
|
|
|
|
|
|
|
|
case getHeader paramNames metrics of
|
|
|
|
Just header -> putStrLn header
|
|
|
|
Nothing -> return ()
|
|
|
|
|
|
|
|
mapM_ (\entry -> putStrLn $ formatTableEntry opts paramNames entry) $ zip multipleResults params
|
2018-06-28 16:22:22 +02:00
|
|
|
where metrics = gesMetrics $ geoSpec opts
|
|
|
|
|
2019-08-11 21:40:11 +02:00
|
|
|
getHeader :: [T.Text] -> [EvaluationScheme] -> Maybe String
|
2018-07-10 16:22:28 +02:00
|
|
|
getHeader [] [singleMetric] = Nothing
|
|
|
|
getHeader [] [] = error "no metric given"
|
2019-08-11 21:40:11 +02:00
|
|
|
getHeader [] schemes = Just $ intercalate "\t" ("File name" : Prelude.map evaluationSchemeName schemes)
|
|
|
|
getHeader params schemes = Just $ intercalate "\t" (Prelude.map T.unpack params
|
|
|
|
++ Prelude.map evaluationSchemeName schemes)
|
2018-07-10 16:22:28 +02:00
|
|
|
|
2019-11-02 12:09:09 +01:00
|
|
|
formatTableEntry :: GEvalOptions -> [T.Text] -> ((SourceSpec, [MetricResult]), OutputFileParsed) -> String
|
2018-07-10 16:22:28 +02:00
|
|
|
formatTableEntry opts paramNames ((sourceSpec, metrics), ofParsed) = intercalate "\t" ((initialColumns paramNames sourceSpec ofParsed) ++ vals)
|
2020-07-13 16:25:20 +02:00
|
|
|
where vals = Prelude.map (formatTheResult (gesFormatting $ geoSpec opts)) metrics
|
2018-07-10 16:22:28 +02:00
|
|
|
|
|
|
|
initialColumns :: [T.Text] -> SourceSpec -> OutputFileParsed -> [String]
|
|
|
|
initialColumns [] sourceSpec ofParsed = [formatSourceSpec sourceSpec]
|
|
|
|
initialColumns params sourceSpec (OutputFileParsed _ paramMap) =
|
|
|
|
Prelude.map (\p -> T.unpack $ M.findWithDefault (T.pack "") p paramMap) params
|
2018-06-28 14:49:44 +02:00
|
|
|
|
2019-11-02 12:09:09 +01:00
|
|
|
showTheResult' :: GEvalOptions -> [MetricResult] -> IO ()
|
2018-06-08 12:38:45 +02:00
|
|
|
-- do not show the metric if just one was given
|
2020-07-13 16:25:20 +02:00
|
|
|
showTheResult' opts [val] = putStrLn $ formatTheResult (gesFormatting $ geoSpec opts) val
|
2018-06-28 14:49:44 +02:00
|
|
|
showTheResult' opts [] = do
|
2018-06-08 12:38:45 +02:00
|
|
|
hPutStrLn stderr "no metric given, use --metric option"
|
|
|
|
exitFailure
|
2020-01-04 20:48:36 +01:00
|
|
|
showTheResult' opts vals = mapM_ putStrLn
|
|
|
|
$ intercalate [""]
|
2020-07-13 16:25:20 +02:00
|
|
|
$ Prelude.map (formatCrossTable (gesFormatting $ geoSpec opts))
|
2020-01-04 20:48:36 +01:00
|
|
|
$ splitIntoTablesWithValues (T.pack "metric") (T.pack "value") mapping metricLabels
|
|
|
|
where mapping = LM.fromList $ zip metricLabels vals
|
|
|
|
metricLabels = Prelude.map T.pack $ Prelude.map evaluationSchemeName $ gesMetrics $ geoSpec opts
|
|
|
|
|
2020-07-13 16:25:20 +02:00
|
|
|
formatCrossTable :: FormattingOptions -> TableWithValues MetricResult -> [String]
|
|
|
|
formatCrossTable format (TableWithValues [_, _] body) =
|
2020-01-04 20:48:36 +01:00
|
|
|
-- actually we won't print metric/value header
|
|
|
|
-- (1) to keep backward-compatible with the previous version
|
|
|
|
-- (2) to be concise
|
2020-07-13 16:25:20 +02:00
|
|
|
Prelude.map (formatCrossTableLine format) body
|
|
|
|
formatCrossTable format (TableWithValues header body) =
|
|
|
|
(intercalate "\t" $ Prelude.map T.unpack header) : Prelude.map (formatCrossTableLine format) body
|
2020-01-04 20:48:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-07-13 16:25:20 +02:00
|
|
|
formatCrossTableLine :: FormattingOptions-> (T.Text, [MetricResult]) -> String
|
|
|
|
formatCrossTableLine format (rowName, values) =
|
|
|
|
intercalate "\t" ((T.unpack rowName):Prelude.map (formatTheResult format) values)
|
2018-06-08 12:38:45 +02:00
|
|
|
|
2018-06-28 16:22:22 +02:00
|
|
|
formatSourceSpec :: SourceSpec -> String
|
|
|
|
formatSourceSpec (FilePathSpec fp) = dropExtensions $ takeFileName fp
|
|
|
|
formatSourceSpec spec = show spec
|
|
|
|
|
2020-07-13 16:25:20 +02:00
|
|
|
formatTheMetricAndResult :: FormattingOptions -> (EvaluationScheme, MetricResult) -> String
|
|
|
|
formatTheMetricAndResult format (scheme, val) = (evaluationSchemeName scheme) ++ "\t" ++ (formatTheResult format val)
|