aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/lwtrace/mon/analytics/json_output.h
diff options
context:
space:
mode:
authorserxa <serxa@yandex-team.ru>2022-02-10 16:49:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:08 +0300
commite5d4696304c6689379ac7ce334512404d4b7836c (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/lwtrace/mon/analytics/json_output.h
parentd6d7db348c2cc64e71243cab9940ee6778f4317d (diff)
downloadydb-e5d4696304c6689379ac7ce334512404d4b7836c.tar.gz
Restoring authorship annotation for <serxa@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/lwtrace/mon/analytics/json_output.h')
-rw-r--r--library/cpp/lwtrace/mon/analytics/json_output.h174
1 files changed, 87 insertions, 87 deletions
diff --git a/library/cpp/lwtrace/mon/analytics/json_output.h b/library/cpp/lwtrace/mon/analytics/json_output.h
index a857ccfa0c..189f9802d3 100644
--- a/library/cpp/lwtrace/mon/analytics/json_output.h
+++ b/library/cpp/lwtrace/mon/analytics/json_output.h
@@ -1,98 +1,98 @@
-#pragma once
-
-#include <util/string/printf.h>
-#include <util/stream/str.h>
-#include <util/string/vector.h>
-#include <util/generic/set.h>
-#include <util/generic/hash_set.h>
+#pragma once
+
+#include <util/string/printf.h>
+#include <util/stream/str.h>
+#include <util/string/vector.h>
+#include <util/generic/set.h>
+#include <util/generic/hash_set.h>
#include "data.h"
#include "util.h"
-
-namespace NAnalytics {
-
+
+namespace NAnalytics {
+
inline TString ToJsonFlot(const TTable& in, const TString& xno, const TVector<TString>& ynos, const TString& opts = TString())
-{
- TStringStream ss;
- ss << "[ ";
- bool first = true;
-
+{
+ TStringStream ss;
+ ss << "[ ";
+ bool first = true;
+
TString xn;
THashSet<TString> xopts;
- ParseNameAndOpts(xno, xn, xopts);
+ ParseNameAndOpts(xno, xn, xopts);
bool xstack = xopts.contains("stack");
-
+
for (const TString& yno : ynos) {
TString yn;
THashSet<TString> yopts;
- ParseNameAndOpts(yno, yn, yopts);
+ ParseNameAndOpts(yno, yn, yopts);
bool ystackOpt = yopts.contains("stack");
-
- ss << (first? "": ",\n ") << "{ " << opts << (opts? ", ": "") << "\"label\": \"" << yn << "\", \"data\": [ ";
- bool first2 = true;
+
+ ss << (first? "": ",\n ") << "{ " << opts << (opts? ", ": "") << "\"label\": \"" << yn << "\", \"data\": [ ";
+ bool first2 = true;
using TPt = std::tuple<double, double, TString>;
- std::vector<TPt> pts;
- for (const TRow& row : in) {
- double x, y;
- if (row.Get(xn, x) && row.Get(yn, y)) {
- pts.emplace_back(x, y, row.Name);
- }
- }
-
- if (xstack) {
- std::sort(pts.begin(), pts.end(), [] (const TPt& a, const TPt& b) {
- // At first sort by Name, then by x, then by y
- return std::make_tuple(std::get<2>(a), std::get<0>(a), std::get<1>(a)) <
- std::make_tuple(std::get<2>(b), std::get<0>(b), std::get<1>(b));
- });
- } else {
- std::sort(pts.begin(), pts.end());
- }
-
- double x = 0.0, xsum = 0.0;
- double y = 0.0, ysum = 0.0;
- for (auto& pt : pts) {
- if (xstack) {
- x = xsum;
- xsum += std::get<0>(pt);
- } else {
- x = std::get<0>(pt);
- }
-
- if (ystackOpt) {
- y = ysum;
- ysum += std::get<1>(pt);
- } else {
- y = std::get<1>(pt);
- }
-
- ss << (first2? "": ", ") << "["
- << Sprintf("%.6lf", Finitize(x)) << ", " // x coordinate
- << Sprintf("%.6lf", Finitize(y)) << ", " // y coordinate
- << "\"" << std::get<2>(pt) << "\", " // label
- << Sprintf("%.6lf", std::get<0>(pt)) << ", " // x label (real value)
- << Sprintf("%.6lf", std::get<1>(pt)) // y label (real value)
- << "]";
- first2 = false;
- }
- // Add final point
- if (!first2 && (xstack || ystackOpt)) {
- if (xstack)
- x = xsum;
- if (ystackOpt)
- y = ysum;
- ss << (first2? "": ", ") << "["
- << Sprintf("%.6lf", Finitize(x)) << ", " // x coordinate
- << Sprintf("%.6lf", Finitize(y)) << ", " // y coordinate
- << "\"\", "
- << Sprintf("%.6lf", x) << ", " // x label (real value)
- << Sprintf("%.6lf", y) // y label (real value)
- << "]";
- }
- ss << " ] }";
- first = false;
- }
- ss << "\n]";
- return ss.Str();
-}
-
-}
+ std::vector<TPt> pts;
+ for (const TRow& row : in) {
+ double x, y;
+ if (row.Get(xn, x) && row.Get(yn, y)) {
+ pts.emplace_back(x, y, row.Name);
+ }
+ }
+
+ if (xstack) {
+ std::sort(pts.begin(), pts.end(), [] (const TPt& a, const TPt& b) {
+ // At first sort by Name, then by x, then by y
+ return std::make_tuple(std::get<2>(a), std::get<0>(a), std::get<1>(a)) <
+ std::make_tuple(std::get<2>(b), std::get<0>(b), std::get<1>(b));
+ });
+ } else {
+ std::sort(pts.begin(), pts.end());
+ }
+
+ double x = 0.0, xsum = 0.0;
+ double y = 0.0, ysum = 0.0;
+ for (auto& pt : pts) {
+ if (xstack) {
+ x = xsum;
+ xsum += std::get<0>(pt);
+ } else {
+ x = std::get<0>(pt);
+ }
+
+ if (ystackOpt) {
+ y = ysum;
+ ysum += std::get<1>(pt);
+ } else {
+ y = std::get<1>(pt);
+ }
+
+ ss << (first2? "": ", ") << "["
+ << Sprintf("%.6lf", Finitize(x)) << ", " // x coordinate
+ << Sprintf("%.6lf", Finitize(y)) << ", " // y coordinate
+ << "\"" << std::get<2>(pt) << "\", " // label
+ << Sprintf("%.6lf", std::get<0>(pt)) << ", " // x label (real value)
+ << Sprintf("%.6lf", std::get<1>(pt)) // y label (real value)
+ << "]";
+ first2 = false;
+ }
+ // Add final point
+ if (!first2 && (xstack || ystackOpt)) {
+ if (xstack)
+ x = xsum;
+ if (ystackOpt)
+ y = ysum;
+ ss << (first2? "": ", ") << "["
+ << Sprintf("%.6lf", Finitize(x)) << ", " // x coordinate
+ << Sprintf("%.6lf", Finitize(y)) << ", " // y coordinate
+ << "\"\", "
+ << Sprintf("%.6lf", x) << ", " // x label (real value)
+ << Sprintf("%.6lf", y) // y label (real value)
+ << "]";
+ }
+ ss << " ] }";
+ first = false;
+ }
+ ss << "\n]";
+ return ss.Str();
+}
+
+}