libdballe  7.21
summary.h
1 #ifndef DBALLE_DB_SUMMARY_H
2 #define DBALLE_DB_SUMMARY_H
3 
4 #include <dballe/core/query.h>
5 #include <dballe/db/db.h>
6 #include <vector>
7 #include <set>
8 
9 namespace dballe {
10 namespace db {
11 
12 class Matcher;
13 class Summary;
14 
15 namespace summary {
16 
18 enum Support
19 {
21  UNSUPPORTED = 0,
23  OVERESTIMATED = 1,
25  EXACT = 2,
26 };
27 
28 struct Entry
29 {
30  int ana_id;
31  std::string rep_memo;
32  dballe::Level level;
33  dballe::Trange trange;
34  wreport::Varcode varcode;
35  dballe::DatetimeRange dtrange;
36  int count = MISSING_INT;
37 
38  Entry(db::CursorSummary& cur, bool want_details);
39 };
40 
41 }
42 
46 class Summary
47 {
48 protected:
49  // Query that generated this summary
50  core::Query query;
51 
52  // Summary of items for the currently active filter
53  std::vector<summary::Entry> summary;
54 
55  void aggregate(const summary::Entry& entry);
56 
57 public:
58  Summary(const dballe::Query& query);
59 
60  // True if the summary has been filled with data
61  bool valid = false;
62 
63  std::set<int> all_stations;
64  std::set<std::string> all_reports;
65  std::set<dballe::Level> all_levels;
66  std::set<dballe::Trange> all_tranges;
67  std::set<wreport::Varcode> all_varcodes;
68 
69  // Last known datetime range for the data that we have
70  dballe::DatetimeRange dtrange;
71  // Last known count for the data that we have
72  unsigned count = MISSING_INT;
73 
75  bool is_valid() const { return valid; }
76 
77  const Datetime& datetime_min() const { return dtrange.min; }
78  const Datetime& datetime_max() const { return dtrange.max; }
79  unsigned data_count() const { return count; }
80 
85  summary::Support supports(const Query& query) const;
86 
88  void add_summary(db::CursorSummary& cur, bool with_details);
89 
91  void add_entry(const summary::Entry& entry);
92 
94  bool iterate(std::function<bool(const summary::Entry&)> f) const;
95 };
96 
97 namespace summary {
98 
117 class Stack
118 {
119 protected:
126  std::vector<Summary> summaries;
127 
128 public:
130  bool empty() const { return summaries.empty(); }
131 
133  unsigned size() const { return summaries.size(); }
134 
136  Summary& push(const Query& query);
137 
139  const Summary& top() const { return summaries.back(); }
140 
148  Support query(const Query& query, bool exact, std::function<bool(const Entry&)> match);
149 };
150 
151 }
152 
153 }
154 }
155 
156 #endif
Cursor iterating over summary entries.
Definition: db.h:136
const Summary & top() const
Return the topmost summary.
Definition: summary.h:139
bool is_valid() const
Return true if the summary has been filled with data.
Definition: summary.h:75
Definition: summary.h:28
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:587
Standard dballe::Query implementation.
Definition: core/query.h:29
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
unsigned size() const
Return the stack size. Only really useful for tests.
Definition: summary.h:133
bool empty() const
Check if the stack is empty.
Definition: summary.h:130
Vertical level or layer.
Definition: types.h:532
Functions used to connect to DB-All.e and insert, query and delete data.
uint16_t Varcode
Range of datetimes.
Definition: types.h:272
Datetime max
Upper bound of the range.
Definition: types.h:277
Stack of summary in increasing order of selectivity.
Definition: summary.h:117
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:46
Query used to filter DB-All.e data.
Definition: query.h:14
Date and time.
Definition: types.h:158
std::vector< Summary > summaries
Summaries for the current query.
Definition: summary.h:126