File size distribution: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: cleanup) |
|||
Line 392: | Line 392: | ||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Uses a grouped frequency distribution. Program arguments are optional. Arguments include starting directory and initial frequency distribution group size. Distribution groups of 0 are removed. After the first frequency distribution is computed it further breaks it down for any group that exceeds 25% of the total file count, when possible. |
Uses a grouped frequency distribution. Program arguments are optional. Arguments include starting directory and initial frequency distribution group size. Distribution groups of 0 are removed. After the first frequency distribution is computed it further breaks it down for any group that exceeds 25% of the total file count, when possible. |
||
<lang haskell>{-# LANGUAGE TupleSections |
<lang haskell>{-# LANGUAGE TupleSections #-} |
||
import Control.Concurrent (forkIO, setNumCapabilities) |
import Control.Concurrent (forkIO, setNumCapabilities) |
||
Line 409: | Line 409: | ||
import Text.Printf (printf, hPrintf) |
import Text.Printf (printf, hPrintf) |
||
data Item = File FilePath Integer |
data Item = File FilePath Integer | Folder FilePath deriving (Show) |
||
| Folder FilePath |
|||
deriving (Show) |
|||
type FrequencyGroup = ((Integer, Integer), Integer) |
type FrequencyGroup = ((Integer, Integer), Integer) |
||
Line 431: | Line 428: | ||
counts :: [Item] -> (Integer, Integer) |
counts :: [Item] -> (Integer, Integer) |
||
counts = foldr (\x (a, b) -> case x of File _ _ -> (succ a, b) |
|||
counts = |
|||
Folder _ -> (a, succ b)) (0, 0) |
|||
Folder _ -> (a, succ b) |
|||
) (0, 0) |
|||
frequencyGroups :: Int -> [Integer] -> [FrequencyGroup] |
frequencyGroups :: Int -> [Integer] -> [FrequencyGroup] |
||
Line 498: | Line 493: | ||
(\e -> do |
(\e -> do |
||
hPrintf stderr "Skipping: %s\n" $ show (e :: IOException) |
hPrintf stderr "Skipping: %s\n" $ show (e :: IOException) |
||
pure [] |
pure []) |
||
) |
|||
where |
where |
||
tryCollect = do |
tryCollect = do |
||
Line 510: | Line 504: | ||
displayFrequency :: Integer -> FrequencyGroup -> IO () |
displayFrequency :: Integer -> FrequencyGroup -> IO () |
||
displayFrequency filesCount ((min, max), count) = |
displayFrequency filesCount ((min, max), count) = |
||
printf "%5s <-> %5s = %-10d %6.3f%%: %-5s\n" |
printf "%5s <-> %5s = %-10d %6.3f%%: %-5s\n" (displaySize min) |
||
(displaySize |
(displaySize max) count percentage bars |
||
(displaySize max) |
|||
count |
|||
percentage |
|||
bars |
|||
where |
where |
||
percentage :: Double |
percentage :: Double |
||
Line 561: | Line 551: | ||
printf "Total size: %s\n" $ displaySize $ totalBytes items |
printf "Total size: %s\n" $ displaySize $ totalBytes items |
||
putStrLn "\nDistribution:\n" |
putStrLn "\nDistribution:\n" |
||
⚫ | |||
printf "%5s <-> %4s %8s\n" "From" "To" "Count" |
printf "%5s <-> %4s %8s\n" "From" "To" "Count" |
||
putStrLn $ replicate 37 '-' |
putStrLn $ replicate 37 '-' |
||
⚫ | |||
mapM_ (displayFrequency fileCount) results |
mapM_ (displayFrequency fileCount) results |
||
where |
where |