]> pilppa.org Git - lib1wire.git/blobdiff - src/StoreDay.cc
Added support for cacheing monthly data.
[lib1wire.git] / src / StoreDay.cc
index 8d35952f5a3321f60501172fdbdc40445f989b58..fb5c1757f3b8f20575b49d21478c3b494d29a832 100644 (file)
@@ -436,10 +436,12 @@ plp::DataRange *StoreDay::get_max_or_min(EnumSummaryPeriod period_type_param, bo
                                                        date    = data->get_date();
                                                        if ((ii <= (row_count -1)) &&
                                                            ((frq_sec == -1) || (date.before(limit_d)))) {
+                                                               int changed = 0;
                                                                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];
+                                                                                       changed = 1;
                                                                                }
                                                                        }
                                                                }
@@ -447,9 +449,16 @@ plp::DataRange *StoreDay::get_max_or_min(EnumSummaryPeriod period_type_param, bo
                                                                        for (jj = 0; jj < col_count; jj++) {
                                                                                if (data->value_arr[jj] < calc->value_arr[jj]) {
                                                                                        calc->value_arr[jj]     = data->value_arr[jj];
+                                                                                       changed = 1;
                                                                                }
                                                                        }
                                                                }
+                                                               if (changed == 1) {
+                                                                       Date new_date;
+
+                                                                       new_date        = data->get_date();
+                                                                       calc->set_date(&new_date);
+                                                               }
                                                        }
                                                        if ((ii >= (row_count -1)) ||
                                                            ((frq_sec != -1) && (date.before(limit_d) == false))) {
@@ -525,17 +534,19 @@ DataRange *StoreDay::get_oldest_and_newest_data(string fname_param) {
                }
                else {
                        in.open(fname_param.c_str());
-                       while (in.eof() == false) {
-                               getline(in, line);
-                               if (line.empty() == false) {
-                                       if (o_data == NULL) {
-                                               o_data  = Data::parse_string(line);
+                       if (in.is_open() == true) {
+                               while (in.eof() == false) {
+                                       getline(in, line);
+                                       if (line.empty() == false) {
+                                               if (o_data == NULL) {
+                                                       o_data  = Data::parse_string(line);
+                                               }
+                                               prev_line       = line;
                                        }
-                                       prev_line       = line;
                                }
-                       }
-                       if (prev_line.empty() == false) {
-                               n_data  = Data::parse_string(prev_line);
+                               if (prev_line.empty() == false) {
+                                       n_data  = Data::parse_string(prev_line);
+                               }
                        }
                }
        }