started adding support device configuration data.
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
* Author: lamikr
*/
+#include <string>
#include <iostream>
+#include <sstream>
#include <stdio.h>
#include <time.h>
#include <malloc.h>
-#include "Data.hh"
#include <plp/log.h>
+#include "Data.hh"
+#include "W1Util.hh"
+
using namespace std;
using namespace plp;
using namespace w1;
+template <class NumberDataType>
+bool string_to_number(NumberDataType& result,
+ const std::string& string_param,
+ std::ios_base& (*format)(std::ios_base&))
+{
+ std::istringstream iss(string_param);
+ return !(iss >> format >> result).fail();
+}
+
Data::Data(int size) {
value_arr.resize(size);
}
}
}
+Data *Data::parse_data_string(const string& dataline) {
+ stringstream ss(dataline);
+ string item;
+ double val;
+ Data *ret_val;
+ int ii;
+ bool suc_flg;
+ vector<double> v;
+ Date date;
+
+ ii = 0;
+ while(getline(ss, item, '|')) {
+ if (ii == 0) {
+ // parse date
+ date = W1Util::parse_date_str(item);
+ }
+ // skip the device type and device id fields
+ // TODO: store device type and id to own file
+ else if (ii >= 3) {
+ suc_flg = string_to_number<double>(val, item, dec);
+ if (suc_flg) {
+ //log_debug("adding number: %f\n", val);
+ v.push_back(val);
+ }
+ }
+ ii++;
+ }
+ ret_val = new Data(v, &date);
+ return ret_val;
+}
+
DataRange::DataRange(int value_count_per_data_item) {
val_matrix = NULL;
column_count = value_count_per_data_item;
plp::Date get_date();
void set_date(plp::Date date);
void printout();
+ static Data *parse_data_string(const std::string& dataline);
std::valarray<double> value_arr;
private:
plp::Date date_time;
--- /dev/null
+/*
+ * DeviceConfig.cc
+ *
+ * Created on: Dec 9, 2010
+ * Author: lamikr
+ */
+
+#include "DeviceConfig.hh"
+
+using namespace std;
+using namespace w1;
+
+DeviceConfig::DeviceConfig(string device_id_param) {
+ device_id = device_id_param;
+}
+
+DeviceConfig::~DeviceConfig() {
+}
+
+string DeviceConfig::get_config_value(string key) {
+ return NULL;
+}
--- /dev/null
+/*
+ * DeviceConfig.hh
+ *
+ * Created on: Dec 9, 2010
+ * Author: lamikr
+ */
+
+#ifndef DEVICECONFIG_HH_
+#define DEVICECONFIG_HH_
+
+#include <string>
+
+namespace w1 {
+ class DeviceConfig {
+ public:
+ DeviceConfig(std::string device_id_param);
+ virtual ~DeviceConfig();
+ std::string get_config_value(std::string key);
+ private:
+ std::string device_id;
+ };
+}
+
+#endif /* DEVICECONFIG_HH_ */
W1CounterDevice.cc W1CounterDevice.hh \
W1Util.cc W1Util.hh \
W1DataList.cc W1DataList.hh \
+ DeviceConfig.cc DeviceConfig.hh \
Data.cc Data.hh \
Date.cc Date.hh \
W1Configure.hh
return ret_val;
}
-string W1DataList::get_day_data(Date *date) {
- string ret_val;
-
- ret_val = W1Store::get_file_name(device_id, date);
- return ret_val;
-}
-
-Data *W1DataList::get_avg_day_data(Date *date) {
+Data *W1DataList::get_daily_summary(Date *date) {
Data *data;
W1Store *store;
return data;
}
-DataRange *W1DataList::get_avg_day_data(Date *start_date,
+DataRange *W1DataList::get_daily_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
Data *data;
ret_val = NULL;
date = start_date->clone();
while(date->before(*end_date)) {
- data = get_avg_day_data(date);
+ data = get_daily_summary(date);
if (ret_val == NULL) {
ret_val = new DataRange(*data);
}
int_type = get_interval_type(start_date, end_date);
switch(int_type) {
case 0:
- log_debug("get avg year data\n");
+ log_debug("get yearly summary\n");
break;
case 1:
- log_debug("get avg month data\n");
+ log_debug("get monthly summary\n");
break;
case 2:
- log_debug("get avg day data\n");
- ret_val = get_avg_day_data(start_date, end_date);
+ log_debug("get daily summary\n");
+ ret_val = get_daily_summary(start_date, end_date);
break;
case 3:
- log_debug("get avg hour data\n");
+ log_debug("get hourly summary\n");
break;
case 4:
- log_debug("get avg min data\n");
+ log_debug("get minute summary data\n");
break;
case 5:
- log_debug("get avg sec data\n");
+ log_debug("get second summary data\n");
break;
}
return ret_val;
W1DataList(std::string device_id);
virtual ~W1DataList();
DataRange *get_data_range();
- Data *get_avg_day_data(plp::Date *date);
- DataRange *get_avg_day_data(plp::Date *start_date, plp::Date *end_date);
+ /**
+ * Get summary data calculated from the daily data items that is meaning full.
+ * Depending from the device type, it may be daily mean value, daily delta, highest value, etc...
+ */
+ Data *get_daily_summary(plp::Date *date);
+ DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date);
DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
protected:
std::string device_id;
std::string device_dir;
std::string device_ch_dir;
- std::string get_day_data(plp::Date *date);
Data *find_oldest_data(std::vector<std::string> year_vector);
Data *find_newest_data(std::vector<std::string> year_vector);
if (in.is_open() == true) {
while (in.eof() == false) {
getline(in, line);
- data = W1Util::parse_data_line(line);
+ data = Data::parse_data_string(line);
if (store_data == NULL) {
store_data = new DataRange(*data);
}
getline(in, line);
if (line.empty() == false) {
if (o_data == NULL) {
- o_data = W1Util::parse_data_line(line);
+ o_data = Data::parse_data_string(line);
}
prev_line = line;
}
}
if (prev_line.empty() == false) {
- n_data = W1Util::parse_data_line(prev_line);
+ n_data = Data::parse_data_string(prev_line);
}
}
}
ss >>ret_val.year >>c >>ret_val.month >>c >>ret_val.day >>ret_val.hour >>c >>ret_val.min >>c >>ret_val.sec;
return ret_val;
}
-
-Data *W1Util::parse_data_line(const string& dataline) {
- stringstream ss(dataline);
- string item;
- double val;
- Data *ret_val;
- int ii;
- bool suc_flg;
- vector<double> v;
- Date date;
-
- ii = 0;
- while(getline(ss, item, '|')) {
- if (ii == 0) {
- // parse date
- date = parse_date_str(item);
- }
- // skip the device type and device id fields
- // TODO: store device type and id to own file
- else if (ii >= 3) {
- suc_flg = string_to_number<double>(val, item, dec);
- if (suc_flg) {
- //log_debug("adding number: %f\n", val);
- v.push_back(val);
- }
- }
- ii++;
- }
- ret_val = new Data(v, &date);
- return ret_val;
-}
static std::vector<std::string> get_subdirectories(const std::string& path);
static std::vector<std::string> get_data_files(const std::string& path);
static plp::Date parse_date_str(std::string date_str);
- static Data *parse_data_line(const std::string& dataline);
static char *parse_directory_path(const char *file_path);
static bool mkdirs(char *path);
static std::ofstream *open_for_writing(const char *path);