using namespace plp;
DeviceData::DeviceData(string device_id_param) {
- string base_dir;
+ string base_dir;
device_config = Factory::get_device_config(device_id_param);
summary_calc_type = device_config->get_summary_calculation_type();
string year_dr;
string mon_dr;
vector<string> mon_vcr;
- vector<string> d_vcr;
+ vector<string> dta_vcr;
string f_name;
W1Store *store;
Data *ret_val;
mon_dr = mon_vcr.at(ii);
mon_dr = W1Util::concat_paths(year_dr, mon_dr);
// scan data files from month dir
- d_vcr = W1Util::get_data_files(mon_dr);
- if (d_vcr.size() > 0) {
- f_name = d_vcr.at(0);
+ dta_vcr = W1Util::get_data_files(mon_dr);
+ if (dta_vcr.size() > 0) {
+ f_name = dta_vcr.at(0);
f_name = W1Util::concat_paths(mon_dr, f_name);
store = new W1Store(f_name);
ret_val = store->get_oldest_data();
return ret_val;
}
-Data *DeviceData::get_day_summary(Date *date) {
+Data *DeviceData::get_daily_summary(Date *date,
+ int calc_type) {
Data *ret_val;
W1Store *store;
bool suc_flg;
if (store != NULL) {
suc_flg = store->load();
if (suc_flg == true) {
- switch(summary_calc_type) {
+ switch(calc_type) {
case SUM:
ret_val = store->get_sum();
break;
return ret_val;
}
+Data *DeviceData::get_daily_summary(Date *date) {
+ Data *ret_val;
+
+ ret_val = get_daily_summary(date, summary_calc_type);
+ return ret_val;
+}
+
DataRange *DeviceData::get_daily_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
ret_val = NULL;
date = start_date->clone();
while(date->before(*end_date)) {
- data = get_day_summary(date);
+ data = get_daily_summary(date);
if (data != NULL) {
if (ret_val == NULL) {
ret_val = new DataRange(data);
return ret_val;
}
-vector<Data *> DeviceData::get_hourly_summary(Date *date) {
- vector<Data *> ret_val;
- W1Store * store;
+vector<Data *> *DeviceData::get_hourly_summary(Date *date,
+ int calc_type) {
+ vector<Data *> *ret_val;
+ W1Store *store;
+ ret_val = NULL;
store = new W1Store(device_id, date);
store->load();
- switch(summary_calc_type) {
-/*
+ switch(calc_type) {
case SUM:
- ret_val = store->get_sum();
+ ret_val = store->get_sum(3600);
break;
-*/
case DELTA:
ret_val = store->get_delta(3600);
break;
default:
ret_val = store->get_mean(3600);
break;
-/*
case MAX:
- ret_val = store->get_max();
+ ret_val = store->get_max(3600);
break;
case MIN:
- ret_val = store->get_min();
+ ret_val = store->get_min(3600);
break;
-*/
}
delete(store);
return ret_val;
}
+vector<Data *> *DeviceData::get_hourly_summary(Date *date) {
+ vector<Data *> *ret_val;
+
+ ret_val = get_hourly_summary(date, summary_calc_type);
+ return ret_val;
+}
+
DataRange *DeviceData::get_hourly_summary(Date *start_date,
Date *end_date) {
DataRange *ret_val;
- vector<Data *> dta_list;
+ vector<Data *> *dta_lst;
Data *data;
Date *date;
vector<Data *>::iterator iter;
ret_val = NULL;
date = start_date->clone();
while(date->before(*end_date)) {
- dta_list = get_hourly_summary(date);
- for(iter = dta_list.begin(); iter != dta_list.end(); iter++) {
+ dta_lst = get_hourly_summary(date);
+ for(iter = dta_lst->begin(); iter != dta_lst->end(); iter++) {
data = (Data *)*iter;
if (data != NULL) {
if (ret_val == NULL) {
delete(date);
return ret_val;
}
+
DataRange *DeviceData::get_data(Date *start_date,
Date *end_date) {
DataRange *ret_val;
DeviceData(std::string device_id);
virtual ~DeviceData();
DataRange *get_data_range();
+ Data *get_daily_summary(plp::Date *date, int calc_type);
/**
* 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_day_summary(plp::Date *date);
+ Data *get_daily_summary(plp::Date *date);
DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date);
- std::vector<Data *> get_hourly_summary(plp::Date *date);
+ std::vector<Data *> *get_hourly_summary(plp::Date *date, int calc_type);
+ std::vector<Data *> *get_hourly_summary(plp::Date *date);
DataRange *get_hourly_summary(plp::Date *start_date, plp::Date *end_date);
DataRange *get_data(plp::Date *start_date, plp::Date *end_date);
protected:
return ret_val;
}
-vector<Data *> W1Store::get_mean(int freq_sec) {
+vector<Data *> *W1Store::get_sum(int freq_sec) {
+ int row_count;
+ int col_count;
+ int jj;
+ int ii;
+ Data *data;
+ Data *calc;
+ Date *limit_d;
+ Date date;
+ vector<Data *> *ret_val;
+
+ ret_val = new vector<Data *>();
+ calc = NULL;
+ limit_d = NULL;
+ if (store_data == NULL) {
+ load();
+ }
+ if (store_data != NULL) {
+ row_count = store_data->get_data_row_count();
+ if (row_count > 0) {
+ col_count = store_data->get_data_column_count();
+ if (col_count > 0) {
+ for (ii = 0; ii < row_count; ii++) {
+ data = store_data->get_data(ii);
+ if (data != NULL) {
+ if (calc == NULL) {
+ calc = data->clone();
+ limit_d = data->get_date().clone();
+ limit_d->min = 0;
+ limit_d->sec = 0;
+ limit_d->inc_seconds(freq_sec);
+ }
+ else {
+ date = data->get_date();
+ if (date.before(*limit_d)) {
+ for (jj = 0; jj < col_count; jj++) {
+ calc->value_arr[jj] = calc->value_arr[jj] + data->value_arr[jj];
+ }
+ }
+ else {
+ ret_val->push_back(calc);
+ calc = data->clone();
+ if (limit_d != NULL) {
+ delete(limit_d);
+ }
+ limit_d = data->get_date().clone();
+ limit_d->min = 0;
+ limit_d->sec = 0;
+ limit_d->inc_seconds(freq_sec);
+ }
+ }
+ delete(data);
+ }
+ }
+ if (calc != NULL) {
+ delete(calc);
+ calc = NULL;
+ }
+ if (limit_d != NULL) {
+ delete(limit_d);
+ }
+ }
+ }
+ }
+ return ret_val;
+}
+
+vector<Data *> *W1Store::get_mean(int freq_sec) {
int row_count;
int col_count;
int d_count;
Data *calc;
Date *limit_d;
Date date;
- vector<Data *> ret_val;
+ vector<Data *> *ret_val;
+ ret_val = new vector<Data *>();
calc = NULL;
limit_d = NULL;
d_count = 1;
for (jj = 0; jj < col_count; jj++) {
calc->value_arr[jj] = calc->value_arr[jj] / d_count;
}
- ret_val.push_back(calc);
+ ret_val->push_back(calc);
d_count = 1;
calc = data->clone();
if (limit_d != NULL) {
return ret_val;
}
-vector<Data *> W1Store::get_delta(int freq_sec) {
+vector<Data *> *W1Store::get_delta(int freq_sec) {
int row_count;
int col_count;
int jj;
Data *calc2;
Date *limit_d;
Date date;
- vector<Data *> ret_val;
+ vector<Data *> *ret_val;
+ ret_val = new vector<Data *>();
calc1 = NULL;
calc2 = NULL;
limit_d = NULL;
for (jj = 0; jj < col_count; jj++) {
calc2->value_arr[jj] = calc2->value_arr[jj] - calc1->value_arr[jj];
}
- ret_val.push_back(calc2);
+ ret_val->push_back(calc2);
delete(calc1);
calc1 = data->clone();
calc2 = NULL; // do not delete calc2 as it's stored to array
return ret_val;
}
+vector<Data *> *W1Store::get_max_or_min(int freq_sec, bool max) {
+ int row_count;
+ int col_count;
+ int jj;
+ int ii;
+ Data *data;
+ Data *calc;
+ Date *limit_d;
+ Date date;
+ vector<Data *> *ret_val;
+
+ ret_val = new vector<Data *>();
+ calc = NULL;
+ limit_d = NULL;
+ if (store_data == NULL) {
+ load();
+ }
+ if (store_data != NULL) {
+ row_count = store_data->get_data_row_count();
+ if (row_count > 0) {
+ col_count = store_data->get_data_column_count();
+ if (col_count > 0) {
+ for (ii = 0; ii < row_count; ii++) {
+ data = store_data->get_data(ii);
+ if (data != NULL) {
+ if (calc == NULL) {
+ calc = data->clone();
+ limit_d = data->get_date().clone();
+ limit_d->min = 0;
+ limit_d->sec = 0;
+ limit_d->inc_seconds(freq_sec);
+ }
+ else {
+ date = data->get_date();
+ if (date.before(*limit_d)) {
+ if (max == true) {
+ for (jj = 0; jj < col_count; jj++) {
+ if (calc->value_arr[jj] < data->value_arr[jj]) {
+ calc->value_arr[jj] = data->value_arr[jj];
+ }
+ }
+ }
+ else {
+ for (jj = 0; jj < col_count; jj++) {
+ if (data->value_arr[jj] < calc->value_arr[jj]) {
+ calc->value_arr[jj] = data->value_arr[jj];
+ }
+ }
+ }
+ }
+ else {
+ ret_val->push_back(calc);
+ calc = data->clone();
+ if (limit_d != NULL) {
+ delete(limit_d);
+ }
+ limit_d = data->get_date().clone();
+ limit_d->min = 0;
+ limit_d->sec = 0;
+ limit_d->inc_seconds(freq_sec);
+ }
+ }
+ delete(data);
+ }
+ }
+ if (calc != NULL) {
+ delete(calc);
+ calc = NULL;
+ }
+ if (limit_d != NULL) {
+ delete(limit_d);
+ }
+ }
+ }
+ }
+ return ret_val;
+}
+
+vector<Data *> *W1Store::get_max(int freq_sec) {
+ vector<Data *> *ret_val;
+
+ ret_val = get_max_or_min(freq_sec, true);
+ return ret_val;
+}
+
+vector<Data *> *W1Store::get_min(int freq_sec) {
+ vector<Data *> *ret_val;
+
+ ret_val = get_max_or_min(freq_sec, false);
+ return ret_val;
+}
+
DataRange *W1Store::get_oldest_and_newest_data() {
DataRange *ret_val;
ifstream in;
Data *get_mean();
Data *get_max();
Data *get_min();
- std::vector<w1::Data *> get_mean(int freq_sec);
- std::vector<w1::Data *> get_delta(int freq_sec);
+ std::vector<w1::Data *> *get_sum(int freq_sec);
+ std::vector<w1::Data *> *get_mean(int freq_sec);
+ std::vector<w1::Data *> *get_delta(int freq_sec);
+ std::vector<w1::Data *> *get_max(int freq_sec);
+ std::vector<w1::Data *> *get_min(int freq_sec);
w1::Data *get_oldest_data();
w1::Data *get_newest_data();
w1::DataRange *get_oldest_and_newest_data();
std::string store_file_name;
DataRange *store_data;
DataRange *range_data;
+ std::vector<Data *> *get_max_or_min(int freq_sec, bool max);
};
}