libdballe  7.29
summary.h
1 #ifndef DBALLE_DB_SUMMARY_H
2 #define DBALLE_DB_SUMMARY_H
3 
4 #include <dballe/core/query.h>
5 #include <dballe/core/values.h>
6 #include <dballe/db/db.h>
7 #include <vector>
8 #include <set>
9 #include <functional>
10 
11 namespace dballe {
12 namespace db {
13 
14 class Matcher;
15 class Summary;
16 
17 namespace summary {
18 
20 enum Support
21 {
23  UNSUPPORTED = 0,
25  OVERESTIMATED = 1,
27  EXACT = 2,
28 };
29 
30 struct Entry
31 {
32  Station station;
33  dballe::Level level;
34  dballe::Trange trange;
35  wreport::Varcode varcode;
36  dballe::DatetimeRange dtrange;
37  int count = MISSING_INT;
38 
40 };
41 
42 }
43 
47 class Summary
48 {
49 protected:
50  // Query that generated this summary
51  core::Query query;
52 
53  // Summary of items for the currently active filter
54  std::vector<summary::Entry> entries;
55 
56  void aggregate(const summary::Entry& entry);
57 
58 public:
59  Summary(const dballe::Query& query);
60 
61  // True if the summary has been filled with data
62  bool valid = false;
63 
64  std::map<int, Station> all_stations;
65  std::set<std::string> all_reports;
66  std::set<dballe::Level> all_levels;
67  std::set<dballe::Trange> all_tranges;
68  std::set<wreport::Varcode> all_varcodes;
69 
70  // Last known datetime range for the data that we have
71  dballe::DatetimeRange dtrange;
72  // Last known count for the data that we have
73  unsigned count = MISSING_INT;
74 
76  bool is_valid() const { return valid; }
77 
78  const Datetime& datetime_min() const { return dtrange.min; }
79  const Datetime& datetime_max() const { return dtrange.max; }
80  unsigned data_count() const { return count; }
81 
86  summary::Support supports(const Query& query) const;
87 
91  void add_filtered(const Summary& summary);
92 
94  void add_summary(db::CursorSummary& cur);
95 
97  void add_entry(const summary::Entry& entry);
98 
100  bool iterate(std::function<bool(const summary::Entry&)> f) const;
101 };
102 
103 }
104 }
105 
106 #endif
Cursor iterating over summary entries.
Definition: db.h:146
Information about a station.
Definition: values.h:21
Definition: summary.h:30
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
bool is_valid() const
Return true if the summary has been filled with data.
Definition: summary.h:76
Standard dballe::Query implementation.
Definition: core/query.h:29
Vertical level or layer.
Definition: types.h:532
Functions used to connect to DB-All.e and insert, query and delete data.
void add_entry(const summary::Entry &entry)
Add a copy of an existing entry.
uint16_t Varcode
Range of datetimes.
Definition: types.h:272
Datetime max
Upper bound of the range.
Definition: types.h:277
bool iterate(std::function< bool(const summary::Entry &)> f) const
Iterate all values in the summary.
Datetime min
Lower bound of the range.
Definition: types.h:275
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:47
summary::Support supports(const Query &query) const
Checks if this summary correctly generate a summary for the given query.
Query used to filter DB-All.e data.
Definition: query.h:14
Date and time.
Definition: types.h:158
void add_summary(db::CursorSummary &cur)
Add an entry to the summary taken from the current status of cur.
Structures used as input to database insert functions.
void add_filtered(const Summary &summary)
Add entries from a summary, filtered with a query.