W1DataList::W1DataList(string device_id_param) {
string base_dir;
- device_id = device_id_param;
- base_dir = W1Store::get_base_dir_name();
- device_dir = W1Util::concat_paths(base_dir, device_id);
- device_ch_dir = W1Util::concat_paths(base_dir, "cache");
- device_ch_dir = W1Util::concat_paths(device_ch_dir, device_id);
+ device_config = new DeviceConfig(device_id_param);
+ summary_calc_type = device_config->get_summary_calculation_type();
+ device_id = device_id_param;
+ base_dir = W1Store::get_base_dir_name();
+ device_dir = W1Util::concat_paths(base_dir, device_id);
+ device_ch_dir = W1Util::concat_paths(base_dir, "cache");
+ device_ch_dir = W1Util::concat_paths(device_ch_dir, device_id);
}
W1DataList::~W1DataList() {
- //delete(device_dir);
+ delete(device_config);
}
Data *W1DataList::find_oldest_data(vector<string> year_vector) {
}
Data *W1DataList::get_daily_summary(Date *date) {
- Data *data;
+ Data *ret_val;
W1Store *store;
store = new W1Store(device_id, date);
store->load();
- data = store->get_mean();
- data->printout();
+ switch(summary_calc_type) {
+ case SUM:
+ ret_val = store->get_sum();
+ break;
+ case DELTA:
+ ret_val = store->get_delta();
+ break;
+ case MEAN:
+ default:
+ ret_val = store->get_mean();
+ break;
+ case MAX:
+ ret_val = store->get_max();
+ break;
+ case MIN:
+ ret_val = store->get_min();
+ break;
+ }
+ ret_val->printout();
delete(store);
- return data;
+ return ret_val;
}
DataRange *W1DataList::get_daily_summary(Date *start_date,
#include <string>
#include <fstream>
#include <valarray>
+#include <limits>
#include <time.h>
#include <dirent.h>
}
}
+Data *W1Store::get_sum() {
+ int row_count;
+ int col_count;
+ double new_val;
+ int ii;
+ int jj;
+ Date *date;
+ Data *data;
+ Data *ret_val;
+
+ ret_val = NULL;
+ data = NULL;
+ if (store_data == NULL) {
+ load();
+ }
+ if (store_data != NULL) {
+ row_count = store_data->get_data_row_count();
+ log_debug("data row count: %d\n", row_count);
+ if (row_count > 0) {
+ col_count = store_data->get_data_column_count();
+ log_debug("data item count per row: %d\n", col_count);
+ ret_val = new Data(col_count);
+ if (col_count > 0) {
+ for (ii = 0; ii < row_count - 1; ii++) {
+ data = store_data->get_data(ii);
+ for (jj = 0; jj < col_count; jj++) {
+ new_val = data->value_arr[jj];
+ ret_val->value_arr[jj] = ret_val->value_arr[jj] + new_val;
+ }
+ if (ii < (row_count - 2)) {
+ delete(data);
+ data = NULL;
+ }
+ //log_debug("new val: %f, sum: %f\n", new_val, sum);
+ }
+ }
+ ret_val->set_date(data->get_date());
+ if (data != NULL) {
+ delete(data);
+ }
+ }
+ }
+ return ret_val;
+}
+
Data *W1Store::get_delta() {
int row_count;
int col_count;
Data *W1Store::get_mean() {
int row_count;
int col_count;
- double avg;
+ int ii;
+ Data *ret_val;
+
+ ret_val = 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();
+ ret_val = get_sum();
+ if (col_count > 0) {
+ for (ii = 0; ii < col_count; ii++) {
+ ret_val->value_arr[ii] = ret_val->value_arr[ii] / row_count;
+ log_debug("avg: %f\n", ret_val->value_arr[ii]);
+ }
+ }
+ }
+ }
+ return ret_val;
+}
+
+Data *W1Store::get_max() {
+ int row_count;
+ int col_count;
double new_val;
int ii;
int jj;
Date *date;
Data *data;
Data *ret_val;
+ double min_val;
ret_val = NULL;
data = NULL;
if (row_count > 0) {
col_count = store_data->get_data_column_count();
log_debug("data item count per row: %d\n", col_count);
- ret_val = new Data(col_count);
+ min_val = numeric_limits<double>::min();
+ ret_val = new Data(col_count, min_val);
if (col_count > 0) {
for (ii = 0; ii < row_count - 1; ii++) {
data = store_data->get_data(ii);
for (jj = 0; jj < col_count; jj++) {
- new_val = data->value_arr[jj];
- ret_val->value_arr[jj] = ret_val->value_arr[jj] + new_val;
+ new_val = data->value_arr[jj];
+ if (new_val > ret_val->value_arr[jj]) {
+ ret_val->value_arr[jj] = new_val;
+ }
}
if (ii < (row_count - 2)) {
delete(data);
data = NULL;
}
- //log_debug("new val: %f, sum: %f\n", new_val, sum);
}
- for (ii = 0; ii < col_count; ii++) {
- ret_val->value_arr[ii] = ret_val->value_arr[ii] / row_count;
- log_debug("avg: %f\n", ret_val->value_arr[ii]);
+ }
+ ret_val->set_date(data->get_date());
+ if (data != NULL) {
+ delete(data);
+ }
+ }
+ }
+ return ret_val;
+}
+
+Data *W1Store::get_min() {
+ int row_count;
+ int col_count;
+ double new_val;
+ int ii;
+ int jj;
+ Date *date;
+ Data *data;
+ Data *ret_val;
+ double max_val;
+
+ ret_val = NULL;
+ data = NULL;
+ if (store_data == NULL) {
+ load();
+ }
+ if (store_data != NULL) {
+ row_count = store_data->get_data_row_count();
+ log_debug("data row count: %d\n", row_count);
+ if (row_count > 0) {
+ col_count = store_data->get_data_column_count();
+ log_debug("data item count per row: %d\n", col_count);
+ max_val = numeric_limits<double>::max();
+ ret_val = new Data(col_count, max_val);
+ if (col_count > 0) {
+ for (ii = 0; ii < row_count - 1; ii++) {
+ data = store_data->get_data(ii);
+ for (jj = 0; jj < col_count; jj++) {
+ new_val = data->value_arr[jj];
+ if (new_val < ret_val->value_arr[jj]) {
+ ret_val->value_arr[jj] = new_val;
+ }
+ }
+ if (ii < (row_count - 2)) {
+ delete(data);
+ data = NULL;
+ }
}
}
ret_val->set_date(data->get_date());