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

Functions

static int8_t FA_ParseListResponse (char *data, FA_HarvestAreas_TypeDef *harvest_areas)
 
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...
 

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_ParseListResponse()

static int8_t FA_ParseListResponse ( char *  data,
FA_HarvestAreas_TypeDef harvest_areas 
)
static

Takes a raw text XML input of all harvest areas across NSW from NSW Food Authority and converts the text into a list of harvest area objects.

NSW Food Authority provides data regarding harvest area status as a raw XML endpoint. First the string "-row" is identified as this divides the raw text into each individual harvest areas. Then the '-' in "-row" is replaced with a newline character. This results in each harvest area being put on seperate lines. These data are saved to a file and then read from the same file using fgets() to get results line by line. These lines are then passed individually to FA_ParseResponse() to construct FA_HarvestArea_TypeDef's.

Parameters
dataRaw XML text from NSW FA JSON request.
harvest_areasList of harvest areas.
Returns
Integer representing error or ok.

◆ 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.