23 #ifndef SRC_UTILS_DATACOLLECTOR_HPP_
24 #define SRC_UTILS_DATACOLLECTOR_HPP_
33 #include<logger/Log.hpp>
45 template <
typename DATA_TYPE>
50 std::vector<DATA_TYPE>
data;
83 template<
class DATA_TYPE>
92 template<
class LABEL_TYPE,
class DATA_TYPE>
93 using DataContainers =
typename std::map<LABEL_TYPE, DataContainerPtr <DATA_TYPE> >;
103 template<
class LABEL_TYPE,
class DATA_TYPE>
104 using DataContainerIt =
typename std::map<LABEL_TYPE, DataContainerPtr <DATA_TYPE> >::iterator;
113 template <
class LABEL_TYPE,
class DATA_TYPE>
135 LOG(LTRACE)<<
"DataCollector::createDataContainer";
139 tmp->auto_scale =
false;
140 tmp->min_value = min_;
141 tmp->max_value = max_;
142 tmp->line_width = line_width_;
145 containers.insert( std::make_pair (label_, tmp) );
155 LOG(LTRACE)<<
"DataCollector::createDataContainer";
159 tmp->auto_scale =
true;
160 tmp->min_value = std::numeric_limits<DATA_TYPE>::max();
161 tmp->max_value = std::numeric_limits<DATA_TYPE>::min();
162 tmp->line_width = line_width_;
165 containers.insert( std::make_pair (label_, tmp) );
175 LOG(LTRACE)<<
"DataCollector::addDataToContainer";
182 (it->second)->data.push_back(value_);
184 if ((it->second)->auto_scale) {
185 (it->second)->min_value = (value_ < (it->second)->min_value) ? value_ : (it->second)->min_value;
186 (it->second)->max_value = (value_ > (it->second)->max_value) ? value_ : (it->second)->max_value;
189 LOG(LERROR) <<
"There is no container with label: " << label_;
199 LOG(LTRACE)<<
"DataCollector::getContainerData";
205 LOG(LERROR) <<
"There is no container with label: " << label_;
208 tmp->auto_scale =
true;
209 tmp->min_value = std::numeric_limits<DATA_TYPE>::max();
210 tmp->max_value = std::numeric_limits<DATA_TYPE>::min();
221 LOG(LTRACE)<<
"DataCollector::getContainer";
231 LOG(LTRACE)<<
"DataCollector::exportDataToCsv";
233 std::ofstream output(filename_);
238 output << it->first <<
", min ,";
239 output << (it->second)->min_value <<
", max, ";
240 output << (it->second)->max_value << std::endl;
243 if ((it->second)->data.size() > 1)
244 std::copy((it->second)->data.begin(), (it->second)->data.end() - 1, std::ostream_iterator<DATA_TYPE>(output,
", "));
245 if ((it->second)->data.size())
246 output << (it->second)->data.back() << std::endl;
257 static void exportVectorToCsv(std::string filename_, std::string label_, std::vector<DATA_TYPE> data_,
bool append_ =
false){
258 LOG(LTRACE)<<
"DataCollector::exportVectorToCsv";
260 std::ofstream output;
262 output.open(filename_);
264 output.open(filename_, std::ofstream::out | std::ofstream::app);
267 output << label_ << std::endl;
270 if (data_.size() > 1)
271 std::copy(data_.begin(), data_.end() - 1, std::ostream_iterator<DATA_TYPE>(output,
", "));
273 output << data_.back() << std::endl;
283 static void exportValueToCsv(std::string filename_, std::string label_, DATA_TYPE value_,
bool append_ =
false){
284 LOG(LTRACE)<<
"DataCollector::exportValueToCsv";
286 std::ofstream output;
288 output.open(filename_);
290 output.open(filename_, std::ofstream::out | std::ofstream::app);
293 output << label_ <<
", " << value_ << std::endl;
304 LOG(LTRACE)<<
"DataCollector::exportCommentToCsv";
306 std::ofstream output;
308 output.open(filename_);
310 output.open(filename_, std::ofstream::out | std::ofstream::app);
313 output << exportCommentToCsv << std::endl;
325 LOG(LTRACE)<<
"DataCollector::exportVectorToCsv";
327 std::ofstream output;
329 output.open(filename_);
331 output.open(filename_, std::ofstream::out | std::ofstream::app);
334 output << label_ << std::endl;
337 for (
size_t y = 0; y < (size_t)matrix_->rows(); y++) {
338 for (
size_t x = 0; x < (size_t)matrix_->cols(); x++) {
339 output << matrix_(y,x) <<
", ";
355 LOG(LTRACE)<<
"DataCollector::exportVectorToCsv";
357 std::ofstream output;
359 output.open(filename_);
361 output.open(filename_, std::ofstream::out | std::ofstream::app);
364 output << label_ << std::endl;
366 for (
size_t i=0; i<data_.size(); i++) {
373 for (
size_t y = 0; y < (size_t)matrix_ptr->rows(); y++) {
374 for (
size_t x = 0; x < (size_t)matrix_ptr->cols(); x++) {
375 output << (*matrix_ptr)(y,x) <<
", ";
399 template<
class LABEL_TYPE,
class DATA_TYPE>
400 using DataCollectorPtr =
typename std::shared_ptr<mic::utils::DataCollector<LABEL_TYPE, DATA_TYPE > >;
DataContainers< LABEL_TYPE, DATA_TYPE > getContainers()
typename std::shared_ptr< DataContainer< DATA_TYPE > > DataContainerPtr
Type representing a pointer to data container.
mic::types::color_rgba color
typename std::shared_ptr< mic::utils::DataCollector< LABEL_TYPE, DATA_TYPE > > DataCollectorPtr
A pointer to data collector.
void exportDataToCsv(std::string filename_="data.csv")
Contains definition of basic matrix datatypes derived from Eigen.
void createContainer(LABEL_TYPE label_, DATA_TYPE min_, DATA_TYPE max_, mic::types::color_rgba color_=mic::types::color_rgba(255, 255, 255, 180), float line_width_=1.0f)
DataContainerPtr< DATA_TYPE > getDataFromContainer(LABEL_TYPE label_)
typename std::map< LABEL_TYPE, DataContainerPtr< DATA_TYPE > > DataContainers
Type representing a set (map) of containers.
Class responsible for collection of data during experiments end exporting the results to files...
static void exportMatrixToCsv(std::string filename_, std::string label_, std::shared_ptr< mic::types::Matrix< DATA_TYPE > > matrix_, bool append_=false)
DataContainers< LABEL_TYPE, DATA_TYPE > containers
static void exportValueToCsv(std::string filename_, std::string label_, DATA_TYPE value_, bool append_=false)
typename std::shared_ptr< mic::types::Matrix< T > > MatrixPtr
Typedef for a shared pointer to template-typed dynamic matrices.
typename std::map< LABEL_TYPE, DataContainerPtr< DATA_TYPE > >::iterator DataContainerIt
Type representing a data container iterator.
static void exportCommentToCsv(std::string filename_, std::string exportCommentToCsv, bool append_=false)
Class for storing single a pixel of four channel (RGBA) image.
std::vector< DATA_TYPE > data
void createContainer(LABEL_TYPE label_, mic::types::color_rgba color_=mic::types::color_rgba(255, 255, 255, 180), float line_width_=1.0f)
static void exportMatricesToCsv(std::string filename_, std::string label_, std::vector< mic::types::MatrixPtr< DATA_TYPE > > data_, bool append_=false)
Template-typed Matrix of dynamic size. Uses OpenBLAS if found by CMAKE - overloaded, specializations of * operator for types: float, double.
void addDataToContainer(LABEL_TYPE label_, DATA_TYPE value_)
static void exportVectorToCsv(std::string filename_, std::string label_, std::vector< DATA_TYPE > data_, bool append_=false)