summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs15
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
56import Text.Layout.Table 56import Text.Layout.Table
57 57
58import Text.Read (readMaybe) 58import Text.Read (readMaybe)
59import Text.Printf
59 60
60import Data.Text (Text) 61import Data.Text (Text)
61import qualified Data.Text as Text 62import 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)