get_statistics_subset should return well-formatted null results
The existing code for handling lists of values that don't meet minimum
length causes problems when the `percentiles` key is used; e.g., rather
than the expected
[{percentile, [{0.5, 0.0}, ... ]}]
the user is presented with
[{{percentile, [0.5, ... ]}, 0.0}]
which doesn't match the formatting for other subset key. This patch
special-cases the `percentile` key to return the expected result.
diff --git a/src/bear.erl b/src/bear.erl
index 7d9eed9..67f4139 100644
--- a/src/bear.erl
+++ b/src/bear.erl
@@ -114,7 +114,14 @@
SortedValues, Scan_res, Scan_res2)
end;
get_statistics_subset(Values, Items) when is_list(Values) ->
- [{Item, 0.0} || Item <- Items].
+ get_null_statistics_subset(Items, []).
+
+get_null_statistics_subset([{percentile, Ps}|Items], Acc) ->
+ get_null_statistics_subset(Items, [{percentile, [{P, 0.0} || P <- Ps]}|Acc]);
+get_null_statistics_subset([I|Items], Acc) ->
+ get_null_statistics_subset(Items, [{I, 0.0}|Acc]);
+get_null_statistics_subset([], Acc) ->
+ lists:reverse(Acc).
calc_steps(Items) ->
lists:foldl(fun({I,_},Acc) ->