WSL/SLF GitLab Repository

DBO.h 3.51 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/***********************************************************************************/
/*  Copyright 2017 SLF                                                                                                                                */
/***********************************************************************************/
/* This file is part of MeteoIO.
    MeteoIO is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    MeteoIO is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with MeteoIO.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DBO_H
#define DBO_H

#include <meteoio/IOInterface.h>

#include <string>
#include <vector>

#ifdef _MSC_VER
	#pragma warning(disable:4512) //we don't need any = operator!
#endif

namespace mio {

/**
 * @class DBO
 * @brief This class enables the access to the DBO RESTful web service
 *
 * @ingroup plugins
 * @date   2017-01-26
 */

class DBO : public IOInterface {
	public:
		DBO(const std::string& configfile);
		DBO(const DBO&);
		DBO(const Config&);

		virtual void readStationData(const Date& date, std::vector<StationData>& vecStation);
		virtual void readMeteoData(const Date& dateStart, const Date& dateEnd,
		                           std::vector< std::vector<MeteoData> >& vecMeteo);

Mathias Bavay's avatar
Mathias Bavay committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
		typedef struct ts_Meta {
			ts_Meta(const Date& i_since, const Date& i_until, const std::string& i_agg_type, const double& i_ts_id, const unsigned int& i_interval)
			                : since(i_since), until(i_until), agg_type(i_agg_type), ts_id(i_ts_id), interval(i_interval) {}

			std::string toString() {
				std::ostringstream os;
				os << ts_id << " [";
				if (since.isUndef()) os << " -∞ - "; else os << since.toString(Date::ISO) << " - ";
				if (until.isUndef()) os << " ∞] "; else os << until.toString(Date::ISO) << "] ";
				os << agg_type << " - " << interval << " s";
				return os.str();
			}

			Date since, until;
			std::string agg_type;
			double ts_id;
			unsigned int interval;
		} tsMeta;
68
	private:
69
		void fillStationMeta();
70
		void readData(const Date& dateStart, const Date& dateEnd, std::vector<MeteoData>& vecMeteo, const size_t& stationindex);
71
		void readTimeSerie(const unsigned int& ts_id, const Date& dateStart, const Date& dateEnd, const StationData& sd, std::vector<MeteoData>& vecMeteo);
72
73
74
75
76
77
78

		void initDBOConnection();
		static size_t data_write(void* buf, size_t size, size_t nmemb, void* userp);
		bool curl_read(const std::string& url, std::ostream& os);

		const Config cfg;
		std::vector<std::string> vecStationName;
79
		std::vector<StationData> vecMeta;
80
		std::vector< std::map<std::string, std::vector<DBO::tsMeta> > > vecTsMeta; ///< for every station, a map that contains for each parameter the relevant timeseries properties
81
		std::string coordin, coordinparam, coordout, coordoutparam; ///< projection parameters
82
		std::string endpoint; ///< Variables for endpoint configuration
83
84
85
86
87
		double default_timezone;
		int http_timeout; //time out for http connections
		bool dbo_debug;

		static const int http_timeout_dflt;
88
		static const std::string metadata_endpoint, data_endpoint, null_string;
89
90
91
92
93
};

} //end namespace mio

#endif