diff options
author | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-07-07 23:13:59 +0200 |
---|---|---|
committer | Gregor Kleen <pngwjpgh@users.noreply.github.com> | 2016-07-07 23:13:59 +0200 |
commit | 3496781f3ebad2901b60f19b388c893d8ad8aa37 (patch) | |
tree | cfb2e3d9f55b744e768ebb11e4e5a325b1c21847 /src | |
parent | e5e9eed0ebb7f63fb9cd111495220024c350879c (diff) | |
download | 2017-01-16_17:13:37-3496781f3ebad2901b60f19b388c893d8ad8aa37.tar 2017-01-16_17:13:37-3496781f3ebad2901b60f19b388c893d8ad8aa37.tar.gz 2017-01-16_17:13:37-3496781f3ebad2901b60f19b388c893d8ad8aa37.tar.bz2 2017-01-16_17:13:37-3496781f3ebad2901b60f19b388c893d8ad8aa37.tar.xz 2017-01-16_17:13:37-3496781f3ebad2901b60f19b388c893d8ad8aa37.zip |
prettier output of distributions
Diffstat (limited to 'src')
-rw-r--r-- | src/Main.hs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/Main.hs b/src/Main.hs index 75f379b..449e21d 100644 --- a/src/Main.hs +++ b/src/Main.hs | |||
@@ -56,6 +56,7 @@ import Sequence.Formula | |||
56 | import Text.Layout.Table | 56 | import Text.Layout.Table |
57 | 57 | ||
58 | import Text.Read (readMaybe) | 58 | import Text.Read (readMaybe) |
59 | import Text.Printf | ||
59 | 60 | ||
60 | import Data.Text (Text) | 61 | import Data.Text (Text) |
61 | import qualified Data.Text as Text | 62 | import qualified Data.Text as Text |
@@ -382,8 +383,12 @@ printVal = withArg $ \formula -> withFocus $ \focusId -> do | |||
382 | where | 383 | where |
383 | outline Nothing = shellPutErrLn "No such value" | 384 | outline Nothing = shellPutErrLn "No such value" |
384 | outline (Just (Map.toList -> [(v, _)])) = shellPutStrLn $ show v | 385 | outline (Just (Map.toList -> [(v, _)])) = shellPutStrLn $ show v |
385 | outline (Just (sortBy (comparing snd) . Map.toList -> vals)) = mapM_ (shellPutStrLn . outline') vals | 386 | outline (Just (sortBy (comparing fst) . Map.toList -> vals)) = mapM_ (shellPutStrLn . outline') vals |
386 | outline' (v, prob) = pad' 3 (show $ round' 10 prob) ++ " → " ++ show v | 387 | where |
387 | round' :: RealFrac a => Float -> a -> Float | 388 | barLength = 100 |
388 | round' n = (/ n) . fromIntegral . (round :: RealFrac a => a -> Integer) . (* n) . realToFrac | 389 | outline' (v, prob) = printf "%*s: %.2f [%-*s]" |
389 | pad' m ys = replicate (m - length (take m ys)) ' ' ++ ys | 390 | (maximum lengths) (show v) |
391 | (fromRational prob :: Double) | ||
392 | barLength (replicate (round $ fromInteger barLength * normalize prob) '#') | ||
393 | lengths = map (length . show . fst) vals | ||
394 | normalize p = p / maximum (map snd vals) | ||