Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
timeseries.c File Reference
Include dependency graph for timeseries.c:

Functions

static void IBM_ParseTimeseries (cJSON *response, IBM_TimeseriesDataset_TypeDef *dataset)
 Parse timeseries response. More...
 
static void IBM_ParseTimeseriesAlt (cJSON *response, IBM_TimeseriesDataset_TypeDef *dataset)
 Parse timeseries response from alternative endpoint. More...
 
static void IBM_BuildURL (IBM_TimeseriesReq_TypeDef *req, char *url)
 Build IBM EIS request URL. More...
 
static void IBM_BuildURLAlt (IBM_TimeseriesReq_TypeDef *req, char *url)
 Build IBM EIS request URL for alternative endpoint. More...
 
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)
 

Function Documentation

◆ IBM_BuildTSDatabase()

void IBM_BuildTSDatabase ( T_LocationsLookup_TypeDef locations,
const char *  start_time,
const char *  end_time,
PGconn *  psql_conn 
)

◆ IBM_BuildURL()

static void IBM_BuildURL ( IBM_TimeseriesReq_TypeDef req,
char *  url 
)
static

Build IBM EIS request URL.

Build a URL for IBM EIS at endpoint https://pairs.res.ibm.com

Takes a request structure and formulates the appropriate URL.

Parameters
reqRequest information to populate URL with.
urlURL to modify.

◆ IBM_BuildURLAlt()

static void IBM_BuildURLAlt ( IBM_TimeseriesReq_TypeDef req,
char *  url 
)
static

Build IBM EIS request URL for alternative endpoint.

Build a URL for IBM EIS at endpoint https://ibmpairs-mvp2-api.mybluemix.net

Takes a request structure and formulates the appropriate URL.

Parameters
reqRequest information to populate URL with.
urlURL to modify.

◆ IBM_GetTimeseries()

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.

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, // 16700 (alt_flag = 0) or 49097 (alt_flag = 1)
.latitude = -35.69701049568654,
.longitude = 150.1546566614602,
.start = 1654005600,
.end = 1654783200
};
TimeseriesDataset_TypeDef dataset;
IBM_GetTimeseries(auth_handle, &ts, &dataset, 0); // or 1 (for alt URL)
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_handleIBM authentication handler
requestRequest struct with corresponding data.
datasetThe dataset to populate.
alt_flagA flag representing if the alt enpoint should be used.
Returns
Curl success code.

◆ IBM_ParseTimeseries()

static void IBM_ParseTimeseries ( cJSON *  response,
IBM_TimeseriesDataset_TypeDef dataset 
)
static

Parse timeseries response.

Parse timeseries data from IBM URL response.

This function takes JSON data received from the endpoint https://pairs.res.ibm.com (IBM_REQUEST_URL) to formulate a dataset (TimeseriesDataset_TypeDef).

Parameters
responseThe JSON to parse.
datasetThe dataset to populate.

◆ IBM_ParseTimeseriesAlt()

static void IBM_ParseTimeseriesAlt ( cJSON *  response,
IBM_TimeseriesDataset_TypeDef dataset 
)
static

Parse timeseries response from alternative endpoint.

Parse timeseries data from alternative IBM URL response.

This function takes JSON data received from the endpoint https://ibmpairs-mvp2-api.mybluemix.net (IBM_ALT_REQUEST_URL) to formulate a dataset (TimeseriesDataset_TypeDef).

Parameters
responseThe JSON to parse.
datasetThe dataset to populate.

◆ IBM_TimeseriesFromCSV()

IBM_TimeseriesDataset_TypeDef IBM_TimeseriesFromCSV ( const char *  filename)

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
filenameFilename of file to open, including path.
Returns
Dataset containing timeseries data

◆ IBM_TimeseriesToCSV()

int8_t IBM_TimeseriesToCSV ( IBM_TimeseriesReq_TypeDef request,
IBM_TimeseriesDataset_TypeDef dataset 
)

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
requestTimeseries request information (layer ID is needed).
datasetDataset to write to file. Count is provided here too.
Returns
Error code. 0 = OK ... 1 = ERROR

◆ IBM_TimeseriesToDB()

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.

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_infoRequest information provided to IBM.
datasetDataset to insert into table.
locationLocation information from PostgreSQL lookup table.
psql_connPostgreSQL database connection handler.