1 #ifndef DBALLE_DB_SUMMARY_H 2 #define DBALLE_DB_SUMMARY_H 4 #include <dballe/core/fwd.h> 6 #include <dballe/core/query.h> 7 #include <dballe/core/smallset.h> 29 : level(level), trange(trange), varcode(varcode) {}
33 bool operator==(
const VarDesc& o)
const {
return std::tie(level, trange, varcode) == std::tie(o.level, o.trange, o.varcode); }
34 bool operator!=(
const VarDesc& o)
const {
return std::tie(level, trange, varcode) != std::tie(o.level, o.trange, o.varcode); }
35 bool operator< (
const VarDesc& o)
const {
return std::tie(level, trange, varcode) < std::tie(o.level, o.trange, o.varcode); }
36 bool operator<=(
const VarDesc& o)
const {
return std::tie(level, trange, varcode) <= std::tie(o.level, o.trange, o.varcode); }
37 bool operator> (
const VarDesc& o)
const {
return std::tie(level, trange, varcode) > std::tie(o.level, o.trange, o.varcode); }
38 bool operator>=(
const VarDesc& o)
const {
return std::tie(level, trange, varcode) >= std::tie(o.level, o.trange, o.varcode); }
54 : var(var), dtrange(dtrange), count(count)
60 bool operator==(
const VarEntry& o)
const {
return std::tie(var, dtrange, count) == std::tie(o.var, o.dtrange, o.count); }
61 bool operator!=(
const VarEntry& o)
const {
return std::tie(var, dtrange, count) != std::tie(o.var, o.dtrange, o.count); }
65 this->dtrange.
merge(dtrange);
72 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
76 inline const VarDesc& station_entry_get_value(
const VarEntry& item) {
return item.var; }
83 template<
typename Station>
86 using SmallSet::iterator;
87 using SmallSet::const_iterator;
88 using SmallSet::reverse_iterator;
89 using SmallSet::const_reverse_iterator;
90 using SmallSet::begin;
92 using SmallSet::rbegin;
95 using SmallSet::empty;
97 bool operator==(
const StationEntry& o)
const {
return SmallSet::operator==(o); }
98 bool operator!=(
const StationEntry& o)
const {
return SmallSet::operator!=(o); }
104 template<
typename OStation>
108 for (
const auto& item: entry)
115 add(vd, dtrange, count);
119 : station(entries.station)
121 add_filtered(entries, query);
127 template<
typename OStation>
134 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
138 template<
typename Station>
146 template<
typename Station>
150 typedef typename Parent::iterator iterator;
151 typedef typename Parent::const_iterator const_iterator;
152 typedef typename Parent::reverse_iterator reverse_iterator;
153 typedef typename Parent::const_reverse_iterator const_reverse_iterator;
156 using Parent::rbegin;
167 template<
typename OStation>
178 bool has(
const Station& station)
const {
return this->find(station) != this->end(); }
180 const StationEntries& sorted()
const {
if (this->dirty) this->rearrange_dirty();
return *
this; }
184 template<
typename Station>
192 : station_entry(station_entry), var_entry(var_entry) {}
194 std::vector<Entry> results;
195 typename std::vector<Entry>::const_iterator cur;
196 bool at_start =
true;
202 if (at_start)
return results.size();
203 return results.end() - cur;
210 cur = results.begin();
213 else if (cur != results.end())
215 return cur != results.end();
232 static int _get_station_id(
const DBStation& s) {
return s.
id; }
233 static int _get_station_id(
const dballe::Station& s) {
return MISSING_INT; }
237 return _get_dbstation(cur->station_entry.station);
241 int get_station_id()
const override 243 return _get_station_id(cur->station_entry.station);
246 Coords get_coords()
const override {
return cur->station_entry.station.coords; }
247 Ident get_ident()
const override {
return cur->station_entry.station.ident; }
248 std::string get_report()
const override {
return cur->station_entry.station.report; }
250 unsigned test_iterate(FILE* dump=0)
override 253 for (count = 0; next(); ++count)
267 size_t get_count()
const override {
return cur->var_entry.count; }
282 template<
typename Station>
294 mutable size_t count = 0;
296 mutable bool dirty =
false;
298 void recompute_summaries()
const;
309 return entries == o.entries;
325 const Datetime& datetime_max()
const {
if (dirty) recompute_summaries();
return dtrange.
max; }
326 unsigned data_count()
const {
if (dirty) recompute_summaries();
return count; }
338 std::unique_ptr<dballe::CursorSummary> query_summary(
const Query& query)
const;
350 void add_messages(
const std::vector<std::shared_ptr<dballe::Message>>& messages);
353 template<
typename OSummary>
366 void merge_entries();
375 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
const Datetime & datetime_min() const
Recompute reports, levels, tranges, and varcodes.
Definition: summary.h:324
Ident ident
Mobile station identifier.
Definition: types.h:799
Class passed to key-value accessors to set values in an invoker-defined way.
Definition: core/enq.h:17
Station information.
Definition: types.h:790
Level get_level() const override
Get the level.
Definition: summary.h:263
Description of a variable, independent of where and when it was measured.
Definition: summary.h:20
Information about a station, and statistics about its variables.
Definition: summary.h:84
Coords coords
Station coordinates.
Definition: types.h:796
Coordinates.
Definition: types.h:365
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:683
Functions used to connect to DB-All.e and insert, query and delete data.
Trange get_trange() const override
Get the time range.
Definition: summary.h:264
A bulletin that has been decoded and physically interpreted.
Definition: message.h:28
void add_summary(const BaseSummary< OSummary > &summary)
Merge the copy of another summary into this one.
Cursor iterating over summary entries.
Definition: cursor.h:84
Vertical level or layer.
Definition: types.h:621
A station identifier, that can be any string (including the empty string) or a missing value...
Definition: types.h:744
int remaining() const override
Get the number of rows still to be fetched.
Definition: summary.h:200
Range of datetimes.
Definition: types.h:291
Definition: summary.h:185
Set structure optimized for a small number of items.
Definition: smallset.h:16
Datetime max
Upper bound of the range.
Definition: types.h:296
std::string report
Report name for this station.
Definition: types.h:793
bool next() override
Get a new item from the results of a query.
Definition: summary.h:206
int id
Database ID of the station.
Definition: types.h:854
Definition: summary.h:187
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: summary.h:265
Datetime min
Lower bound of the range.
Definition: types.h:294
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:283
Statistics about a variable.
Definition: summary.h:44
Query used to filter DB-All.e data.
Definition: query.h:14
Date and time.
Definition: types.h:164
JSON serializer.
Definition: json.h:29
Cursor iterating over summary entries.
Definition: core/cursor.h:57
void discard() override
Discard the results that have not been read yet.
Definition: summary.h:218
void merge(const DatetimeRange &range)
Merge range into this one, resulting in the smallest range that contains both.
Index of all stations known to a summary.
Definition: summary.h:147
DBStation get_station() const override
Get the whole station data in a single call.
Definition: summary.h:235
DatetimeRange get_datetimerange() const override
Get the datetime range.
Definition: summary.h:266
size_t get_count() const override
Get the count of elements.
Definition: summary.h:267