3#include <initializer_list>
5#include <userver/formats/json/value_builder.hpp>
6#include <userver/utils/assert.hpp>
7#include <userver/utils/meta_light.hpp>
8#include <userver/utils/statistics/metadata.hpp>
9#include <userver/utils/statistics/percentile.hpp>
11USERVER_NAMESPACE_BEGIN
13namespace utils::statistics {
18using HasGetPercentileResult =
decltype(std::declval<
const T&>().GetPercentile(0.0));
22std::string GetPercentileFieldName(
double perc);
25formats::
json::ValueBuilder PercentileToJson(
const T& perc, std::initializer_list<
double> percents) {
27 meta::kIsDetected<impl::HasGetPercentileResult, T>,
28 "T must specify T::GetPercentile(double) returning "
29 "json-serializable value"
31 formats::
json::ValueBuilder result;
32 for (
double percent : percents) {
33 result[GetPercentileFieldName(percent)] = perc.GetPercentile(percent);
35 utils::statistics::SolomonChildrenAreLabelValues(result,
"percentile");
40formats::
json::ValueBuilder PercentileToJson(
const T& perc) {
41 return PercentileToJson(perc, {0, 50, 90, 95, 98, 99, 99.6, 99.9, 100});