]> pilppa.org Git - lib1wire.git/blobdiff - src/DeviceData.cc
Use pointers in date comparison functions.
[lib1wire.git] / src / DeviceData.cc
index 5f95966edae83aa8b5156ab58289bd49bd8ded33..6b75301a4c67b609683ea4cad92bcae75a9d62af 100644 (file)
@@ -22,7 +22,7 @@ using namespace std;
 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();
@@ -42,7 +42,7 @@ Data *DeviceData::find_oldest_data(vector<string> year_vector) {
        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;
@@ -57,9 +57,9 @@ Data *DeviceData::find_oldest_data(vector<string> year_vector) {
                        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();
@@ -169,7 +169,8 @@ long int get_interval_type(Date *start_date,
        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;
@@ -179,23 +180,23 @@ Data *DeviceData::get_day_summary(Date *date) {
        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;
                                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;
+                               case MEAN:
+                               default:
+                                       ret_val = store->get_mean();
+                                       break;
                        }
                        if (ret_val != NULL) {
                                ret_val->printout();
@@ -215,6 +216,13 @@ Data *DeviceData::get_day_summary(Date *date) {
        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;
@@ -223,8 +231,8 @@ DataRange *DeviceData::get_daily_summary(Date *start_date,
 
        ret_val = NULL;
        date    = start_date->clone();
-       while(date->before(*end_date)) {
-               data    = get_day_summary(date);
+       while(date->before(end_date)) {
+               data    = get_daily_summary(date);
                if (data != NULL) {
                        if (ret_val == NULL) {
                                ret_val = new DataRange(data);
@@ -240,18 +248,18 @@ DataRange *DeviceData::get_daily_summary(Date *start_date,
        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;
@@ -259,32 +267,37 @@ vector<Data *> DeviceData::get_hourly_summary(Date *date) {
                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++) {
+       while(date->before(end_date)) {
+               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) {
@@ -301,6 +314,7 @@ DataRange *DeviceData::get_hourly_summary(Date *start_date,
        delete(date);
        return ret_val;
 }
+
 DataRange *DeviceData::get_data(Date *start_date,
                                Date *end_date) {
        DataRange       *ret_val;