File size distribution: Difference between revisions

m
Line 398:
import Data.List (sort, genericLength, genericTake)
import System.Directory (getDirectoryContents, doesFileExist
, canonicalizePath, doesDirectoryExist)
import System.Environment (getArgs)
import System.FilePath.Posix (pathSeparator, (</>))
Line 408:
deriving (Show)
 
type FrequencyGroup = ((Integer, Integer), Integer)
frequencyGroups :: (Integral a) => Int -> [a] -> [((a, a), a)]
 
frequencyGroups :: (Integral a) => Int -> [aInteger] -> [((a, a), a)FrequencyGroup]
frequencyGroups totalGroups xs = placeGroups xs groupMinMax
where
range = maximum xs - minimum xs
groupSize = succ $ ceiling $ realToFrac range / realToFrac totalGroups
groups = genericTake (succ totalGroups) ($ iterate (+groupSize) 0)
groupMinMax = (,0) <$> zip groups (pred <$> tail groups)
 
Line 451 ⟶ 453:
pure $ a <> join b <> fmap Folder folders
 
displayFrequency :: ((Integer, Integer), Integer)FrequencyGroup -> IO ()
displayFrequency ((min, max), count) =
printf "%5s <-> %5s = %d\n" (displaySize min) (displaySize max) count
Anonymous user