File size distribution: Difference between revisions

m
Line 509:
display :: Double -> String -> String
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 ()
Line 525 ⟶ 536:
items <- mapM (\f -> File f <$> withFile f ReadMode hFileSize) files
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]
Line 563 ⟶ 556:
result <- mapM (loop folderChan resultItemsChan) childItems
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 ()
Anonymous user