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