Commit c888041d authored by Ben Gamari's avatar Ben Gamari 🐢

Give files friendly names

parent 92802a28
......@@ -4,9 +4,10 @@
import Data.Align
import Data.Maybe
import Data.These
import Data.List (intercalate)
import Data.List (intercalate, group)
import Data.Foldable
import Numeric
import qualified Data.Sequence as Seq
import qualified Data.Tree as Tree
import Data.Tree (Tree)
import qualified Data.Map.Strict as M
......@@ -22,11 +23,38 @@ import LabelMatch
args :: Parser [FilePath]
args = some $ argument str (metavar "FILE" <> help "results.json file")
-- | Pick out the interesting part of a set of filenames for use as a friendly
-- name. Essentially we just break up all paths into their components and drop
-- all components common to all.
friendlyNameFiles :: [FilePath] -> M.Map String FilePath
friendlyNameFiles files =
M.fromList
[ (joinPath $ toList name, path)
| (path, name) <- M.toList friendlyNames
]
where
friendlyNames :: M.Map FilePath (Seq.Seq String)
friendlyNames =
fmap (fmap snd . Seq.filter (not . fst) . Seq.zip isCommon) splitPaths
where
isCommon :: Seq.Seq Bool
isCommon = Seq.fromList $ fmap isCommonComp [0..maximum $ fmap length splitPaths]
splitPaths :: M.Map FilePath (Seq.Seq String)
splitPaths = M.fromList [ (f, Seq.fromList $ splitPath f) | f <- files ]
isCommonComp :: Int -> Bool
isCommonComp n = allEqual $ M.elems $ fmap (Seq.!? n) splitPaths
allEqual :: Eq a => [a] -> Bool
allEqual xs = length (group xs) == 1
main :: IO ()
main = do
files <- execParser $ info (helper <*> args) mempty
mtrees <- mapM (fmap (MTree.toMap head . fromJust) . MTree.readFile) files
let aligned = alignMany $ M.fromList $ zip (map takeFileName files) mtrees
let filesWithFriendlyNames = friendlyNameFiles files
mtrees <- mapM (fmap (MTree.toMap head . fromJust) . MTree.readFile) filesWithFriendlyNames
let aligned = alignMany mtrees
let tabulate :: (Show a, Ord a) => String -> (LabelMatcher a) -> IO ()
tabulate heading pred
| null xs = putStrLn $ heading ++ ": no measurements"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment