From 3d2ca40bf3d475f7e2d7e67bd888bd33a94ca978 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Wed, 26 Jan 2011 02:33:37 +0200 Subject: [PATCH] Implemented yearly calculations for min, max, mean, delta and sum functions with cache support. Signed-off-by: Mika Laitio --- src/DeviceData.cc | 188 +++++++++++++++++++++++++++++++------------- src/DeviceData.hh | 19 +++-- src/Factory.cc | 1 + src/Factory.hh | 2 +- src/Store.cc | 3 - src/Store.hh | 6 ++ src/StoreCache.cc | 195 +++++++++++++++++++++++++++++++++++++--------- src/StoreCache.hh | 2 + src/StoreDay.cc | 8 +- 9 files changed, 320 insertions(+), 104 deletions(-) diff --git a/src/DeviceData.cc b/src/DeviceData.cc index d13287c..790bcae 100644 --- a/src/DeviceData.cc +++ b/src/DeviceData.cc @@ -25,86 +25,111 @@ using namespace plp; DeviceData::DeviceData(string device_id_param) { string base_dir; - device_config = Factory::get_device_config(device_id_param); - summary_calc_type = device_config->get_summary_calculation_type(); - device_id = device_id_param; - base_dir = DeviceConfig::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 = NULL; + device_id = device_id_param; + base_dir = DeviceConfig::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); } DeviceData::~DeviceData() { - delete(device_config); + if (device_config != NULL) { + delete(device_config); + device_config = NULL; + } } -Data *DeviceData::find_oldest_data(vector year_vector) { - unsigned int ii; - string year_dr; +Data *DeviceData::find_newest_data(string year_name_param) { + int ii; string mon_dr; vector mon_vcr; - vector dta_vcr; + vector d_vcr; string f_name; StoreDay *store; Data *ret_val; + string year_dr; + int size; ret_val = NULL; - if (year_vector.size() > 0) { - // dirs are alphabetically sorted - year_dr = year_vector.at(0); - year_dr = W1Util::concat_paths(device_dir, year_dr); - mon_vcr = W1Util::get_subdirectories(year_dr); - for (ii = 0; ii < mon_vcr.size(); ii++) { - mon_dr = mon_vcr.at(ii); - mon_dr = W1Util::concat_paths(year_dr, mon_dr); - // scan data files from month dir - 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 StoreDay(f_name); - ret_val = store->get_oldest_data(); - delete(store); - break; - } + year_dr = W1Util::concat_paths(device_dir, year_name_param); + mon_vcr = W1Util::get_subdirectories(year_dr); + for (ii = mon_vcr.size() - 1; ii >= 0; ii--) { + 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); + size = d_vcr.size(); + if (size > 0) { + f_name = d_vcr.at(size - 1); + f_name = W1Util::concat_paths(mon_dr, f_name); + store = new StoreDay(f_name); + ret_val = store->get_newest_data(); + delete(store); + break; } } return ret_val; } -Data *DeviceData::find_newest_data(vector year_vector) { - int ii; +Data *DeviceData::find_newest_data(vector year_name_vector_param) { + string year_name; + int size; + Data *ret_val; + + ret_val = NULL; + size = year_name_vector_param.size(); + if (size > 0) { + // dirs are alphabetically sorted + year_name = year_name_vector_param.at(size - 1); + ret_val = find_newest_data(year_name); + } + return ret_val; +} + +Data *DeviceData::find_oldest_data(string year_name_param) { + int size; + unsigned int ii; string year_dr; string mon_dr; vector mon_vcr; - vector d_vcr; + vector dta_vcr; string f_name; + StoreDay *store; Data *ret_val; - int size; - StoreDay *store; ret_val = NULL; - size = year_vector.size(); + year_dr = W1Util::concat_paths(device_dir, year_name_param); + mon_vcr = W1Util::get_subdirectories(year_dr); + for (ii = 0; ii < mon_vcr.size(); ii++) { + mon_dr = mon_vcr.at(ii); + mon_dr = W1Util::concat_paths(year_dr, mon_dr); + // scan data files from month dir + dta_vcr = W1Util::get_data_files(mon_dr); + size = dta_vcr.size(); + if (size > 0) { + f_name = dta_vcr.at(0); + f_name = W1Util::concat_paths(mon_dr, f_name); + store = new StoreDay(f_name); + ret_val = store->get_oldest_data(); + delete(store); + break; + } + } + return ret_val; +} + +Data *DeviceData::find_oldest_data(vector year_name_vector_param) { + int size; + string year_name; + Data *ret_val; + + ret_val = NULL; + size = year_name_vector_param.size(); if (size > 0) { // dirs are alphabetically sorted - year_dr = year_vector.at(size - 1); - year_dr = W1Util::concat_paths(device_dir, year_dr); - mon_vcr = W1Util::get_subdirectories(year_dr); - for (ii = mon_vcr.size() - 1; ii >= 0; ii--) { - 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); - size = d_vcr.size(); - if (size > 0) { - f_name = d_vcr.at(size - 1); - f_name = W1Util::concat_paths(mon_dr, f_name); - store = new StoreDay(f_name); - ret_val = store->get_newest_data(); - delete(store); - break; - } - } + year_name = year_name_vector_param.at(0); + ret_val = find_oldest_data(year_name); } return ret_val; } @@ -212,6 +237,47 @@ DataRange *DeviceData::get_summary(Date *date_param, return ret_val; } +DataRange *DeviceData::get_yearly_summary(Date *date, + EnumSummaryCalculationType calc_type_param) { + return get_summary(date, calc_type_param, PERIOD_YEARLY); +} + +DataRange *DeviceData::get_yearly_summary(Date *date) { + DataRange *ret_val; + + if (device_config == NULL) { + device_config = Factory::get_device_config(device_id); + summary_calc_type = device_config->get_summary_calculation_type(); + } + ret_val = get_yearly_summary(date, summary_calc_type); + return ret_val; +} + +DataRange *DeviceData::get_yearly_summary(Date *start_date, + Date *end_date) { + DataRange *ret_val; + DataRange *data; + Date *date; + + ret_val = NULL; + date = start_date->clone(); + while(date->before_or_equal_year(end_date)) { + data = get_yearly_summary(date); + if (data != NULL) { + if (ret_val == NULL) { + ret_val = new DataRange(data); + } + else { + ret_val->add(data); + } + delete(data); + } + date->next_year(); + } + delete(date); + return ret_val; +} + DataRange *DeviceData::get_monthly_summary(Date *date, EnumSummaryCalculationType calc_type_param) { return get_summary(date, calc_type_param, PERIOD_MONTHLY); @@ -220,6 +286,10 @@ DataRange *DeviceData::get_monthly_summary(Date *date, DataRange *DeviceData::get_monthly_summary(Date *date) { DataRange *ret_val; + if (device_config == NULL) { + device_config = Factory::get_device_config(device_id); + summary_calc_type = device_config->get_summary_calculation_type(); + } ret_val = get_monthly_summary(date, summary_calc_type); return ret_val; } @@ -257,6 +327,10 @@ DataRange *DeviceData::get_daily_summary(Date *date, DataRange *DeviceData::get_daily_summary(Date *date) { DataRange *ret_val; + if (device_config == NULL) { + device_config = Factory::get_device_config(device_id); + summary_calc_type = device_config->get_summary_calculation_type(); + } ret_val = get_daily_summary(date, summary_calc_type); return ret_val; } @@ -294,6 +368,10 @@ DataRange *DeviceData::get_hourly_summary(Date *date, DataRange *DeviceData::get_hourly_summary(Date *date) { DataRange *ret_val; + if (device_config == NULL) { + device_config = Factory::get_device_config(device_id); + summary_calc_type = device_config->get_summary_calculation_type(); + } ret_val = get_hourly_summary(date, summary_calc_type); return ret_val; } @@ -342,7 +420,7 @@ DataRange *DeviceData::get_data(Date *start_date, switch(period) { case PERIOD_YEARLY: log_debug("get yearly summary: %s - %s\n", start_date->to_string().c_str(), end_date->to_string().c_str()); - ret_val = get_monthly_summary(start_date, end_date); + ret_val = get_yearly_summary(start_date, end_date); break; case PERIOD_MONTHLY: log_debug("get monthly summary\n"); diff --git a/src/DeviceData.hh b/src/DeviceData.hh index 367e00f..a85bf14 100644 --- a/src/DeviceData.hh +++ b/src/DeviceData.hh @@ -17,30 +17,39 @@ #include -namespace w1 { +namespace plp { class DeviceData { public: DeviceData(std::string device_id); virtual ~DeviceData(); plp::DataRange *get_data_range(); - plp::DataRange *get_monthly_summary(plp::Date *date, EnumSummaryCalculationType calc_type); /** - * Get summary data calculated from the daily data items that is meaning full. + * Get monthly summary data. + * Depending from the device type, it may be daily mean value, daily delta, highest value, etc... + */ + plp::DataRange *get_yearly_summary(plp::Date *date, EnumSummaryCalculationType calc_type); + plp::DataRange *get_yearly_summary(plp::Date *date); + plp::DataRange *get_yearly_summary(plp::Date *start_date, plp::Date *end_date); + /** + * Get monthly summary data. * Depending from the device type, it may be daily mean value, daily delta, highest value, etc... */ + plp::DataRange *get_monthly_summary(plp::Date *date, EnumSummaryCalculationType calc_type); plp::DataRange *get_monthly_summary(plp::Date *date); plp::DataRange *get_monthly_summary(plp::Date *start_date, plp::Date *end_date); - plp::DataRange *get_daily_summary(plp::Date *date, EnumSummaryCalculationType calc_type); /** - * Get summary data calculated from the daily data items that is meaning full. + * Get daily summary data calculated from the daily data items. * Depending from the device type, it may be daily mean value, daily delta, highest value, etc... */ + plp::DataRange *get_daily_summary(plp::Date *date, EnumSummaryCalculationType calc_type); plp::DataRange *get_daily_summary(plp::Date *date); plp::DataRange *get_daily_summary(plp::Date *start_date, plp::Date *end_date); plp::DataRange *get_hourly_summary(plp::Date *date, EnumSummaryCalculationType calc_type); plp::DataRange *get_hourly_summary(plp::Date *date); plp::DataRange *get_hourly_summary(plp::Date *start_date, plp::Date *end_date); plp::DataRange *get_data(plp::Date *start_date, plp::Date *end_date); + plp::Data *find_newest_data(std::string year_name_param); + plp::Data *find_oldest_data(std::string year_name_param); protected: std::string device_id; std::string device_dir; diff --git a/src/Factory.cc b/src/Factory.cc index b10c3ea..76287eb 100644 --- a/src/Factory.cc +++ b/src/Factory.cc @@ -18,6 +18,7 @@ #include "W1Util.hh" using namespace w1; +using namespace plp; using namespace std; template diff --git a/src/Factory.hh b/src/Factory.hh index 415ce95..6e2beb2 100644 --- a/src/Factory.hh +++ b/src/Factory.hh @@ -27,7 +27,7 @@ namespace w1 { virtual ~Factory(); static W1Device *get_device(int family_code, std::string device_id, dirent *direntry_param); static std::list get_device_list(); - static std::list get_device_data_list(); + static std::list get_device_data_list(); static DeviceConfig *get_device_config(std::string device_id); private: //int parse_family_code(std::string folder_name); diff --git a/src/Store.cc b/src/Store.cc index 288f7f2..a33465d 100644 --- a/src/Store.cc +++ b/src/Store.cc @@ -72,8 +72,5 @@ bool Store::load(string fname_param) { log_error("Could not open data file: %s\n", fname_param.c_str()); } } - else { - log_warning("Could not open data file, file does not exist or user does not have read access for it: %s\n", fname_param.c_str()); - } return ret_val; } diff --git a/src/Store.hh b/src/Store.hh index 51252ad..02ce3a7 100644 --- a/src/Store.hh +++ b/src/Store.hh @@ -11,12 +11,18 @@ #include #include "Data.hh" #include "Date.hh" +#include "W1Configure.hh" namespace plp { class Store { public: Store(std::string device_id, plp::Date *date_time); virtual ~Store(); + virtual plp::DataRange *get_sum(EnumSummaryPeriod period_type_param) = 0; + virtual plp::DataRange *get_mean(EnumSummaryPeriod period_type_param) = 0; + virtual plp::DataRange *get_delta(EnumSummaryPeriod period_type_param) = 0; + virtual plp::DataRange *get_max(EnumSummaryPeriod period_type_param) = 0; + virtual plp::DataRange *get_min(EnumSummaryPeriod period_type_param) = 0; protected: std::string device_id; plp::Date *date; diff --git a/src/StoreCache.cc b/src/StoreCache.cc index 3fc9c4b..b444f32 100644 --- a/src/StoreCache.cc +++ b/src/StoreCache.cc @@ -10,6 +10,7 @@ #include "StoreCache.hh" #include "StoreDay.hh" #include "DeviceConfig.hh" +#include "DeviceData.hh" #include "W1Util.hh" using namespace std; @@ -17,7 +18,7 @@ using namespace plp; using namespace w1; StoreCache::StoreCache(string device_id_param, - Date *date_time_param): Store(device_id_param, date_time_param) { + Date *date_time_param): Store(device_id_param, date_time_param) { } StoreCache::~StoreCache() { @@ -84,7 +85,6 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) { DataRange *ret_val; Data *dta; string fname; - StoreDay *store; ret_val = NULL; fname = get_file_name(device_id, @@ -108,8 +108,8 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) { if (ret_val == NULL) { switch(period_type_param) { case PERIOD_YEARLY: - break; - case PERIOD_MONTHLY: { + case PERIOD_MONTHLY: + { Data *cur_data; Data *res_data; Date *cur_date; @@ -118,25 +118,37 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) { int cnt; int val_cnt; DataRange *dr; + Store *store; cur_date = date->clone(); max_date = date->clone(); - max_date->next_month(); + if (period_type_param == PERIOD_YEARLY) { + max_date->next_year(); + } + else { + max_date->next_month(); + } cur_data = NULL; res_data = NULL; cnt = 0; while(cur_date->before(max_date)) { - store = new StoreDay(device_id, cur_date); - dr = store->get_mean(PERIOD_DAILY); + if (period_type_param == PERIOD_YEARLY) { + store = new StoreCache(device_id, cur_date); + dr = store->get_mean(PERIOD_MONTHLY); + } + else { + store = new StoreDay(device_id, cur_date); + dr = store->get_mean(PERIOD_DAILY); + } if (dr != NULL) { cur_data = dr->get_first(); if (cur_data != NULL) { cnt++; if (res_data == NULL) { res_data = cur_data; + val_cnt = res_data->get_value_count(); } else { - val_cnt = res_data->get_value_count(); for (ii = 0; ii < val_cnt; ii++) { res_data->value_arr[ii] = res_data->value_arr[ii] + cur_data->value_arr[ii]; } @@ -146,7 +158,12 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) { delete(dr); } delete(store); - cur_date->next_day(); + if (period_type_param == PERIOD_YEARLY) { + cur_date->next_month(); + } + else { + cur_date->next_day(); + } } if ((res_data != NULL) && (cnt > 0)) { @@ -164,11 +181,14 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) { case PERIOD_DAILY: case PERIOD_HOURLY: case PERIOD_MINUTELY: - case PERIOD_SECONDLY: - store = new StoreDay(device_id, date); - ret_val = store->get_mean(period_type_param); - save(fname, ret_val, 4); - delete(store); + case PERIOD_SECONDLY: { + StoreDay *store; + + store = new StoreDay(device_id, date); + ret_val = store->get_mean(period_type_param); + save(fname, ret_val, 4); + delete(store); + } break; } } @@ -180,7 +200,7 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) { DataRange *ret_val; Data *dta; string fname; - StoreDay *store; + Store *store; ret_val = NULL; fname = get_file_name(device_id, @@ -204,7 +224,6 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) { if (ret_val == NULL) { switch(period_type_param) { case PERIOD_YEARLY: - break; case PERIOD_MONTHLY: { Data *cur_data; Data *res_data; @@ -217,13 +236,24 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) { cur_date = date->clone(); max_date = date->clone(); - max_date->next_month(); + if (period_type_param == PERIOD_YEARLY) { + max_date->next_year(); + } + else { + max_date->next_month(); + } cur_data = NULL; res_data = NULL; cnt = 0; while(cur_date->before(max_date)) { - store = new StoreDay(device_id, cur_date); - dr = store->get_sum(PERIOD_DAILY); + if (period_type_param == PERIOD_YEARLY) { + store = new StoreCache(device_id, cur_date); + dr = store->get_sum(PERIOD_MONTHLY); + } + else { + store = new StoreDay(device_id, cur_date); + dr = store->get_sum(PERIOD_DAILY); + } if (dr != NULL) { cur_data = dr->get_first(); if (cur_data != NULL) { @@ -242,7 +272,12 @@ DataRange *StoreCache::get_sum(EnumSummaryPeriod period_type_param) { delete(dr); } delete(store); - cur_date->next_day(); + if (period_type_param == PERIOD_YEARLY) { + cur_date->next_month(); + } + else { + cur_date->next_day(); + } } if ((res_data != NULL) && (cnt > 0)) { @@ -273,7 +308,7 @@ DataRange *StoreCache::get_delta(EnumSummaryPeriod period_type_param) { DataRange *ret_val; Data *dta; string fname; - StoreDay *store; + StoreDay *store; ret_val = NULL; fname = get_file_name(device_id, @@ -297,7 +332,31 @@ DataRange *StoreCache::get_delta(EnumSummaryPeriod period_type_param) { } if (ret_val == NULL) { switch(period_type_param) { - case PERIOD_YEARLY: + case PERIOD_YEARLY: { + Data *first_data; + Data *last_data; + int ii; + int cnt; + + first_data = get_year_oldest_data(); + if (first_data != NULL) { + last_data = get_year_newest_data(); + if (last_data != NULL) { + ret_val = new DataRange(); + cnt = last_data->get_value_count(); + for (ii = 0; ii < cnt; ii++) { + last_data->value_arr[ii] = last_data->value_arr[ii] - first_data->value_arr[ii]; + } + ret_val->add(last_data); + delete(last_data); + } + delete(first_data); + save(fname, ret_val, 4); + } + else { + log_error("Could not read first or last data item from device %s for year: %d", device_id.c_str(), date->year); + } + } break; case PERIOD_MONTHLY: { Data *first_data; @@ -308,7 +367,7 @@ DataRange *StoreCache::get_delta(EnumSummaryPeriod period_type_param) { int ii; int cnt; - cur_date = date->clone(); + cur_date = date->clone(); limit_date = date->clone(); limit_date->next_month(); first_data = NULL; @@ -372,7 +431,7 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) { DataRange *ret_val; Data *dta; string fname; - StoreDay *store; + Store *store; ret_val = NULL; fname = get_file_name(device_id, @@ -396,7 +455,6 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) { if (ret_val == NULL) { switch(period_type_param) { case PERIOD_YEARLY: - break; case PERIOD_MONTHLY: { Data *cur_data; Data *res_data; @@ -409,13 +467,24 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) { cur_date = date->clone(); max_date = date->clone(); - max_date->next_month(); + if (period_type_param == PERIOD_YEARLY) { + max_date->next_year(); + } + else { + max_date->next_month(); + } cur_data = NULL; res_data = NULL; cnt = 0; while(cur_date->before(max_date)) { - store = new StoreDay(device_id, cur_date); - dr = store->get_max(PERIOD_DAILY); + if (period_type_param == PERIOD_YEARLY) { + store = new StoreCache(device_id, cur_date); + dr = store->get_max(PERIOD_MONTHLY); + } + else { + store = new StoreDay(device_id, cur_date); + dr = store->get_max(PERIOD_DAILY); + } if (dr != NULL) { cur_data = dr->get_first(); if (cur_data != NULL) { @@ -444,7 +513,12 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) { delete(dr); } delete(store); - cur_date->next_day(); + if (period_type_param == PERIOD_YEARLY) { + cur_date->next_month(); + } + else { + cur_date->next_day(); + } } if ((res_data != NULL) && (cnt > 0)) { @@ -475,7 +549,7 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) { DataRange *ret_val; Data *dta; string fname; - StoreDay *store; + Store *store; ret_val = NULL; fname = get_file_name(device_id, @@ -499,7 +573,6 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) { if (ret_val == NULL) { switch(period_type_param) { case PERIOD_YEARLY: - break; case PERIOD_MONTHLY: { Data *cur_data; Data *res_data; @@ -512,13 +585,24 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) { cur_date = date->clone(); max_date = date->clone(); - max_date->next_month(); + if (period_type_param == PERIOD_YEARLY) { + max_date->next_year(); + } + else { + max_date->next_month(); + } cur_data = NULL; res_data = NULL; cnt = 0; while(cur_date->before(max_date)) { - store = new StoreDay(device_id, cur_date); - dr = store->get_min(PERIOD_DAILY); + if (period_type_param == PERIOD_YEARLY) { + store = new StoreCache(device_id, cur_date); + dr = store->get_min(PERIOD_MONTHLY); + } + else { + store = new StoreDay(device_id, cur_date); + dr = store->get_min(PERIOD_DAILY); + } if (dr != NULL) { cur_data = dr->get_first(); if (cur_data != NULL) { @@ -547,7 +631,12 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) { delete(dr); } delete(store); - cur_date->next_day(); + if (period_type_param == PERIOD_YEARLY) { + cur_date->next_month(); + } + else { + cur_date->next_day(); + } } if ((res_data != NULL) && (cnt > 0)) { @@ -582,7 +671,7 @@ void StoreCache::save(std::string fname_param, plp::DataRange *datarange_param, cnt = datarange_param->get_count(); ostream = NULL; - log_info("[%s] cacheing %d data values.\n", device_id.c_str(), cnt); + //log_info("[%s] cacheing %d data values.\n", device_id.c_str(), cnt); ostream = W1Util::open_for_writing(fname_param.c_str()); if ((ostream != NULL) && (ostream->is_open() == true)) { @@ -606,3 +695,37 @@ void StoreCache::save(std::string fname_param, plp::DataRange *datarange_param, delete(ostream); } } + +/** + * Find oldest data in certain year + */ +Data *StoreCache::get_year_oldest_data() { + Data *ret_val; + char buffer[30]; + DeviceData *dta_finder; + string str; + + dta_finder = new DeviceData(device_id); + snprintf(buffer, 30, "%d", date->year); + str.append(buffer); + ret_val = dta_finder->find_oldest_data(str); + delete(dta_finder); + return ret_val; +} + +/** + * Find newest data in certain year + */ +Data *StoreCache::get_year_newest_data() { + Data *ret_val; + char buffer[30]; + DeviceData *dta_finder; + string str; + + dta_finder = new DeviceData(device_id); + snprintf(buffer, 30, "%d", date->year); + str.append(buffer); + ret_val = dta_finder->find_newest_data(str); + delete(dta_finder); + return ret_val; +} diff --git a/src/StoreCache.hh b/src/StoreCache.hh index dadd6b2..fdf3fe0 100644 --- a/src/StoreCache.hh +++ b/src/StoreCache.hh @@ -28,6 +28,8 @@ namespace plp { plp::DataRange *get_max(EnumSummaryPeriod period_type_param); plp::DataRange *get_min(EnumSummaryPeriod period_type_param); protected: + plp::Data *get_year_oldest_data(); + plp::Data *get_year_newest_data(); static std::string get_dir_name(std::string device_id_param, Date *date_time_param, EnumSummaryPeriod period_type_param, diff --git a/src/StoreDay.cc b/src/StoreDay.cc index fb5c175..089f884 100644 --- a/src/StoreDay.cc +++ b/src/StoreDay.cc @@ -520,16 +520,16 @@ DataRange *StoreDay::get_oldest_and_newest_data(string fname_param) { if (store_data != NULL) { row_count = store_data->get_count(); if (row_count > 0) { - o_data = store_data->get(0); - n_data = store_data->get(row_count - 1); + o_data = store_data->get(0); + n_data = store_data->get(row_count - 1); } } else { if (range_data != NULL) { row_count = range_data->get_count(); if (row_count > 0) { - o_data = range_data->get(0); - n_data = range_data->get(row_count - 1); + o_data = range_data->get(0); + n_data = range_data->get(row_count - 1); } } else { -- 2.41.1