Skip to content
Snippets Groups Projects
Commit 60306176 authored by Tom Fischer's avatar Tom Fischer
Browse files

Changed SensorData::addTimeSeries() and used logog logging within class SensorData.

parent 6456e087
No related branches found
No related tags found
No related merge requests found
...@@ -10,12 +10,16 @@ ...@@ -10,12 +10,16 @@
* Created on 2012-08-01 by Karsten Rink * Created on 2012-08-01 by Karsten Rink
*/ */
#include <cstdlib>
#include <fstream>
// ThirdParty/logog
#include "logog/include/logog.hpp"
#include "SensorData.h" #include "SensorData.h"
#include "StringTools.h" #include "StringTools.h"
#include "DateTools.h" #include "DateTools.h"
#include <cstdlib>
#include <fstream>
SensorData::SensorData(const std::string &file_name) SensorData::SensorData(const std::string &file_name)
...@@ -30,7 +34,7 @@ SensorData::SensorData(std::vector<size_t> time_steps) ...@@ -30,7 +34,7 @@ SensorData::SensorData(std::vector<size_t> time_steps)
for (size_t i=1; i<time_steps.size(); i++) for (size_t i=1; i<time_steps.size(); i++)
{ {
if (time_steps[i-1]>=time_steps[i]) if (time_steps[i-1]>=time_steps[i])
std::cout << "Error in SensorData() - Time series has no order!" << std::endl; ERR("Error in SensorData() - Time series has no order!");
} }
} }
...@@ -51,19 +55,21 @@ void SensorData::addTimeSeries( const std::string &data_name, std::vector<float> ...@@ -51,19 +55,21 @@ void SensorData::addTimeSeries( const std::string &data_name, std::vector<float>
void SensorData::addTimeSeries( SensorDataType::type data_name, std::vector<float> *data, const std::string &data_unit_string ) void SensorData::addTimeSeries( SensorDataType::type data_name, std::vector<float> *data, const std::string &data_unit_string )
{ {
if (_step_size>0) if (_step_size>0) {
{ if (((_end-_start)/_step_size) != data->size()) {
if (((_end-_start)/_step_size) != data->size()) WARN("Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps.");
std::cout << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps." << std::endl; return;
} }
else if (data->size() != _time_steps.size()) } else {
std::cout << "Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps." << std::endl; if (data->size() != _time_steps.size()) {
else WARN("Warning in SensorData::addTimeSeries() - Lengths of time series does not match number of time steps.");
{ return;
_vec_names.push_back(data_name); }
_data_vecs.push_back(data);
_data_unit_string.push_back(data_unit_string);
} }
_vec_names.push_back(data_name);
_data_vecs.push_back(data);
_data_unit_string.push_back(data_unit_string);
} }
const std::vector<float>* SensorData::getTimeSeries(SensorDataType::type time_series_name) const const std::vector<float>* SensorData::getTimeSeries(SensorDataType::type time_series_name) const
...@@ -73,18 +79,18 @@ const std::vector<float>* SensorData::getTimeSeries(SensorDataType::type time_se ...@@ -73,18 +79,18 @@ const std::vector<float>* SensorData::getTimeSeries(SensorDataType::type time_se
if (time_series_name == _vec_names[i]) if (time_series_name == _vec_names[i])
return _data_vecs[i]; return _data_vecs[i];
} }
std::cout << "Error in SensorData::getTimeSeries() - Time series \"" << time_series_name << "\" not found." << std::endl; ERR("Error in SensorData::getTimeSeries() - Time series \"%d\" not found.", time_series_name);
return NULL; return NULL;
} }
const std::string SensorData::getDataUnit(SensorDataType::type time_series_name) const std::string SensorData::getDataUnit(SensorDataType::type time_series_name) const
{ {
for (size_t i=0; i<_vec_names.size(); i++) for (size_t i=0; i<_vec_names.size(); i++)
{ {
if (time_series_name == _vec_names[i]) if (time_series_name == _vec_names[i])
return _data_unit_string[i]; return _data_unit_string[i];
} }
std::cout << "Error in SensorData::getDataUnit() - Time series \"" << time_series_name << "\" not found." << std::endl; ERR("Error in SensorData::getDataUnit() - Time series \"%d\" not found.", time_series_name);
return ""; return "";
} }
...@@ -94,7 +100,7 @@ int SensorData::readDataFromFile(const std::string &file_name) ...@@ -94,7 +100,7 @@ int SensorData::readDataFromFile(const std::string &file_name)
if (!in.is_open()) if (!in.is_open())
{ {
std::cout << "SensorData::readDataFromFile() - Could not open file...\n"; INFO("SensorData::readDataFromFile() - Could not open file %s.", file_name.c_str());
return 0; return 0;
} }
......
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
TimeStepType::type getTimeUnit() const { return _time_unit; }; TimeStepType::type getTimeUnit() const { return _time_unit; };
/// Returns the data unit of the given time series /// Returns the data unit of the given time series
const std::string getDataUnit(SensorDataType::type t) const; std::string getDataUnit(SensorDataType::type t) const;
/// Converts Sensor Data Types to Strings /// Converts Sensor Data Types to Strings
static std::string convertSensorDataType2String(SensorDataType::type t); static std::string convertSensorDataType2String(SensorDataType::type t);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment