#include <curl/curl.h>
#include <cjson/cJSON.h>
#include <math.h>
#include <time.h>
#include <libpq-fe.h>
#include <log.h>
#include "IBM_EIS/authenticate.h"
#include "transform.h"
#include "http.h"
#include "utils.h"
Go to the source code of this file.
|
| CURLcode | IBM_GetTimeseries (IBM_AuthHandle_TypeDef *auth_handle, IBM_TimeseriesReq_TypeDef *request, IBM_TimeseriesDataset_TypeDef *dataset, uint8_t alt_flag) |
| | Get timeseries data from IBM EMS. More...
|
| |
| int8_t | IBM_TimeseriesToCSV (IBM_TimeseriesReq_TypeDef *request, IBM_TimeseriesDataset_TypeDef *dataset) |
| | Write timeseries dataset to .csv file. More...
|
| |
| IBM_TimeseriesDataset_TypeDef | IBM_TimeseriesFromCSV (const char *filename) |
| | Load IBM timeseries dataset from local .csv file. More...
|
| |
| void | IBM_TimeseriesToDB (IBM_TimeseriesReq_TypeDef *req_info, IBM_TimeseriesDataset_TypeDef *dataset, T_LocationLookup_TypeDef *location, PGconn *psql_conn) |
| | Write timeseries dataset to PostgreSQL table. More...
|
| |
| void | IBM_BuildTSDatabase (T_LocationsLookup_TypeDef *locations, const char *start_time, const char *end_time, PGconn *psql_conn) |
| |
◆ IBM_MAX_RESPONSE_LENGTH
| #define IBM_MAX_RESPONSE_LENGTH 2000 |
Max number of values in response.
◆ IBM_MAX_TEMPERATURE_ID
| #define IBM_MAX_TEMPERATURE_ID 26018 |
◆ IBM_MIN_TEMPERATURE_ID
| #define IBM_MIN_TEMPERATURE_ID 26019 |
◆ IBM_PRECIPITATION_ID
| #define IBM_PRECIPITATION_ID 49097 |
Define layer identifier (daily precip, max temp, min temp)
◆ IBM_URL_SIZE
Max characters in formulated URL.
◆ IBM_BuildTSDatabase()
| void IBM_BuildTSDatabase |
( |
T_LocationsLookup_TypeDef * |
locations, |
|
|
const char * |
start_time, |
|
|
const char * |
end_time, |
|
|
PGconn * |
psql_conn |
|
) |
| |
◆ IBM_GetTimeseries()
Get timeseries data from IBM EMS.
IBM EIS get timeseries data as a JSON response.
IBM EIS provides two endpoints to get data from:
The responses from these requests have different formats therefore they need to be treated seperatly. Luckly similar data is used for each request making the use of TimeseriesReq_TypeDef possible for both requests.
TimeseriesReq_TypeDef ts = {
.layer_id = 16700,
.latitude = -35.69701049568654,
.longitude = 150.1546566614602,
.start = 1654005600,
.end = 1654783200
};
TimeseriesDataset_TypeDef dataset;
CURLcode IBM_GetTimeseries(IBM_AuthHandle_TypeDef *auth_handle, IBM_TimeseriesReq_TypeDef *request, IBM_TimeseriesDataset_TypeDef *dataset, uint8_t alt_flag)
Get timeseries data from IBM EMS.
Definition: timeseries.c:50
- Note
- Start and end times are represented as UNIX timestamps (in seconds).
- Parameters
-
| auth_handle | IBM authentication handler |
| request | Request struct with corresponding data. |
| dataset | The dataset to populate. |
| alt_flag | A flag representing if the alt enpoint should be used. |
- Returns
- Curl success code.
◆ IBM_TimeseriesFromCSV()
Load IBM timeseries dataset from local .csv file.
Load timeseries dataset from a cached .csv for .txt file.
Requires the file to be formatted as Unix;Date;Value
- Parameters
-
| filename | Filename of file to open, including path. |
- Returns
- Dataset containing timeseries data
◆ IBM_TimeseriesToCSV()
Write timeseries dataset to .csv file.
IBM timeseires dataset to csv.
Creates required directories and then builds a csv files with the downloaded dataset.
- Parameters
-
| request | Timeseries request information (layer ID is needed). |
| dataset | Dataset to write to file. Count is provided here too. |
- Returns
- Error code. 0 = OK ... 1 = ERROR
◆ IBM_TimeseriesToDB()
Write timeseries dataset to PostgreSQL table.
Insert an IBM dataset into a PostgreSQL table.
This function handles precipitation, min and max temperatures. Several other datasets are required to give context regarding the IBM datasets location and relevance.
- Parameters
-
| req_info | Request information provided to IBM. |
| dataset | Dataset to insert into table. |
| location | Location information from PostgreSQL lookup table. |
| psql_conn | PostgreSQL database connection handler. |
◆ IBM_ALT_REQUEST_URL
| const char* IBM_ALT_REQUEST_URL = "https://ibmpairs-mvp2-api.mybluemix.net" |
|
static |
◆ IBM_REQUEST_URL
| const char* IBM_REQUEST_URL = "https://pairs.res.ibm.com" |
|
static |