diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/lwtrace/mon/analytics/csv_output.h | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/lwtrace/mon/analytics/csv_output.h')
-rw-r--r-- | library/cpp/lwtrace/mon/analytics/csv_output.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/library/cpp/lwtrace/mon/analytics/csv_output.h b/library/cpp/lwtrace/mon/analytics/csv_output.h new file mode 100644 index 0000000000..90ded32f5d --- /dev/null +++ b/library/cpp/lwtrace/mon/analytics/csv_output.h @@ -0,0 +1,52 @@ +#pragma once + +#include <util/string/printf.h> +#include <util/stream/str.h> +#include <util/generic/set.h> +#include "data.h" + +namespace NAnalytics { + +inline TString ToCsv(const TTable& in, TString sep = TString("\t"), bool head = true) +{ + TSet<TString> cols; + bool hasName = false; + for (const TRow& row : in) { + hasName = hasName || !row.Name.empty(); + for (const auto& kv : row) { + cols.insert(kv.first); + } + } + + TStringStream ss; + if (head) { + bool first = true; + if (hasName) { + ss << (first? TString(): sep) << "Name"; + first = false; + } + for (const TString& c : cols) { + ss << (first? TString(): sep) << c; + first = false; + } + ss << Endl; + } + + for (const TRow& row : in) { + bool first = true; + if (hasName) { + ss << (first? TString(): sep) << row.Name; + first = false; + } + for (const TString& c : cols) { + ss << (first? TString(): sep); + first = false; + TString value; + ss << (row.GetAsString(c, value) ? value : TString("-")); + } + ss << Endl; + } + return ss.Str(); +} + +} |