]> pilppa.org Git - libplp.git/blob - src/StoreDay.hh
Data read optimizations
[libplp.git] / src / StoreDay.hh
1 /*
2  * Store.hh
3  *
4  *  Created on: Oct 31, 2010
5  *      Author: lamikr
6  */
7
8 #ifndef W1STORE_HH_
9 #define W1STORE_HH_
10
11 #include <string>
12 #include <list>
13 #include <vector>
14
15 #include <stdbool.h>
16
17 #include "Data.hh"
18 #include "Date.hh"
19 #include "Store.hh"
20
21 namespace plp {
22         class StoreDay: public plp::Store {
23                 public:
24                         StoreDay(std::string device_id_param,
25                                 plp::Date *date_time_param);
26                         StoreDay(std::string file_name_param);
27                         virtual ~StoreDay();
28                         static void save(std::string device_id, std::list<plp::Data *> *data_list, int dec_precision);
29                         plp::DataRange *get_sum(EnumSummaryPeriod period_type_param);
30                         plp::DataRange *get_mean(EnumSummaryPeriod period_type_param);
31                         plp::DataRange *get_delta(EnumSummaryPeriod period_type_param);
32                         plp::DataRange *get_max(EnumSummaryPeriod period_type_param);
33                         plp::DataRange *get_min(EnumSummaryPeriod period_type_param);
34                         plp::Data *get_oldest_data();
35                         plp::Data *get_latest_data();
36                         plp::DataRange *get_oldest_and_latest_data();
37                         /*
38                          * Checks whether store file exist.
39                          */
40                         bool exist(bool writable);
41                         static bool exist(std::string dev_id,
42                                         plp::Date *date,
43                                         bool writable);
44                         static bool exist_in_month(string device_id,
45                                                 Date *date,
46                                                 bool writable);
47                         static bool exist_in_year(string device_id,
48                                                 Date *date,
49                                                 bool writable);
50                         static bool get_next_date_with_data(std::string device_id,
51                                                         plp::Date *next_date,
52                                                         plp::Date *max_date);
53                 protected:
54                         std::string     store_fname;
55                         bool load();
56                         plp::DataRange *get_max_or_min(EnumSummaryPeriod period_type_param, bool max);
57                         static std::string get_dir_name(std::string device_id,
58                                                         plp::Date *date_time_param);
59                         static std::string get_year_dir_name(std::string device_id,
60                                                         plp::Date *date_time_param);
61                         static std::string get_file_name(std::string device_id,
62                                                         plp::Date *date_time_param);
63                         plp::DataRange *get_oldest_and_latest_data(std::string fname_param);
64                         /**
65                          * Check whether the given file exist and has either read or write permissions.
66                          */
67                         static bool exist(std::string fname_param, bool writable);
68                         /**
69                          * Go through days in month to find out whether daily data file exist.
70                          *
71                          * If data is not found, false is returned and last scanned date is set to next_date.
72                          * If data is found true is returned and date is set to next_date.
73                          */
74                         static bool data_day_scan_days_in_month(string dev_id_param,
75                                                         Date *next_date,
76                                                         Date *max_date);
77                         /**
78                          * Go through month dir in year to find out first date with data
79                          * after the given date.
80                          *
81                          * If data is not found, false is returned and last scanned date is set to next_date.
82                          * If data is found true is returned and date is set to next_date.
83                          */
84                         static bool data_day_scan_month_in_year(string dev_id_param,
85                                                         Date *next_date,
86                                                         Date *max_date);
87                         /**
88                          * Go through year and month directories to find out first date with data
89                          * after the given date.
90                          *
91                          * If data is not found, false is returned and last scanned date is set to next_date.
92                          * If data is found true is returned and date is set to next_date.
93                          */
94                         static bool data_day_scan_years(string dev_id_param,
95                                                 Date *next_date,
96                                                 Date *max_date);
97         };
98 }
99
100 #endif /* W1STORE_HH_ */