MeteoIODoc 20250905.f67af007
 
Loading...
Searching...
No Matches
DBO.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later
2/***********************************************************************************/
3/* Copyright 2017 SLF */
4/***********************************************************************************/
5/* This file is part of MeteoIO.
6 MeteoIO is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 MeteoIO is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef DBO_H
20#define DBO_H
21
23#include <meteoio/IOInterface.h>
24
25#include <string>
26#include <vector>
27
28#ifdef _MSC_VER
29 #pragma warning(disable:4512) //we don't need any = operator!
30#endif
31
32namespace mio {
33
34class JsonWrapper; //forward declaration, it is defined in an include called in the .cc file
35
44class DBO : public IOInterface {
45 public:
46 DBO(const std::string& configfile);
47 DBO(const Config&);
48 DBO(const DBO&);
49 ~DBO() override;
50
51 DBO& operator=(const mio::DBO&);
52
53 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation) override;
54 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
55 std::vector< std::vector<MeteoData> >& vecMeteo) override;
56
57 private:
58 typedef struct ts_Meta {
59 ts_Meta() : since(), until(), param_dbo(), parname(), agg_type(), id(0), units_factor(1.), units_offset(0), interval(IOUtils::unodata), ts_offset(IOUtils::unodata), sequence(IOUtils::unodata) {} //required by std::map
60 ts_Meta(const std::string& i_param_str, const Date& i_since, const Date& i_until, const std::string& i_agg_type, const size_t i_id, const unsigned int& i_interval, const unsigned int& i_ts_offset, const unsigned int& i_sequence)
61 : since(i_since), until(i_until), param_dbo(i_param_str), parname(), agg_type(i_agg_type), id(i_id), units_factor(1.), units_offset(0), interval(i_interval), ts_offset(i_ts_offset), sequence(i_sequence) {}
62
63 std::string toString() const {
64 std::ostringstream os;
65 os << " " << id << " " << param_dbo << " -> " << parname << " [";
66 os << ((since.isUndef())? "-∞" : since.toString(Date::ISO)) << " - ";
67 os << ((until.isUndef())? "∞" : until.toString(Date::ISO)) << "] ";
68 os << agg_type << " - " << interval << " s - #" << sequence;
69 if (units_factor!=1. || units_offset!=0.) {
70 os << " -";
71 if (units_factor!=1.) os << " x" << units_factor;
72 if (units_offset!=0.) os << " +" << units_offset;
73 }
74 return os.str();
75 }
76
77 Date since, until;
78 std::string param_dbo, parname, agg_type;
79 size_t id;
80 double units_factor, units_offset;
81 unsigned int interval, ts_offset, sequence;
82 } tsMeta;
83
84 typedef struct ts_Data {
85 ts_Data() : date(), val(IOUtils::nodata) {}
86 ts_Data(const Date& i_date, const double& i_val) : date(i_date), val(i_val){}
87
88 Date date;
89 double val;
90 } tsData;
91
92 void fillStationMeta();
93 void readData(const Date& dateStart, const Date& dateEnd, std::vector<MeteoData>& vecMeteo, const size_t& stationindex);
94 std::vector<DBO::tsMeta> getTsProperties() const;
95 std::vector<DBO::tsData> getTimeSerie(const size_t& tsID, const double& factor, const double& offset) const;
96 static void setUnitsConversion(DBO::tsMeta& ts);
97 std::string getParameter(const std::string& param_str, const std::string& agg_type) const;
98 void mergeTimeSeries(const MeteoData& md_pattern, const size_t& param, const std::vector<DBO::tsData>& vecData, std::vector<MeteoData>& vecMeteo) const;
99 void initDBOConnection(const Config& cfg);
100
101 std::vector<std::string> vecStationName;
102 std::vector<StationData> vecMeta;
103 std::vector< std::vector<DBO::tsMeta> > vecTsMeta;
104 std::string coordin, coordinparam;
105 std::string endpoint;
106 DateRange coverageRestrict;
107 JsonWrapper *json;
108
109 bool dbo_debug;
110
111 static const int http_timeout_dflt;
112 static const std::string endpoint_default, metadata_api, data_api;
113};
114
115} //end namespace mio
116
117#endif
A class that reads a key/value file. These files (typically named *.ini) follow the INI file format s...
Definition Config.h:79
This class enables the access to the DBO RESTful web service.
Definition DBO.h:44
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation) override
Fill vecStation with StationData objects for a certain date of interest.
Definition DBO.cc:188
virtual void readMeteoData(const Date &dateStart, const Date &dateEnd, std::vector< std::vector< MeteoData > > &vecMeteo) override
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition DBO.cc:195
~DBO() override
Definition DBO.cc:149
DBO & operator=(const mio::DBO &)
Definition DBO.cc:154
A class to represent and handle date ranges. They can be sorted, checked for uniqueness and a date ca...
Definition Date.h:241
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition Date.h:87
A class representing the IO Layer of the software Alpine3D. For each type of IO (File,...
Definition IOInterface.h:98
This is a wrapper class around picoJson and Curl.
Definition JsonWrapper.h:75
A class to represent a singular measurement received from one station at a certain time (represented ...
Definition MeteoData.h:108
Definition Config.cc:34