From c23e28250ac2211fba1d627feb4b477a00aa79d2 Mon Sep 17 00:00:00 2001 From: Filip Gralinski Date: Sat, 1 Sep 2018 13:56:18 +0200 Subject: [PATCH] numbers in graphs are shown with the right precision --- Handler/Graph.hs | 11 ++++++----- Handler/Shared.hs | 4 ++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Handler/Graph.hs b/Handler/Graph.hs index eac24e3..1daf991 100644 --- a/Handler/Graph.hs +++ b/Handler/Graph.hs @@ -3,7 +3,7 @@ module Handler.Graph where import Import import Handler.Tables -import Handler.Shared (getMainTest, formatParameter) +import Handler.Shared (formatParameter, formatScore) import Data.Maybe import Data.List ((!!)) import Database.Persist.Sql @@ -21,6 +21,7 @@ data ParamGraphSeries = ParamGraphSeries Text [(TableEntry, Text, MetricValue)] getChallengeParamGraphDataR :: Text -> (Key Test) -> Text -> Handler Value getChallengeParamGraphDataR challengeName testId paramName = do (Entity challengeId _) <- runDB $ getBy404 $ UniqueName challengeName + test <- runDB $ get404 testId (entries, tests) <- getChallengeSubmissionInfos (const True) challengeId @@ -34,11 +35,11 @@ getChallengeParamGraphDataR challengeName testId paramName = do return $ object [ "xs" .= object (map (\(ParamGraphSeries seriesName _) -> (seriesName .= (xSeriesName seriesName))) series), - "columns" .= ((map toYColumn series) ++ (map toXColumn series)) + "columns" .= ((map (toYColumn $ testPrecision test) series) ++ (map toXColumn series)) ] -toYColumn :: ParamGraphSeries -> [Text] -toYColumn (ParamGraphSeries seriesName items) = - seriesName : (map (\(_,_,v) -> pack $ show v) items) +toYColumn :: Maybe Int -> ParamGraphSeries -> [Text] +toYColumn mPrecision (ParamGraphSeries seriesName items) = + seriesName : (map (\(_,_,v) -> formatScore mPrecision v) items) toXColumn :: ParamGraphSeries -> [Text] toXColumn (ParamGraphSeries seriesName items) = diff --git a/Handler/Shared.hs b/Handler/Shared.hs index e2c6389..ef745ce 100644 --- a/Handler/Shared.hs +++ b/Handler/Shared.hs @@ -349,6 +349,10 @@ formatTruncatedScore (Just precision) (Just evaluation) = case evaluationScore e Just score -> T.pack $ printf "%0.*f" precision score Nothing -> formatFullScore Nothing +formatScore :: Maybe Int -> Double -> Text +formatScore Nothing = T.pack . show +formatScore (Just precision) = T.pack . (printf "%0.*f" precision) + formatParameter :: Parameter -> Text formatParameter param = parameterName param ++ "=" ++ parameterValue param