Anonymous user
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 =
| n >= 2^10 && n <= 2^20 = display (2^10) "KB"
| n >= 2^20 && n <= 2^30 = display (2^20) "MB"
| n >= 2^30 && n <= 2^40 = display (2^30) "GB"
| n >= 2^40 && n <= 2^50 = display (2^40) "TB"
| otherwise = printf "
where
-- display suffix = (<> suffix) . show
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 "%
printf "=
where
percentage :: Double
Line 579 ⟶ 581:
printf "Total size: %s\n" $ displaySize $ totalBytes items
putStrLn "\nDistribution:\n"
printf "%
putStrLn $ replicate
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:
Distribution:
---------------------------------------------
0B <-> 80B = 7 1.017%: █
81B <-> 161B = 74 10.756%: ███████████
$ filedist ~/Music 10
Line 629 ⟶ 631:
Total files: 688
Total folders: 663
Total size:
Distribution:
---------------------------------------------
0B <-> 88B = 7 1.017%: █
89B <-> 177B = 75 10.901%: ███████████
</pre>
|