sdk.cc 1.4 KB
Newer Older
S
superjom 已提交
1 2 3 4
#include "visualdl/logic/sdk.h"

namespace visualdl {

S
superjom 已提交
5
namespace components {
S
superjom 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

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();
}
S
superjom 已提交
57 58 59 60 61 62

template class Scalar<int>;
template class Scalar<int64_t>;
template class Scalar<float>;
template class Scalar<double>;

S
superjom 已提交
63 64 65
}  // namespace components

}  // namespace visualdl