1 #ifndef DBALLE_DB_SUMMARY_UTILS_H 2 #define DBALLE_DB_SUMMARY_UTILS_H 4 #include <dballe/core/smallset.h> 5 #include <dballe/core/query.h> 6 #include <dballe/core/cursor.h> 7 #include <dballe/db/summary.h> 28 : var(var), dtrange(dtrange), count(count)
34 bool operator==(
const VarEntry& o)
const {
return std::tie(var, dtrange, count) == std::tie(o.var, o.dtrange, o.count); }
35 bool operator!=(
const VarEntry& o)
const {
return std::tie(var, dtrange, count) != std::tie(o.var, o.dtrange, o.count); }
39 this->dtrange.
merge(dtrange);
46 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
50 inline const VarDesc& station_entry_get_value(
const VarEntry& item) {
return item.var; }
57 template<
typename Station>
60 using SmallSet::iterator;
61 using SmallSet::const_iterator;
62 using SmallSet::reverse_iterator;
63 using SmallSet::const_reverse_iterator;
64 using SmallSet::begin;
66 using SmallSet::rbegin;
69 using SmallSet::empty;
71 bool operator==(
const StationEntry& o)
const {
return SmallSet::operator==(o); }
72 bool operator!=(
const StationEntry& o)
const {
return SmallSet::operator!=(o); }
78 template<
typename OStation>
82 for (
const auto& item: entry)
89 add(vd, dtrange, count);
93 : station(entries.station)
95 add_filtered(entries, query);
101 template<
typename OStation>
109 DBALLE_TEST_ONLY
void dump(FILE* out)
const;
113 template<
typename Station>
121 template<
typename Station>
125 typedef typename Parent::iterator iterator;
126 typedef typename Parent::const_iterator const_iterator;
127 typedef typename Parent::reverse_iterator reverse_iterator;
128 typedef typename Parent::const_reverse_iterator const_reverse_iterator;
131 using Parent::rbegin;
142 template<
typename OStation>
153 bool has(
const Station& station)
const {
return this->find(station) != this->end(); }
155 const StationEntries& sorted()
const {
if (this->dirty) this->rearrange_dirty();
return *
this; }
171 template<
typename S1,
typename S2>
172 inline S1 convert_station(
const S2& s)
177 template<>
inline Station convert_station<Station, Station>(
const Station& s) {
return s; }
178 template<>
inline DBStation convert_station<DBStation, DBStation>(
const DBStation& s) {
return s; }
181 inline Station convert_station<Station, DBStation>(
const DBStation& station)
183 Station res(station);
188 inline DBStation convert_station<DBStation, Station>(
const Station& station)
191 res.report = station.report;
192 res.coords = station.coords;
193 res.ident = station.ident;
201 bool has_flt_rep_memo;
204 bool has_flt_station;
212 has_flt_rep_memo = !q.report.empty();
215 has_flt_station = has_flt_rep_memo || has_flt_area || has_flt_ident;
218 template<
typename Station>
219 bool matches_station(
const Station& station)
223 if (!q.latrange.
contains(station.coords.lat) ||
224 !q.lonrange.
contains(station.coords.lon))
228 if (has_flt_rep_memo && q.report != station.report)
231 if (has_flt_ident && q.ident != station.ident)
238 template<
class Station>
244 using StationFilterBase::StationFilterBase;
245 bool matches_station(
const Station& station)
247 return StationFilterBase::matches_station(station);
257 has_flt_station |= (q.ana_id != MISSING_INT);
260 bool matches_station(
const DBStation& station)
262 if (q.ana_id != MISSING_INT and station.id != q.ana_id)
264 return StationFilterBase::matches_station(station);
268 template<
typename Station>
272 typename summary::StationEntries<Station>::const_iterator station_entry;
273 typename summary::StationEntry<Station>::const_iterator var_entry;
274 bool at_start =
true;
280 bool has_value()
const override {
return !at_start && station_entry != results.end(); }
291 station_entry = results.begin();
292 if (station_entry != results.end())
293 var_entry = station_entry->begin();
295 }
else if (station_entry == results.end())
298 if (var_entry != station_entry->end())
300 if (var_entry == station_entry->end())
303 if (station_entry != results.end())
305 var_entry = station_entry->begin();
310 return station_entry != results.end();
315 station_entry = results.end();
322 res.
report = station.report;
323 res.
coords = station.coords;
324 res.
ident = station.ident;
327 static int _get_station_id(
const DBStation& s) {
return s.
id; }
328 static int _get_station_id(
const dballe::Station& s) {
return MISSING_INT; }
332 return _get_dbstation(station_entry->station);
339 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:198
Common base types used by most of DB-All.e code.
Ident ident
Mobile station identifier.
Definition: types.h:802
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:793
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:335
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:58
Coords coords
Station coordinates.
Definition: types.h:799
Information on how a value has been sampled or computed with regards to time.
Definition: types.h:686
Definition: summary_utils.h:252
Trange get_trange() const override
Get the time range.
Definition: summary_utils.h:336
Definition: summary_utils.h:239
Standard dballe::Query implementation.
Definition: core/query.h:34
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:242
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:282
Range of datetimes.
Definition: types.h:294
Definition: summary_utils.h:269
Set structure optimized for a small number of items.
Definition: smallset.h:16
std::string report
Report name for this station.
Definition: types.h:796
bool next() override
Get a new item from the results of a query.
Definition: summary_utils.h:287
int id
Database ID of the station.
Definition: types.h:857
wreport::Varcode get_varcode() const override
Get the variable code.
Definition: summary_utils.h:337
High level objects for working with DB-All.e DB summaries.
Definition: summary.h:44
Statistics about a variable.
Definition: summary_utils.h:18
JSON serializer.
Definition: json.h:29
Cursor iterating over summary entries.
Definition: core/cursor.h:66
void discard() override
Discard the results that have not been read yet.
Definition: summary_utils.h:313
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:122
DBStation get_station() const override
Get the whole station data in a single call.
Definition: summary_utils.h:330
DatetimeRange get_datetimerange() const override
Get the datetime range.
Definition: summary_utils.h:338
Query used to filter DB-All.e data.
Definition: query.h:14
size_t get_count() const override
Get the count of elements.
Definition: summary_utils.h:339
bool has_value() const override
Check if the cursor points to a valid value.
Definition: summary_utils.h:280