From ac03535bc7d08c4fc05c19eda6271e92b6558e41 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sat, 21 Mar 2015 18:07:44 +0100 Subject: o Dropping empty samples when looking for an end sample. --- README-apps.md | 16 ++++++++++++++++ apps/SoilMoistureIo.cpp | 4 ++++ apps/sample-timestamp.cpp | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 README-apps.md diff --git a/README-apps.md b/README-apps.md new file mode 100644 index 0000000..f9c3753 --- /dev/null +++ b/README-apps.md @@ -0,0 +1,16 @@ +Example pipeline that adds an absolute timestamp and converts to CSV. + + sample-timestamp --input log.txt --relative-name now | \ + sample-convert --output-format csv > log.csv + +Example input: + + analog=251, dry=0, pumping_water=0, last_watering_started=234, last_watering_stopped=235, now=346 + +Example output: + + now,analog,dry,pumping_water,last_watering_started,last_watering_stopped,timestamp + 346,251,0,0,234,235,1425594335 + 347,249,0,0,234,235,1425594336 + 348,248,0,0,234,235,1425594337 + 349,245,0,0,234,235,1425594338 diff --git a/apps/SoilMoistureIo.cpp b/apps/SoilMoistureIo.cpp index 7d8f5bb..66e1dce 100644 --- a/apps/SoilMoistureIo.cpp +++ b/apps/SoilMoistureIo.cpp @@ -12,6 +12,10 @@ using namespace std; using json = nlohmann::json; void VectorSampleOutputStream::write(SampleRecord const &sample) { + if (sample.empty()) { + return; + } + samples.emplace_back(sample); } diff --git a/apps/sample-timestamp.cpp b/apps/sample-timestamp.cpp index 6672091..0affd36 100644 --- a/apps/sample-timestamp.cpp +++ b/apps/sample-timestamp.cpp @@ -107,7 +107,7 @@ public: return EXIT_FAILURE; } - const int buffer_size = 100; + const int buffer_size = 1024; input.seekg(-buffer_size, ios_base::end); @@ -146,6 +146,7 @@ public: o s = sample.at(relative_key); if (!s) { cerr << "Missing key '" + relative_name + "'." << endl; + cerr << "Found " << sample_buffer->samples.size() << " samples." << endl; cerr << "keys: " << sample.to_string() << endl; return EXIT_FAILURE; } -- cgit v1.2.3