diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-22 11:15:04 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-22 11:15:04 +0100 |
commit | 46309b7bb5795ac15fc7953deb13c98c90040cad (patch) | |
tree | d3f8d9c87d07f11814b716d2d1691dbd843875a0 | |
parent | d76bf876d4ce8e845a8e03a48b72a4ad4761359f (diff) | |
download | ble-toys-46309b7bb5795ac15fc7953deb13c98c90040cad.tar.gz ble-toys-46309b7bb5795ac15fc7953deb13c98c90040cad.tar.bz2 ble-toys-46309b7bb5795ac15fc7953deb13c98c90040cad.tar.xz ble-toys-46309b7bb5795ac15fc7953deb13c98c90040cad.zip |
o Start of a tool to select columns,
-rw-r--r-- | apps/CMakeLists.txt | 1 | ||||
-rw-r--r-- | apps/sample-select.cpp | 123 |
2 files changed, 124 insertions, 0 deletions
diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 5510cb3..99bef28 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -2,6 +2,7 @@ list(APPEND APPS log4cplus-test) list(APPEND APPS ble-inspect-device) list(APPEND APPS sample-convert) list(APPEND APPS sample-timestamp) +list(APPEND APPS sample-select) list(APPEND APPS sm-db-insert) list(APPEND APPS sm-db-select) list(APPEND APPS sm-get-value) diff --git a/apps/sample-select.cpp b/apps/sample-select.cpp new file mode 100644 index 0000000..d1954b3 --- /dev/null +++ b/apps/sample-select.cpp @@ -0,0 +1,123 @@ +#include "SoilMoistureIo.h" +#include "apps.h" +#include <boost/tokenizer.hpp> + +namespace trygvis { +namespace apps { + +using namespace std; +using namespace trygvis::apps; +using namespace trygvis::soil_moisture; +using boost::tokenizer; +namespace po = boost::program_options; + +class sample_select : public app { + +private: + string fields; + +public: + void add_options(po::options_description_easy_init &options) override { + options + ("help", "produce this help message") + ("fields", po::value<string>(&fields)->required()); + } + + int main(app_execution &execution) override { + tokenizer<> tok(fields); + + for (tokenizer<>::iterator beg = tok.begin(); beg != tok.end(); ++beg) { + cout << *beg << "\n"; + } + + /* + KeyDictionary dict; + + relative_key = dict.indexOf(relative_name); + + auto sample_buffer = make_shared<VectorSampleOutputStream>(); + auto parser = open_sample_input_stream(sample_buffer, dict); + while (!input.fail()) { + char buffer[buffer_size]; + input.read(buffer, buffer_size); + auto count = (size_t) input.gcount(); + + cerr << "eof? " << input.eof() << endl; + mutable_buffers_1 b = boost::asio::buffer(buffer, count); + parser->process(b); + } + + if (sample_buffer->samples.empty()) { + cerr << "Could not find any samples" << endl; + return EXIT_FAILURE; + } + + time_t end_time = buf.st_mtim.tv_sec; + + SampleRecord sample = *--sample_buffer->samples.end(); + + o<string> 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; + } + + long relative; + try { + relative = boost::lexical_cast<long>(s.get()); + } catch (const boost::bad_lexical_cast &e) { + cerr << "Bad integer value '" + s.get() + "'." << endl; + return EXIT_FAILURE; + } + + if (relative_resolution == time_resolution::MILLISECONDS) { + relative /= 1000; + } + + time_t start_time = end_time - relative; + cerr << "end_time " << end_time << endl; + cerr << "relative " << relative << endl; + cerr << "start_time " << start_time << endl; + + // Restart the reading of the input file and add the adjusted timestamp + input.clear(ios::eofbit); + input.seekg(0); + if(input.fail()) { + cerr << "Coult not seek input file" << endl; + return EXIT_FAILURE; + } + + vector<sample_output_stream_option*> options = {}; + unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, parser->type(), options); + shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)}; + shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict, timestamp_name, relative_name, relative_resolution, start_time); + parser = open_sample_input_stream(p, dict, parser->type()); + + int recordCount = 0; + + while (!input.eof()) { + char buffer[buffer_size]; + input.read(buffer, buffer_size); + size_t gcount = (size_t)input.gcount(); + + recordCount++; + + mutable_buffers_1 b = boost::asio::buffer(buffer, gcount); + parser->process(b); + } + */ + return EXIT_SUCCESS; + }; +}; + +} +} + +using namespace trygvis::apps; + +int main(int argc, char *argv[]) { + sample_select app; + return launch_app(argc, argv, app); +} |