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 =
19 decltype(std::declval<
const T&>().GetPercentile(0.0));
23std::string GetPercentileFieldName(
double perc);
26formats::
json::ValueBuilder PercentileToJson(
27 const T& perc, std::initializer_list<
double> percents) {
28 static_assert(meta::kIsDetected<impl::HasGetPercentileResult, T>,
29 "T must specify T::GetPercentile(double) returning "
30 "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});