]> pilppa.org Git - lib1wire.git/blobdiff - src/DeviceData.cc
W1Store --> Store...
[lib1wire.git] / src / DeviceData.cc
index 5f95966edae83aa8b5156ab58289bd49bd8ded33..d066bbdc3f96f9f423d0c58935b3709baae9547f 100644 (file)
@@ -11,7 +11,7 @@
 
 #include "W1Util.hh"
 #include "DeviceData.hh"
-#include "W1Store.hh"
+#include "Store.hh"
 #include "DeviceConfig.hh"
 #include "Factory.hh"
 
@@ -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,9 +42,9 @@ 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;
+       Store           *store;
        Data            *ret_val;
 
        ret_val = NULL;
@@ -57,11 +57,11 @@ 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);
+                               store   = new Store(f_name);
                                ret_val = store->get_oldest_data();
                                delete(store);
                                break;
@@ -80,7 +80,7 @@ Data *DeviceData::find_newest_data(vector<string> year_vector) {
        string          f_name;
        Data            *ret_val;
        int             size;
-       W1Store         *store;
+       Store           *store;
 
        ret_val = NULL;
        size    = year_vector.size();
@@ -98,7 +98,7 @@ Data *DeviceData::find_newest_data(vector<string> year_vector) {
                        if (size > 0) {
                                f_name  = d_vcr.at(size - 1);
                                f_name  = W1Util::concat_paths(mon_dr, f_name);
-                               store   = new W1Store(f_name);
+                               store   = new Store(f_name);
                                ret_val = store->get_newest_data();
                                delete(store);
                                break;
@@ -169,33 +169,35 @@ 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;
+       Store   *store;
        bool    suc_flg;
+       //Store *cache_store;
 
        ret_val = NULL;
-       store   = new W1Store(device_id, date);
+       store   = new Store(device_id, 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 +217,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 +232,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 +249,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;
+       Store           *store;
 
-       store   = new W1Store(device_id, date);
+       ret_val = NULL;
+       store   = new Store(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 +268,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 +315,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;