diff --git a/visualdl/logic/CMakeLists.txt b/visualdl/logic/CMakeLists.txt index f1a4250dc342caa116e32c6e54c7da99150cc75f..046e40489b714dcdc881ab06145c933eaf97e989 100644 --- a/visualdl/logic/CMakeLists.txt +++ b/visualdl/logic/CMakeLists.txt @@ -1,6 +1,8 @@ #add_library(sdk ${PROJECT_SOURCE_DIR}/visualdl/logic/sdk.cc) add_library(im ${PROJECT_SOURCE_DIR}/visualdl/logic/im.cc) +add_library(sdk ${PROJECT_SOURCE_DIR}/visualdl/logic/sdk.cc) add_dependencies(im storage_proto) +add_dependencies(sdk storage_proto) #add_dependencies(sdk storage_proto) ## pybind diff --git a/visualdl/logic/sdk.cc b/visualdl/logic/sdk.cc index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..8ac545813825734251c786d8e853f327c6ff1dc4 100644 --- a/visualdl/logic/sdk.cc +++ b/visualdl/logic/sdk.cc @@ -0,0 +1,59 @@ +#include "visualdl/logic/sdk.h" + +namespace visualdl { + +namespace components { + +template +void components::Scalar::AddRecord(int id, const std::vector &values) { + // add record data + auto record = tablet_.AddRecord(); + auto entry = record.AddData(); + for (auto v : values) { + entry.Add(v); + } + // set record id + record.SetId(id); + // set record timestamp + record.SetTimeStamp(time(NULL)); +} + +template +std::vector ScalarReader::records() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).data(0)); + } + return res; +} + +template +std::vector ScalarReader::ids() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).id()); + } + return res; +} + +template +std::vector ScalarReader::timestamps() const { + std::vector res; + for (int i = 0; i < reader_.total_records(); i++) { + res.push_back(reader_.record(i).timestamp()); + } + return res; +} + +template +std::vector ScalarReader::captions() const { + return reader_.captions(); +} + +template +size_t ScalarReader::size() const { + return reader_.total_records(); +} +} // namespace components + +} // namespace visualdl diff --git a/visualdl/logic/sdk.h b/visualdl/logic/sdk.h index b3c12f915b1f59144126dc8cbcdf9773a0d4ece2..930fc24ede8bf9837679351bb00e0871fed18aca 100644 --- a/visualdl/logic/sdk.h +++ b/visualdl/logic/sdk.h @@ -11,17 +11,32 @@ namespace components { * Read and write support for Scalar component. */ template -class Scalar { -public: - Scalar(Tablet tablet) : tablet_(tablet) { tablet_->SetTag(kScalar); } +struct Scalar { + Scalar(Tablet tablet) : tablet_(tablet) { tablet_.SetType(Tablet::Type::kScalar);} void SetCaption(const std::string cap) { - tablet_->SetCaptions(std::vector({cap})); + tablet_.SetCaptions(std::vector({cap})); } + void AddRecord(int id, const std::vector &values); + private: Tablet tablet_; }; +template +struct ScalarReader { + ScalarReader(TabletReader&& reader) : reader_(reader) {} + + std::vector records() const; + std::vector ids() const; + std::vector timestamps() const; + std::vector captions() const; + size_t size() const; + + private: + TabletReader reader_; +}; + } // namespace components } // namespace visualdl diff --git a/visualdl/storage/storage_test.cc b/visualdl/storage/storage_test.cc index 9eebdc41d5f44618bfb30bc02caa57b792eef178..8603bf3c0b1bba92d9abb9faba2ff35eecb4c595 100644 --- a/visualdl/storage/storage_test.cc +++ b/visualdl/storage/storage_test.cc @@ -21,7 +21,6 @@ TEST_F(StorageTest, main) { auto tag0 = storage.AddTablet("tag0"); auto tag1 = storage.AddTablet("tag1"); - StorageReader reader("./tmp/storage_test"); auto modes = reader.Modes();