MeteoIODoc 20241221.207bde49
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
22#include <meteoio/IOInterface.h>
23
24#include <string>
25#include <vector>
26
27#ifdef _MSC_VER
28 #pragma warning(disable:4512) //we don't need any = operator!
29#endif
30
31namespace mio {
32
33class JsonWrapper; //forward declaration, it is defined in an include called in the .cc file
34
43class DBO : public IOInterface {
44 public:
45 DBO(const std::string& configfile);
46 DBO(const Config&);
47 DBO(const DBO&);
48 ~DBO();
49
50 DBO& operator=(const mio::DBO&);
51
52 virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
53 virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
54 std::vector< std::vector<MeteoData> >& vecMeteo);
55
56 private:
57 typedef struct ts_Meta {
58 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
59 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)
60 : 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) {}
61
62 std::string toString() const {
63 std::ostringstream os;
64 os << " " << id << " " << param_dbo << " [";
65 os << ((since.isUndef())? "-∞" : since.toString(Date::ISO)) << " - ";
66 os << ((until.isUndef())? "∞" : until.toString(Date::ISO)) << "] ";
67 os << agg_type << " - " << interval << " s - #" << sequence;
68 //os << " - x" << units_factor << " +" << units_offset;
69 return os.str();
70 }
71
72 Date since, until;
73 std::string param_dbo, parname, agg_type;
74 size_t id;
75 double units_factor, units_offset;
76 unsigned int interval, ts_offset, sequence;
77 } tsMeta;
78
79 typedef struct ts_Data {
80 ts_Data() : date(), val(IOUtils::nodata) {}
81 ts_Data(const Date& i_date, const double& i_val) : date(i_date), val(i_val){}
82
83 Date date;
84 double val;
85 } tsData;
86
87 void fillStationMeta();
88 void readData(const Date& dateStart, const Date& dateEnd, std::vector<MeteoData>& vecMeteo, const size_t& stationindex);
89 std::vector<DBO::tsMeta> getTsProperties() const;
90 std::vector<DBO::tsData> getTimeSerie(const size_t& tsID, const double& factor, const double& offset) const;
91 static void setUnitsConversion(DBO::tsMeta& ts);
92 std::string getParameter(const std::string& param_str, const std::string& agg_type) const;
93 void mergeTimeSeries(const MeteoData& md_pattern, const size_t& param, const std::vector<DBO::tsData>& vecData, std::vector<MeteoData>& vecMeteo) const;
94 void initDBOConnection(const Config& cfg);
95
96 std::vector<std::string> vecStationName;
97 std::vector<StationData> vecMeta;
98 std::vector< std::vector<DBO::tsMeta> > vecTsMeta;
99 std::string coordin, coordinparam;
100 std::string endpoint;
101 JsonWrapper *json;
102
103 bool dbo_debug;
104
105 static const int http_timeout_dflt;
106 static const std::string endpoint_default, metadata_api, data_api;
107};
108
109} //end namespace mio
110
111#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:43
virtual void readStationData(const Date &date, std::vector< StationData > &vecStation)
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)
Fill vecMeteo with a time series of objects corresponding to the interval indicated by dateStart and ...
Definition: DBO.cc:195
DBO(const std::string &configfile)
Definition: DBO.cc:125
DBO & operator=(const mio::DBO &)
Definition: DBO.cc:159
~DBO()
Definition: DBO.cc:154
A class to handle timestamps. This class handles conversion between different time display formats (I...
Definition: Date.h:87
@ ISO
ISO 8601 extended format combined date: YYYY-MM-DDTHH:mm:SS.sss (fields might be dropped,...
Definition: Date.h:91
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
const double nodata
This is the internal nodata value.
Definition: IOUtils.h:75
std::string toString(const T &t)
Definition: IOUtils.h:294
const unsigned int unodata
Definition: IOUtils.h:76
Definition: Config.cc:31