提交 64885033 编写于 作者: S superjom

add scalar

上级 c103645a
#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
......
#include "visualdl/logic/sdk.h"
namespace visualdl {
namespace components {
template <typename T>
void components::Scalar<T>::AddRecord(int id, const std::vector<T> &values) {
// add record data
auto record = tablet_.AddRecord();
auto entry = record.AddData<T>();
for (auto v : values) {
entry.Add(v);
}
// set record id
record.SetId(id);
// set record timestamp
record.SetTimeStamp(time(NULL));
}
template <typename T>
std::vector<T> ScalarReader<T>::records() const {
std::vector<T> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).data<T>(0));
}
return res;
}
template <typename T>
std::vector<int> ScalarReader<T>::ids() const {
std::vector<int> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).id());
}
return res;
}
template <typename T>
std::vector<int> ScalarReader<T>::timestamps() const {
std::vector<T> res;
for (int i = 0; i < reader_.total_records(); i++) {
res.push_back(reader_.record(i).timestamp());
}
return res;
}
template <typename T>
std::vector<std::string> ScalarReader<T>::captions() const {
return reader_.captions();
}
template <typename T>
size_t ScalarReader<T>::size() const {
return reader_.total_records();
}
} // namespace components
} // namespace visualdl
......@@ -11,17 +11,32 @@ namespace components {
* Read and write support for Scalar component.
*/
template <typename T>
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<std::string>({cap}));
tablet_.SetCaptions(std::vector<std::string>({cap}));
}
void AddRecord(int id, const std::vector<T> &values);
private:
Tablet tablet_;
};
template <typename T>
struct ScalarReader {
ScalarReader(TabletReader&& reader) : reader_(reader) {}
std::vector<T> records() const;
std::vector<int> ids() const;
std::vector<int> timestamps() const;
std::vector<std::string> captions() const;
size_t size() const;
private:
TabletReader reader_;
};
} // namespace components
} // namespace visualdl
......
......@@ -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();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册