File size distribution: Difference between revisions

m
→‎{{header|Haskell}}: increase the precision when displaying file sizes
m (→‎{{header|Haskell}}: use Data.Map. Some other optimizations.)
m (→‎{{header|Haskell}}: increase the precision when displaying file sizes)
Line 504:
displaySize :: Integer -> String
displaySize n
| n <= 2^10 = showprintf n <>"%8dB "B" n
| n >= 2^10 && n <= 2^20 = display (2^10) "KB" $ 2^10
| n >= 2^20 && n <= 2^30 = display (2^20) "MB" $ 2^20
| n >= 2^30 && n <= 2^40 = display (2^30) "GB" $ 2^30
| n >= 2^40 && n <= 2^50 = display (2^40) "TB" $ 2^40
| otherwise = printf "Too%8dB large!" n
where
-- display suffix = (<> suffix) . show . round . (realToFrac n /)
display :: Double -> String -> String
display b = printf "%7.2f%s " (realToFrac n / b)
 
folderWorker :: Chan FilePath -> Chan [Item] -> IO ()
Line 531 ⟶ 533:
 
displayFrequency :: Integer -> FrequencyGroup -> IO ()
displayFrequency filesCount ((min, max), count) = do
printf "%5ss <-> %5ss" =(displaySize %-10d %6.3f%%: %-5s\n"min) (displaySize minmax)
printf "= (displaySize%-10d max)%6.3f%%: %-5s\n" count percentage bars
where
percentage :: Double
Line 579 ⟶ 581:
printf "Total size: %s\n" $ displaySize $ totalBytes items
putStrLn "\nDistribution:\n"
printf "%5s9s <-> %4s9s %8s7s\n" "From" "To" "Count"
putStrLn $ replicate 3745 '-'
let results = expandedGroups groupSize (sizes items) (groupThreshold fileCount) items
-- let results = initialGroups groupSize items
Line 591 ⟶ 593:
expandGroups gsize sizes n . initialGroups gsize</lang>
{{out}}
<pre style="height: 50rem;">$ filedist ~/Music
Using 4 worker threads
Total files: 688
Total folders: 663
Total size: 986MB 985.85MB
 
Distribution:
 
From <-> To To Count
---------------------------------------------
0B <-> 80B = 7 1.017%: █
81B <-> 161B = 74 10.756%: ███████████
162B <-> 242B = 112 16.279%: ████████████████
243B <-> 323B = 99 14.390%: ██████████████
322B 323B <-> 643B 645B = 23 3.343%: ███
644B 646B <-> 965B 968B = 2 0.291%:
966B 969B <-> 1KB 1.26KB = 1 0.145%:
3KB 3.19KB <-> 6KB 6.38KB = 12 1.744%: ██
6KB 6.38KB <-> 10KB 9.58KB = 22 3.198%: ███
10KB 9.58KB <-> 13KB 12.77KB = 12 1.744%: ██
14KB 13.52KB <-> 27KB 27.04KB = 15 2.180%: ██
27KB 27.04KB <-> 41KB 40.57KB = 6 0.872%: █
41KB 40.57KB <-> 54KB 54.09KB = 22 3.198%: ███
54KB 54.20KB <-> 108KB 108.41KB = 99 14.390%: ██████████████
108KB 108.41KB <-> 163KB 162.61KB = 23 3.343%: ███
163KB 162.61KB <-> 217KB 216.81KB = 8 1.163%: █
236KB 236.46KB <-> 473KB 472.93KB = 3 0.436%:
709KB 709.39KB <-> 946KB 945.85KB = 44 6.395%: ██████
3MB 3.30MB <-> 5MB 4.96MB = 4 0.581%: █
5MB 4.96MB <-> 7MB 6.61MB = 21 3.052%: ███
7MB 6.67MB <-> 13MB 13.33MB = 72 10.465%: ██████████
13MB 13.33MB <-> 20MB 20.00MB = 6 0.872%: █
20MB 20.00MB <-> 27MB 26.66MB = 1 0.145%:
 
$ filedist ~/Music 10
Line 629 ⟶ 631:
Total files: 688
Total folders: 663
Total size: 986MB 985.85MB
 
Distribution:
 
From <-> To To Count
---------------------------------------------
0B <-> 88B = 7 1.017%: █
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%:
959B <-> 2KB 1.87KB = 1 0.145%:
4KB 3.75KB <-> 5KB 4.68KB = 1 0.145%:
5KB 4.68KB <-> 6KB 5.62KB = 1 0.145%:
6KB 5.62KB <-> 7KB 6.55KB = 11 1.599%: ██
7KB 6.56KB <-> 7KB 7.49KB = 10 1.453%: █
7KB 7.49KB <-> 8KB 8.43KB = 4 0.581%: █
8KB 8.43KB <-> 9KB 9.36KB = 7 1.017%: █
9KB 9.43KB <-> 19KB 18.85KB = 21 3.052%: ███
19KB 18.85KB <-> 28.28KB = 6 0.872%: █
28.28KB <-> 38KB 37.71KB = 4 0.581%: █
38KB 37.71KB <-> 47KB 47.13KB = 12 1.744%: ██
47KB 47.13KB <-> 57KB 56.56KB = 16 2.326%: ██
57KB 56.56KB <-> 66KB 65.99KB = 23 3.343%: ███
66KB 65.99KB <-> 75KB 75.41KB = 26 3.779%: ████
75KB 75.41KB <-> 85KB 84.84KB = 15 2.180%: ██
85KB 84.84KB <-> 94KB 94.27KB = 17 2.471%: ██
95KB 94.59KB <-> 189KB 189.17KB = 42 6.105%: ██████
189KB 189.17KB <-> 284KB 283.76KB = 4 0.581%: █
284KB 283.76KB <-> 378KB 378.35KB = 2 0.291%:
851KB 851.28KB <-> 946KB 945.87KB = 44 6.395%: ██████
3MB 2.67MB <-> 5MB 5.33MB = 5 0.727%: █
5MB 5.33MB <-> 8MB 8.00MB = 41 5.959%: ██████
8MB 8.00MB <-> 11MB 10.67MB = 35 5.087%: █████
11MB 10.67MB <-> 13MB 13.33MB = 16 2.326%: ██
13MB 13.33MB <-> 16MB 16.00MB = 3 0.436%:
16MB 16.00MB <-> 19MB 18.67MB = 3 0.436%:
24MB 24.00MB <-> 27MB 26.66MB = 1 0.145%:
</pre>
 
Anonymous user