|
Oyster Harvest Area Closure Analysis 0.1
Prediction and analysis of NSW oyster harvest area closures.
|
#include <stdlib.h>#include <string.h>#include <curl/curl.h>#include <stdint.h>#include <cjson/cJSON.h>#include <sys/stat.h>#include <sys/types.h>#include <errno.h>#include <math.h>#include <log.h>#include <libpq-fe.h>Go to the source code of this file.
Data Structures | |
| struct | Utils_ReqData_TypeDef |
| Holds HTTP response data before converting these data into cJSON objects. More... | |
Macros | |
| #define | USER_AGENT "EnvMonitoring/0.1 (NSW Department of Primary Industries)" |
Functions | |
| size_t | WriteMemoryCallback (void *contents, size_t size, size_t nmemb, void *userp) |
| int8_t | MakeDirectory (const char *directory) |
| Make directories (with error handling) More... | |
| void | WriteTimeseriesToFile (const char *filename, time_t *dates, double *values, int16_t max_n_values) |
| Write timeseries data into a csv file. More... | |
| void | cJSON_Minify_Mod (char *json) |
| Modified minify function from cJSON. More... | |
| double | Utils_PointsDistance (double latitude, double longitude, double station_latitude, double station_longitude) |
| Distance between two points on earth. More... | |
| void | Utils_PrepareStatement (PGconn *psql_conn, const char *stmt_name, const char *stmt, const int nparams) |
| #define USER_AGENT "EnvMonitoring/0.1 (NSW Department of Primary Industries)" |
| void cJSON_Minify_Mod | ( | char * | json | ) |
Modified minify function from cJSON.
HTML minify function modified from cJSON library.
The main cJSON_Minify() function gets rid of all white space and '/' characters in a string. This however, causes sentances to appear without the nessessary spaces between words. This modified function keeps only one space between each character (if more than one space occurs) and maintains the spaces between words in a sentance. Additionally '/' characters are maintained as they are used as datetime delimiters.
| json | The string to minify (parse). |
| int8_t MakeDirectory | ( | const char * | directory | ) |
Make directories (with error handling)
Helper function to create directories with error handling.
| directory | Directory name you want to create. |
| double Utils_PointsDistance | ( | double | latitude, |
| double | longitude, | ||
| double | station_latitude, | ||
| double | station_longitude | ||
| ) |
Distance between two points on earth.
Uses haversine formula to calculate the distance in km between two points on earth.
Used to calculate the distance between an POI and the closest Bureau of Meterology station.
| latitude | Latitude of point of interest. |
| longitude | Longitude of point of interest. |
| station_latitude | Latitude of station. |
| station_longitude | Longitude of station. |
| void Utils_PrepareStatement | ( | PGconn * | psql_conn, |
| const char * | stmt_name, | ||
| const char * | stmt, | ||
| const int | nparams | ||
| ) |
| size_t WriteMemoryCallback | ( | void * | contents, |
| size_t | size, | ||
| size_t | nmemb, | ||
| void * | userp | ||
| ) |
Helper function to handle a CURL request response which normally gets written to stdout.
Callback function to save HTTP response data to a character array.
CURL defaults to printing to stdout. This function is added to CURL in the setup options (curl_easy_setupopt()). Memory is allocated and then filled with the response string. This character array is then used to create cJSON objects and other items.
| contents | The items to add. |
| size | The size of items to add. |
| nmemb | The number of members (data size). |
| userp | The struct to populate with data. |
| void WriteTimeseriesToFile | ( | const char * | filename, |
| time_t * | dates, | ||
| double * | values, | ||
| int16_t | max_n_values | ||
| ) |
Write timeseries data into a csv file.
Helper function to handle writing timeseries data to a .csv file.
Writes timeseries data to a filename, exiting when the data is un-initialised '\0' or the maxiumum buffer size is reached. This function also converts UNIX time into local (human readable) time in ISO 8601 format.
| filename | File to write to. |
| dates | Dates (x values). |
| values | Data values (y values). |
| max_n_values | Max buffer size. |