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 Options.Applicative
|
||||
|
||||
import Text.Printf
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
result <- runGEval args
|
||||
result <- runGEvalGetOptions args
|
||||
case result of
|
||||
Left parseResult -> handleParseResult parseResult >> return ()
|
||||
Right (Just result) -> print $ result
|
||||
Right Nothing -> return ()
|
||||
Right (opts, Just result) -> showTheResult opts result
|
||||
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
|
||||
version: 0.1.0.0
|
||||
version: 0.1.1.0
|
||||
synopsis: Machine learning evaluation tools
|
||||
description: Please see README.md
|
||||
homepage: http://github.com/name/project
|
||||
|
@ -66,6 +66,7 @@ getExpectedDirectory spec = fromMaybe outDirectory $ gesExpectedDirectory spec
|
||||
|
||||
data GEvalOptions = GEvalOptions
|
||||
{ geoInit :: Bool,
|
||||
geoPrecision :: Maybe Int,
|
||||
geoSpec :: GEvalSpecification }
|
||||
|
||||
|
||||
|
@ -2,7 +2,8 @@
|
||||
|
||||
module GEval.OptionsParser
|
||||
(fullOptionsParser,
|
||||
runGEval) where
|
||||
runGEval,
|
||||
runGEvalGetOptions) where
|
||||
|
||||
import Options.Applicative
|
||||
import qualified System.Directory as D
|
||||
@ -25,8 +26,15 @@ optionsParser = GEvalOptions
|
||||
<$> switch
|
||||
( long "init"
|
||||
<> help "Init a sample Gonito challenge rather than run an evaluation" )
|
||||
<*> optional precisionArgParser
|
||||
<*> 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 = GEvalSpecification
|
||||
<$> strOption
|
||||
@ -68,18 +76,28 @@ metricReader = option auto
|
||||
<> help "Metric to be used - RMSE, MSE or BLEU" )
|
||||
|
||||
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 =
|
||||
case parserResult of
|
||||
Success opts -> if readOptsFromConfigFile then
|
||||
attemptToReadOptsFromConfigFile args opts else
|
||||
Right <$> runGEval'' opts
|
||||
do
|
||||
mmv <- runGEval'' opts
|
||||
return $ Right $ (opts, mmv)
|
||||
otherwise -> return $ Left parserResult
|
||||
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
|
||||
configExists <- D.doesFileExist configFilePath
|
||||
if configExists then do
|
||||
|
Loading…
Reference in New Issue
Block a user