add --precision option
This commit is contained in:
parent
e96f16b829
commit
085ef0ec9e
15
app/Main.hs
15
app/Main.hs
@ -6,11 +6,20 @@ import GEval.OptionsParser
|
|||||||
import System.Environment
|
import System.Environment
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
|
||||||
|
import Text.Printf
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
result <- runGEval args
|
result <- runGEvalGetOptions args
|
||||||
case result of
|
case result of
|
||||||
Left parseResult -> handleParseResult parseResult >> return ()
|
Left parseResult -> handleParseResult parseResult >> return ()
|
||||||
Right (Just result) -> print $ result
|
Right (opts, Just result) -> showTheResult opts result
|
||||||
Right Nothing -> return ()
|
Right (_, Nothing) -> return ()
|
||||||
|
|
||||||
|
showTheResult :: GEvalOptions -> MetricValue -> IO ()
|
||||||
|
showTheResult opts val = putStrLn $ formatTheResult (geoPrecision opts) val
|
||||||
|
|
||||||
|
formatTheResult :: Maybe Int -> MetricValue -> String
|
||||||
|
formatTheResult Nothing = show
|
||||||
|
formatTheResult (Just prec) = printf "%0.*f" prec
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: geval
|
name: geval
|
||||||
version: 0.1.0.0
|
version: 0.1.1.0
|
||||||
synopsis: Machine learning evaluation tools
|
synopsis: Machine learning evaluation tools
|
||||||
description: Please see README.md
|
description: Please see README.md
|
||||||
homepage: http://github.com/name/project
|
homepage: http://github.com/name/project
|
||||||
|
@ -66,6 +66,7 @@ getExpectedDirectory spec = fromMaybe outDirectory $ gesExpectedDirectory spec
|
|||||||
|
|
||||||
data GEvalOptions = GEvalOptions
|
data GEvalOptions = GEvalOptions
|
||||||
{ geoInit :: Bool,
|
{ geoInit :: Bool,
|
||||||
|
geoPrecision :: Maybe Int,
|
||||||
geoSpec :: GEvalSpecification }
|
geoSpec :: GEvalSpecification }
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
module GEval.OptionsParser
|
module GEval.OptionsParser
|
||||||
(fullOptionsParser,
|
(fullOptionsParser,
|
||||||
runGEval) where
|
runGEval,
|
||||||
|
runGEvalGetOptions) where
|
||||||
|
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
import qualified System.Directory as D
|
import qualified System.Directory as D
|
||||||
@ -25,8 +26,15 @@ optionsParser = GEvalOptions
|
|||||||
<$> switch
|
<$> switch
|
||||||
( long "init"
|
( long "init"
|
||||||
<> help "Init a sample Gonito challenge rather than run an evaluation" )
|
<> help "Init a sample Gonito challenge rather than run an evaluation" )
|
||||||
|
<*> optional precisionArgParser
|
||||||
<*> specParser
|
<*> specParser
|
||||||
|
|
||||||
|
precisionArgParser :: Parser Int
|
||||||
|
precisionArgParser = option auto
|
||||||
|
( long "precision"
|
||||||
|
<> metavar "PRECISION"
|
||||||
|
<> help "Precision with which the evaluation results should be shown" )
|
||||||
|
|
||||||
specParser :: Parser GEvalSpecification
|
specParser :: Parser GEvalSpecification
|
||||||
specParser = GEvalSpecification
|
specParser = GEvalSpecification
|
||||||
<$> strOption
|
<$> strOption
|
||||||
@ -68,18 +76,28 @@ metricReader = option auto
|
|||||||
<> help "Metric to be used - RMSE, MSE or BLEU" )
|
<> help "Metric to be used - RMSE, MSE or BLEU" )
|
||||||
|
|
||||||
runGEval :: [String] -> IO (Either (ParserResult GEvalOptions) (Maybe MetricValue))
|
runGEval :: [String] -> IO (Either (ParserResult GEvalOptions) (Maybe MetricValue))
|
||||||
runGEval = runGEval' True
|
runGEval args = do
|
||||||
|
ret <- runGEvalGetOptions args
|
||||||
|
case ret of
|
||||||
|
Left e -> return $ Left e
|
||||||
|
Right (_, mmv) -> return $ Right mmv
|
||||||
|
|
||||||
runGEval' :: Bool -> [String] -> IO (Either (ParserResult GEvalOptions) (Maybe MetricValue))
|
runGEvalGetOptions :: [String] -> IO (Either (ParserResult GEvalOptions) (GEvalOptions, Maybe MetricValue))
|
||||||
|
runGEvalGetOptions = runGEval' True
|
||||||
|
|
||||||
|
-- the first argument: whether to try to read from the config file
|
||||||
|
runGEval' :: Bool -> [String] -> IO (Either (ParserResult GEvalOptions) (GEvalOptions, Maybe MetricValue))
|
||||||
runGEval' readOptsFromConfigFile args =
|
runGEval' readOptsFromConfigFile args =
|
||||||
case parserResult of
|
case parserResult of
|
||||||
Success opts -> if readOptsFromConfigFile then
|
Success opts -> if readOptsFromConfigFile then
|
||||||
attemptToReadOptsFromConfigFile args opts else
|
attemptToReadOptsFromConfigFile args opts else
|
||||||
Right <$> runGEval'' opts
|
do
|
||||||
|
mmv <- runGEval'' opts
|
||||||
|
return $ Right $ (opts, mmv)
|
||||||
otherwise -> return $ Left parserResult
|
otherwise -> return $ Left parserResult
|
||||||
where parserResult = execParserPure (prefs idm) fullOptionsParser args
|
where parserResult = execParserPure (prefs idm) fullOptionsParser args
|
||||||
|
|
||||||
attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) (Maybe MetricValue))
|
attemptToReadOptsFromConfigFile :: [String] -> GEvalOptions -> IO (Either (ParserResult GEvalOptions) (GEvalOptions, Maybe MetricValue))
|
||||||
attemptToReadOptsFromConfigFile args opts = do
|
attemptToReadOptsFromConfigFile args opts = do
|
||||||
configExists <- D.doesFileExist configFilePath
|
configExists <- D.doesFileExist configFilePath
|
||||||
if configExists then do
|
if configExists then do
|
||||||
|
Loading…
Reference in New Issue
Block a user