[input-output-hk/cardano-sl] [CO-347] Wallet’s UTXO histogram view (#3402)

paweljakubas commented on this pull request.

> + UtxoStatistics
+ <$> populateBuckets bounds
+ <*> L.sum
+
+populateBuckets :: NonEmpty Word64 -> L.Fold Word64 [HistogramBar]
+populateBuckets bounds =
+ L.Fold (addCountInBuckets $ head bounds) (initalizeMap bounds)
+ (fmap (\(x1, x2) -> HistogramBarCount (T.pack $ show x1) x2) . Map.toList)
+ where
+ initalizeMap :: NonEmpty Word64 -> Map.Map Word64 Word64
+ initalizeMap b = Map.fromList $ NL.toList $ NL.zip b (NL.repeat 0)
+ addCountInBuckets :: Word64 -> Map.Map Word64 Word64 -> Word64 -> Map.Map Word64 Word64
+ addCountInBuckets thefirst acc entry =
+ case Map.lookupGE entry acc of
+ Just (k, v) -> Map.insert k (v+1) acc
+ Nothing -> Map.adjust (+1) thefirst acc

done