Anonymous user
File size distribution: Difference between revisions
m
→{{header|Haskell}}
m (→{{header|Haskell}}: cleanup) |
|||
Line 392:
=={{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.
<lang haskell>{-# LANGUAGE TupleSections
import Control.Concurrent (forkIO, setNumCapabilities)
Line 409:
import Text.Printf (printf, hPrintf)
data Item = File FilePath Integer | Folder FilePath deriving (Show)
type FrequencyGroup = ((Integer, Integer), Integer)
Line 431 ⟶ 428:
counts :: [Item] -> (Integer, Integer)
counts = foldr (\x (a, b) -> case x of File _ _ -> (succ a, b)
frequencyGroups :: Int -> [Integer] -> [FrequencyGroup]
Line 498 ⟶ 493:
(\e -> do
hPrintf stderr "Skipping: %s\n" $ show (e :: IOException)
pure [])
where
tryCollect = do
Line 510 ⟶ 504:
displayFrequency :: Integer -> FrequencyGroup -> IO ()
displayFrequency filesCount ((min, max), count) =
printf "%5s <-> %5s = %-10d %6.3f%%: %-5s\n" (displaySize min)
(displaySize
where
percentage :: Double
Line 561 ⟶ 551:
printf "Total size: %s\n" $ displaySize $ totalBytes items
putStrLn "\nDistribution:\n"
let results = expandedGroups groupSize (sizes items) (groupThreshold fileCount) items▼
printf "%5s <-> %4s %8s\n" "From" "To" "Count"
putStrLn $ replicate 37 '-'
▲ let results = expandedGroups groupSize (sizes items) (groupThreshold fileCount) items
mapM_ (displayFrequency fileCount) results
where
|