Anonymous user
File size distribution: Difference between revisions
m
→{{header|Haskell}}: fix non terminating condition
m (→{{header|Haskell}}: fix non terminating condition) |
|||
Line 391:
</pre>
=={{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, LambdaCase #-}
Line 418:
range = maximum xs - minimum xs
groupSize = succ $ ceiling $ realToFrac range / realToFrac totalGroups
groups =
groupMinMax = (,0) <$> zip groups (pred <$> tail groups)
Line 426:
if d >= min && d <= max
then ((min, max), succ count)
else g
) gs
fileSizes :: [Item] -> [Integer]
Line 460 ⟶ 462:
expandGroups :: Int -> [Integer] -> Integer -> [FrequencyGroup] -> [FrequencyGroup]
expandGroups gsize fileSizes groupThreshold
where
loop 0 gs = gs -- break out in case we can't go below threshold
loop n gs
| all ((<= groupThreshold) . snd) gs = gs
| otherwise = loop (pred n) $ expand gs
expand = ((\g@((min, max), count) ->
if count > groupThreshold then
Line 505 ⟶ 510:
percentage :: Double
percentage = (realToFrac count / realToFrac filesCount) * 100
bars = replicate (round
parseArgs :: [String] -> Either String (FilePath, Int)
Line 558 ⟶ 563:
. initialGroups gsize</lang>
{{out}}
<pre style="height: 50rem;">$ filedist ~/Music
Using 4 worker threads
Total files:
Total folders:
Total size:
Distribution:
0B <-> 80B = 7 1.017%: █
81B <-> 161B = 74 10.756%: ███████████
162B <-> 242B = 112 16.279%: ████████████████
243B <-> 323B = 99 14.390%: ██████████████
322B <-> 643B = 23 3.343%: ███
644B <-> 965B = 2 0.291%:
966B <-> 1KB = 1 0.145%:
3KB <-> 6KB = 12 1.744%: ██
6KB <-> 10KB = 22 3.198%: ███
10KB <-> 13KB = 12 1.744%: ██
14KB <-> 27KB = 15 2.180%: ██
$ filedist ~/Music 10
Using 4 worker threads
Total files:
Total folders:
Total size:
Distribution:
0B <->
89B <-> 177B = 75 10.901%: ███████████
178B <-> 266B = 156 22.674%: ███████████████████████
267B <-> 355B = 57 8.285%: ████████
356B <-> 444B = 20 2.907%: ███
801B <-> 889B = 2 0.291%:
4KB <-> 5KB = 1 0.145%:
7KB <-> 7KB = 10 1.453%: █
5MB <-> 8MB = 41 5.959%: ██████
8MB <-> 11MB = 35 5.087%: █████
11MB <-> 13MB = 16 2.326%: ██
13MB <-> 16MB = 3 0.436%:
16MB <-> 19MB = 3 0.436%:
24MB <-> 27MB = 1 0.145%:
</pre>
|