Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
historical_weather.h File Reference
#include <time.h>
#include <curl/curl.h>
#include <ctype.h>
#include <libpq-fe.h>
#include <stdint.h>
#include "transform.h"
#include "BOM/stations.h"
#include "ftp.h"
Include dependency graph for historical_weather.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BOM_WeatherDataset_TypeDef
 

Macros

#define BOM_RESPONSE_BUFFER_SIZE   200
 Max number of items in weather dataset. More...
 
#define BOM_TIME_STR_BUFFER_SIZE   30
 Max number of chars in timestamp buffer. More...
 
#define BOM_MAX_RESPONSE_SIZE   10000
 Max buffer size to read into memory (size of .csv file from BOM FTP server) More...
 

Functions

CURLcode BOM_GetWeather (BOM_WeatherDataset_TypeDef *dataset, BOM_WeatherStation_TypeDef *station, const char *year_month)
 Get historical weather for a particular BOM weather station. More...
 
int8_t BOM_LoadWeatherFromCSV (const char *filename, BOM_WeatherDataset_TypeDef *dataset, BOM_WeatherStation_TypeDef *station)
 Load BOM weather station dataset from .csv file. More...
 
void BOM_HistoricalWeatherToDB (BOM_WeatherStation_TypeDef *weather_station, BOM_WeatherDataset_TypeDef *dataset, PGconn *psql_conn)
 Write observed weather to PostgreSQL table (weather_bom) More...
 
void BOM_TimeseriesToDB (const char *start_time, PGconn *psql_conn)
 

Macro Definition Documentation

◆ BOM_MAX_RESPONSE_SIZE

#define BOM_MAX_RESPONSE_SIZE   10000

Max buffer size to read into memory (size of .csv file from BOM FTP server)

◆ BOM_RESPONSE_BUFFER_SIZE

#define BOM_RESPONSE_BUFFER_SIZE   200

Max number of items in weather dataset.

◆ BOM_TIME_STR_BUFFER_SIZE

#define BOM_TIME_STR_BUFFER_SIZE   30

Max number of chars in timestamp buffer.

Function Documentation

◆ BOM_GetWeather()

CURLcode BOM_GetWeather ( BOM_WeatherDataset_TypeDef dataset,
BOM_WeatherStation_TypeDef station,
const char *  year_month 
)

Get historical weather for a particular BOM weather station.

Get a file from the Bureau of Meterology FTP server.

The BOM provides formatted .csv files for certain locations in Australia. These .csv files can be downloaded from the BOM's FTP server. Currently, it is unknown when the data is updated (sometime daily).

See also
http://www.bom.gov.au/catalogue/anon-ftp.shtml
Parameters
datasetTimeseries dataset to populate with data.
filenameStation filename obtained from BOM_Stations_TypeDef.
year_monthYear and month of interest e.g. 202206 for 2022 06 (June)
Returns
Returns cURL status code.

◆ BOM_HistoricalWeatherToDB()

void BOM_HistoricalWeatherToDB ( BOM_WeatherStation_TypeDef weather_station,
BOM_WeatherDataset_TypeDef dataset,
PGconn *  psql_conn 
)

Write observed weather to PostgreSQL table (weather_bom)

Turn a weather station dataset from the BOM into database values.

Rows that already exist are overwritten, new rows are added. Need to ensure each dataset and weather station are from the same source. These data are inserted into the weather_bom PostgreSQL table.

Parameters
weather_stationBOM weather station information.
datasetBOM weather station dataset.
psql_connPostgreSQL connection handler.

◆ BOM_LoadWeatherFromCSV()

int8_t BOM_LoadWeatherFromCSV ( const char *  filename,
BOM_WeatherDataset_TypeDef dataset,
BOM_WeatherStation_TypeDef station 
)

Load BOM weather station dataset from .csv file.

Load a BOM dataset from a cached .csv file.

Parameters
filenameFile to load (includes path).
datasetDataset to populate.
Returns
Status code.

◆ BOM_TimeseriesToDB()

void BOM_TimeseriesToDB ( const char *  start_time,
PGconn *  psql_conn 
)