Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
Loading...
Searching...
No Matches
harvest_areas.h File Reference
#include <curl/curl.h>
#include <cjson/cJSON.h>
#include <time.h>
#include <libpq-fe.h>
#include <log.h>
#include "FoodAuthority/harvest_area.h"
#include "transform.h"
#include "http.h"
#include "utils.h"
#include "WillyWeather/location.h"
#include "BOM/stations.h"
Include dependency graph for harvest_areas.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FA_HarvestAreas_TypeDef
 Holds a list of oyster harvest areas (and their status) in NSW. More...
 

Macros

#define FA_DEFAULT_DIRECTORY   "datasets/nsw_food_authority"
 Harvest areas directory. More...
 
#define FA_DEFAULT_FILENAME   "datasets/nsw_food_authority/statuses.csv"
 Harvest area statuses filename. More...
 
#define FA_MAX_NUMBER_HARVEST_AREAS   120
 Maxiumum number of oyster harvest areas in response. More...
 

Functions

CURLcode FA_GetHarvestAreas (FA_HarvestAreas_TypeDef *harvest_areas)
 Get a list of oyster harvest areas in NSW Australia. More...
 
int8_t FA_HarvestAreasToCSV (FA_HarvestAreas_TypeDef *harvest_areas)
 Push harvest areas list into a .csv file. More...
 
void FA_HarvestAreasToDB (FA_HarvestAreas_TypeDef *harvest_areas, PGconn *psql_conn)
 Push harvest area statuses to DB. More...
 
void FA_CreateLocationsLookupDB (PGconn *psql_conn)
 Create unique harvest area locations lookup table in DB. More...
 
void FA_UniqueLocationsFromDB (T_LocationsLookup_TypeDef *locations, PGconn *psql_conn)
 Get Unique harvest area locations from DB. More...
 

Macro Definition Documentation

◆ FA_DEFAULT_DIRECTORY

#define FA_DEFAULT_DIRECTORY   "datasets/nsw_food_authority"

Harvest areas directory.

◆ FA_DEFAULT_FILENAME

#define FA_DEFAULT_FILENAME   "datasets/nsw_food_authority/statuses.csv"

Harvest area statuses filename.

◆ FA_MAX_NUMBER_HARVEST_AREAS

#define FA_MAX_NUMBER_HARVEST_AREAS   120

Maxiumum number of oyster harvest areas in response.

Function Documentation

◆ FA_CreateLocationsLookupDB()

void FA_CreateLocationsLookupDB ( PGconn *  psql_conn)

Create unique harvest area locations lookup table in DB.

Build a harvest area / locations lookup table in PostgreSQL database.

To make it easier to query datasources a lookup table is created using this function that matches a program name to the closest BOM weather station, Willy Weather location and other relevant information.

Note
This function requires that the harvest_area table is populated and there is an available bom weather station .txt file available.
Todo:
Improve this function to use the BOM table, rather than the .txt file
Parameters
psql_connPostgreSQL connection handler.

◆ FA_GetHarvestAreas()

CURLcode FA_GetHarvestAreas ( FA_HarvestAreas_TypeDef harvest_areas)

Get a list of oyster harvest areas in NSW Australia.

Request list of harvest areas (and status) from NSW Food Authority.

End product of this function is a list of harvest areas with their status (open, closed etc.).

Parameters
harvest_areasList of harvest areas to populate.
Returns
CURL error code.

◆ FA_HarvestAreasToCSV()

int8_t FA_HarvestAreasToCSV ( FA_HarvestAreas_TypeDef harvest_areas)

Push harvest areas list into a .csv file.

◆ FA_HarvestAreasToDB()

void FA_HarvestAreasToDB ( FA_HarvestAreas_TypeDef harvest_areas,
PGconn *  psql_conn 
)

Push harvest area statuses to DB.

Takes a list of harvest area statuses and passess them into a PSQL table.

The current time is taken to reference all values against. Ideally when querying these data the program should sort by the "time_processed" and this will provide a historical look at harvest area status at a particular site.

Parameters
harvest_areasBasically a list of harvest areas.
psql_connA connection handler for PostrgreSQL.

◆ FA_UniqueLocationsFromDB()

void FA_UniqueLocationsFromDB ( T_LocationsLookup_TypeDef locations,
PGconn *  psql_conn 
)

Get Unique harvest area locations from DB.

Load unique locations from lookup table in PostgreSQL database.

Load all the relevent locations from the lookup table (only 20 something locations to load).

Note
This requires the lookup table being populated.
Parameters
locationsLookup table locations from PostgreSQL table.
psql_connPostgreSQL database connection.