aboutsummaryrefslogtreecommitdiff
path: root/apps/sample-convert.cpp
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-03-22 11:14:42 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-03-22 11:14:42 +0100
commitd76bf876d4ce8e845a8e03a48b72a4ad4761359f (patch)
treecb8e786a1cd166e92658bc8b73ed1012c6bec93b /apps/sample-convert.cpp
parentac03535bc7d08c4fc05c19eda6271e92b6558e41 (diff)
downloadble-toys-d76bf876d4ce8e845a8e03a48b72a4ad4761359f.tar.gz
ble-toys-d76bf876d4ce8e845a8e03a48b72a4ad4761359f.tar.bz2
ble-toys-d76bf876d4ce8e845a8e03a48b72a4ad4761359f.tar.xz
ble-toys-d76bf876d4ce8e845a8e03a48b72a4ad4761359f.zip
o RRD output.
Diffstat (limited to 'apps/sample-convert.cpp')
-rw-r--r--apps/sample-convert.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp
index c6f5d01..d1c53fb 100644
--- a/apps/sample-convert.cpp
+++ b/apps/sample-convert.cpp
@@ -2,6 +2,7 @@
#include "json.hpp"
#include "apps.h"
#include <fstream>
+#include <boost/tokenizer.hpp>
namespace trygvis {
namespace apps {
@@ -9,9 +10,12 @@ namespace apps {
using namespace std;
using namespace trygvis::apps;
using namespace trygvis::soil_moisture;
+using boost::tokenizer;
namespace po = boost::program_options;
class sample_convert : public app {
+ string fields;
+ string timestamp_field;
public:
void add_options(po::options_description_easy_init &options) override {
@@ -20,7 +24,9 @@ public:
("input", po::value<string>(&input_file)->default_value("-"))
// ("input-format", po::value<string>(&input_format)->default_value("csv"))
("output", po::value<string>(&output_file)->default_value("-"))
- ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE));
+ ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE))
+ ("fields", po::value<string>(&fields))
+ ("timestamp-field", po::value<string>(&timestamp_field));
}
void add_extra_options(po::options_description &all_options) override {
@@ -59,7 +65,21 @@ public:
}
}
- shared_ptr<SampleOutputStream> output = open_sample_output_stream(outputStream, dict, output_format);
+ std::vector<sample_output_stream_option *> options;
+ trygvis::soil_moisture::timestamp_field tf(timestamp_field);
+
+ if (!timestamp_field.empty()) {
+ options.push_back(&tf);
+ }
+
+ tokenizer<> tok(fields);
+ output_fields fs;
+ std::copy(tok.begin(), tok.end(), std::back_inserter(fs.fields));
+ if (!fs.fields.empty()) {
+ options.push_back(&fs);
+ }
+
+ shared_ptr <SampleOutputStream> output = open_sample_output_stream(outputStream, dict, output_format, options);
auto input = make_shared<KeyValueSampleParser>(output, dict);