File size distribution: Difference between revisions

Content added Content deleted
Line 509: Line 509:
display :: Double -> String -> String
display :: Double -> String -> String
display b = printf "%7.2f%s " (realToFrac n / b)
display b = printf "%7.2f%s " (realToFrac n / b)

displayFrequency :: Integer -> FrequencyGroup -> IO ()
displayFrequency filesCount ((min, max), count) = do
printf "%s <-> %s" (displaySize min) (displaySize max)
printf "= %-10d %6.3f%%: %-5s\n" count percentage bars
where
percentage :: Double
percentage = (realToFrac count / realToFrac filesCount) * 100
size = round percentage
bars | size == 0 = "▍"
| otherwise = replicate size '█'


folderWorker :: Chan FilePath -> Chan [Item] -> IO ()
folderWorker :: Chan FilePath -> Chan [Item] -> IO ()
Line 525: Line 536:
items <- mapM (\f -> File f <$> withFile f ReadMode hFileSize) files
items <- mapM (\f -> File f <$> withFile f ReadMode hFileSize) files
pure $ items <> fmap Folder folders
pure $ items <> fmap Folder folders

displayFrequency :: Integer -> FrequencyGroup -> IO ()
displayFrequency filesCount ((min, max), count) = do
printf "%s <-> %s" (displaySize min) (displaySize max)
printf "= %-10d %6.3f%%: %-5s\n" count percentage bars
where
percentage :: Double
percentage = (realToFrac count / realToFrac filesCount) * 100
size = round percentage
bars | size == 0 = "▍"
| otherwise = replicate size '█'

parseArgs :: [String] -> Either String (FilePath, Int)
parseArgs (x:y:xs)
| all isDigit y = Right (x, read y)
| otherwise = Left "Invalid frequency group size"
parseArgs (x:xs) = Right (x, 4)
parseArgs _ = Right (".", 4)


parallelItemCollector :: FilePath -> IO [Item]
parallelItemCollector :: FilePath -> IO [Item]
Line 563: Line 556:
result <- mapM (loop folderChan resultItemsChan) childItems
result <- mapM (loop folderChan resultItemsChan) childItems
pure (join childItems <> join result)
pure (join childItems <> join result)

parseArgs :: [String] -> Either String (FilePath, Int)
parseArgs (x:y:xs)
| all isDigit y = Right (x, read y)
| otherwise = Left "Invalid frequency group size"
parseArgs (x:xs) = Right (x, 4)
parseArgs _ = Right (".", 4)


main :: IO ()
main :: IO ()