1 #ifndef DBALLE_DB_SUMMARY_UTILS_H 2 #define DBALLE_DB_SUMMARY_UTILS_H 4 #include <dballe/core/cursor.h> 5 #include <dballe/core/query.h> 6 #include <dballe/core/smallset.h> 7 #include <dballe/db/summary.h> 29 : var(var), dtrange(dtrange), count(count)
35 bool operator==(
const VarEntry& o)
const 37 return std::tie(var, dtrange, count) ==
38 std::tie(o.var, o.dtrange, o.count);
40 bool operator!=(
const VarEntry& o)
const 42 return std::tie(var, dtrange, count) !=
43 std::tie(o.var, o.dtrange, o.count);
48 this->dtrange.
merge(dtrange);
55 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
68 template <
typename Station>
70 :
protected core::SmallSet<VarEntry, VarDesc, station_entry_get_value>
73 using SmallSet::begin;
74 using SmallSet::const_iterator;
75 using SmallSet::const_reverse_iterator;
76 using SmallSet::empty;
78 using SmallSet::iterator;
79 using SmallSet::rbegin;
81 using SmallSet::reverse_iterator;
85 return SmallSet::operator==(o);
89 return SmallSet::operator!=(o);
96 template <
typename OStation>
100 for (
const auto& item : entry)
108 add(vd, dtrange, count);
112 : station(entries.station)
114 add_filtered(entries, query);
121 template <
typename OStation>
133 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
136 template <
typename Station>
148 template <
typename Station>
151 station_entries_get_value<Station>>
154 station_entries_get_value<Station>>
156 typedef typename Parent::iterator iterator;
157 typedef typename Parent::const_iterator const_iterator;
158 typedef typename Parent::reverse_iterator reverse_iterator;
159 typedef typename Parent::const_reverse_iterator const_reverse_iterator;
163 using Parent::rbegin;
168 return Parent::operator==(o);
172 return Parent::operator!=(o);
180 template <
typename OStation>
191 bool has(
const Station& station)
const 193 return this->find(station) != this->end();
199 this->rearrange_dirty();
221 template <
typename S1,
typename S2>
inline S1 convert_station(
const S2& s)
226 template <>
inline Station convert_station<Station, Station>(
const Station& s)
237 inline Station convert_station<Station, DBStation>(
const DBStation& station)
239 Station res(station);
244 inline DBStation convert_station<DBStation, Station>(
const Station& station)
247 res.report = station.report;
248 res.coords = station.coords;
249 res.ident = station.ident;
256 bool has_flt_rep_memo;
259 bool has_flt_station;
268 has_flt_rep_memo = !q.report.empty();
271 has_flt_station = has_flt_rep_memo || has_flt_area || has_flt_ident;
274 template <
typename Station>
bool matches_station(
const Station& station)
278 if (!q.latrange.
contains(station.coords.lat) ||
279 !q.lonrange.
contains(station.coords.lon))
283 if (has_flt_rep_memo && q.report != station.report)
286 if (has_flt_ident && q.ident != station.ident)
297 using StationFilterBase::StationFilterBase;
298 bool matches_station(
const Station& station)
300 return StationFilterBase::matches_station(station);
308 has_flt_station |= (q.ana_id != MISSING_INT);
311 bool matches_station(
const DBStation& station)
313 if (q.ana_id != MISSING_INT and station.id != q.ana_id)
315 return StationFilterBase::matches_station(station);
322 typename summary::StationEntries<Station>::const_iterator station_entry;
323 typename summary::StationEntry<Station>::const_iterator var_entry;
324 bool at_start =
true;
332 return !at_start && station_entry != results.end();
341 station_entry = results.begin();
342 if (station_entry != results.end())
343 var_entry = station_entry->begin();
346 else if (station_entry == results.end())
350 if (var_entry != station_entry->end())
352 if (var_entry == station_entry->end())
355 if (station_entry != results.end())
357 var_entry = station_entry->begin();
362 return station_entry != results.end();
365 void discard()
override { station_entry = results.end(); }
371 res.
report = station.report;
372 res.
coords = station.coords;
373 res.
ident = station.ident;
376 static int _get_station_id(
const DBStation& s) {
return s.
id; }
377 static int _get_station_id(
const dballe::Station& s) {
return MISSING_INT; }
381 return _get_dbstation(station_entry->station);
388 return var_entry->var.varcode;
392 return var_entry->dtrange;
394 size_t get_count()
const override {
return var_entry->count; }
Base class for cursors that iterate over DB query results.
Definition: cursor.h:15
Definition: summary_utils.h:253
Common base types used by most of DB-All.e code.
Ident ident
Mobile station identifier.
Definition: types.h:887
Class passed to key-value accessors to set values in an invoker-defined way.
Definition: core/enq.h:17
bool contains(int lat) const
Check if a point is inside this range (extremes included)
Station information.
Definition: types.h:878
bool is_missing() const
Check if the Ident is set to the missing value.
Level get_level() const override
Get the level.
Definition: summary_utils.h:384
Description of a variable, independent of where and when it was measured.
Definition: summary.h:17
bool is_missing() const
Return true if the LatRange matches any latitude.
Information about a station, and statistics about its variables.
Definition: summary_utils.h:69
Report report
Report name for this station.
Definition: types.h:881
Coords coords
Station coordinates.
Definition: types.h:884
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:688
Definition: summary_utils.h:304
Trange get_trange() const override
Get the time range.
Definition: summary_utils.h:385
Definition: summary_utils.h:293
Standard dballe::Query implementation.
Definition: core/query.h:35
void add(const Station &station, const VarDesc &vd, const dballe::DatetimeRange &dtrange, size_t count)
Merge the given entry.
static const Query & downcast(const dballe::Query &query)
Return a reference to query downcasted as core::Query.
Definition: summary_utils.h:295
bool contains(int lon) const
Check if a point is inside this range (extremes included)
Vertical level or layer.
Definition: types.h:624
bool is_missing() const
Return true if the LonRange matches any longitude.
int remaining() const override
Get the number of rows still to be fetched.
Definition: summary_utils.h:335
Range of datetimes.
Definition: types.h:296
Definition: summary_utils.h:319
Set structure optimized for a small number of items.
Definition: smallset.h:20
bool next() override
Get a new item from the results of a query.
Definition: summary_utils.h:337
int id
Database ID of the station.
Definition: types.h:946
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: summary_utils.h:386
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:70
Statistics about a variable.
Definition: summary_utils.h:18
JSON serializer.
Definition: json.h:29
Cursor iterating over summary entries.
Definition: core/cursor.h:72
void discard() override
Discard the results that have not been read yet.
Definition: summary_utils.h:365
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_utils.h:149
DBStation get_station() const override
Get the whole station data in a single call.
Definition: summary_utils.h:379
DatetimeRange get_datetimerange() const override
Get the datetime range.
Definition: summary_utils.h:390
Query used to filter DB-All.e data.
Definition: query.h:16
size_t get_count() const override
Get the count of elements.
Definition: summary_utils.h:394
bool has_value() const override
Check if the cursor points to a valid value.
Definition: summary_utils.h:330