/* ---------------------------------------------------	*/
/* src_creel/total_caught.h				*/
/* ---------------------------------------------------	*/
/* This is the header file for the Species Estimated    */
/* Total Caught Algorithm.				*/
/*							*/
/* Freely available software: see Appaserver.org	*/
/* ---------------------------------------------------	*/

#ifndef TOTAL_CAUGHT_H
#define TOTAL_CAUGHT_H

#include "list.h"
#include "dictionary.h"
#include "date.h"
#include "hash_table.h"

/* Enumerated Types */
/* ---------------- */
enum performed_census_weekend {	performed_census_saturday_only,
				performed_census_sunday_only,
				performed_census_saturday_and_sunday,
				missed_census_weekend };

/* Constants */
/* --------- */
#define WEEKENDS_TO_GO_BACK			3
#define BEGIN_DAY_GO_BACK			14.0
#define AREAS_1_5_COEFFICIENT			1.1307
#define AREAS_1_5_Y_INTERCEPT			26.478
#define AREA_6_COEFFICIENT			0.5593
#define AREA_6_Y_INTERCEPT			21.5574

#define DICTIONARY_KEY_DELIMITER		'|'

#define PARKING_LOT_FLORIDA_BAY			"florida_bay"
#define PARKING_LOT_WHITEWATER_BAY		"white_water_bay"

#define INTERVIEW_LOCATION_FLAMINGO		"flamingo"
#define INTERVIEW_LOCATION_EVERGLADES_CITY	"everglades_city"

/* Structures */
/* ---------- */
typedef struct
{
	char *family;
	char *genus;
	char *species_name;
	int florida_state_code;
} SPECIES;

typedef struct
{
	SPECIES *species;
	int kept;
	int released;
} CATCH;

typedef struct
{
	char *fishing_purpose;
	DATE *census_date;
	char *interview_location;
	int interview_number;
	int hours_fishing;
	int fishing_area_integer;
	LIST *catch_list;
} FISHING_TRIP;

typedef struct
{
	int begin_month;
	int end_month;
	int year;
	LIST *species_list;
	DICTIONARY *trailer_count_dictionary;
	HASH_TABLE *fishing_trip_hash_table;
	LIST *fishing_trip_list;
	DICTIONARY *weekend_creel_census_dictionary;
} ESTIMATED_TOTAL_CAUGHT_INPUT;

typedef struct
{
	int areas_1_5_sample_kept_saturday;
	int areas_1_5_sample_kept_sunday;
	int areas_1_5_sample_released_saturday;
	int areas_1_5_sample_released_sunday;
	int areas_1_6_sample_kept_saturday;
	int areas_1_6_sample_kept_sunday;
	int areas_1_6_sample_released_saturday;
	int areas_1_6_sample_released_sunday;
	int areas_1_5_sample_kept_weekend;
	int areas_1_6_sample_kept_weekend;
	int areas_1_5_sample_released_weekend;
	int areas_1_6_sample_released_weekend;
	double areas_1_5_sample_kept;
	double areas_1_5_sample_released;
	double areas_1_5_sample_caught;
	double areas_1_6_sample_kept;
	double areas_1_6_sample_released;
	double areas_1_6_sample_caught;
	double areas_1_5_estimated_total_kept;
	double areas_1_5_estimated_total_released;
	double areas_1_5_estimated_total_caught;
	double areas_1_6_estimated_total_kept;
	double areas_1_6_estimated_total_released;
	double areas_1_6_estimated_total_caught;
	SPECIES *species;
} CATCH_AREA;

typedef struct
{
	int florida_bay_trailer_count_saturday;
	int florida_bay_trailer_count_sunday;
	int whitewater_bay_trailer_count_saturday;
	int whitewater_bay_trailer_count_sunday;
	int florida_bay_trailer_count_day;
	int whitewater_bay_trailer_count_day;
	double average_daily_trailer_count_weekend;
	int total_trailer_count_weekend;
	int total_trailer_count_day;
	double areas_1_5_vessels;
	double area_6_vessels;
	double areas_1_6_vessels;
	double weekday_trailer_count_ratio_day;
} MONTH_ROW_VESSEL;

typedef struct
{
	int flamingo_fishing_trips_saturday;
	int flamingo_fishing_trips_sunday;
	int flamingo_pleasure_trips_saturday;
	int flamingo_pleasure_trips_sunday;
	int everglades_city_fishing_trips_saturday;
	int everglades_city_fishing_trips_sunday;
	int everglades_city_pleasure_trips_saturday;
	int everglades_city_pleasure_trips_sunday;
	double flamingo_fishing_trips_weekend;
	double flamingo_boating_trips_weekend;
	double park_fishing_trips_weekend;
	double park_boating_trips_weekend;
	double flamingo_fishing_trips_day;
	double flamingo_boating_trips_day;
	double park_fishing_trips_day;
	double park_boating_trips_day;
} MONTH_ROW_FISHING_TRIP;

typedef struct
{
	int day;
	MONTH_ROW_VESSEL vessel;
	MONTH_ROW_FISHING_TRIP fishing_trip;
	LIST *catch_area_list;
	enum performed_census_weekend performed_census_weekend;
} MONTH_ROW;

typedef struct
{
	int month;
	MONTH_ROW *total_row;
	LIST *row_list;
} MONTH_SHEET;

typedef struct
{
	char *month;
	int florida_bay_trailer_count_day;
	int whitewater_bay_trailer_count_day;
	int total_trailer_count_day;
	double areas_1_5_vessels;
	double area_6_vessels;
	double areas_1_6_vessels;
	double flamingo_fishing_trips_day;
	double flamingo_boating_trips_day;
	double park_fishing_trips_day;
	double park_boating_trips_day;
	LIST *catch_area_list;
} TOTAL_ROW;

typedef struct
{
	int year;
	LIST *total_row_list;
	TOTAL_ROW *total_row;
} TOTAL_SHEET;

typedef struct
{
	double grand_areas_1_5_total_kept;
	double grand_areas_1_5_total_released;
	double grand_areas_1_5_total_caught;
	double grand_areas_1_6_total_kept;
	double grand_areas_1_6_total_released;
	double grand_areas_1_6_total_caught;
	LIST *month_sheet_list;
	TOTAL_SHEET *total_sheet;
} ESTIMATED_TOTAL_CAUGHT_OUTPUT;

typedef struct
{
	ESTIMATED_TOTAL_CAUGHT_INPUT *input;
	ESTIMATED_TOTAL_CAUGHT_OUTPUT *output;
} ESTIMATED_TOTAL_CAUGHT;

/* Prototypes */
/* ---------- */
CATCH *total_caught_catch_new(	void );

SPECIES *total_caught_species_new(
				char *family,
				char *genus,
				char *species_name );

FISHING_TRIP *total_caught_fishing_trip_new(
				char *fishing_purpose,
				char *census_date_string,
				char *interview_location,
				int interview_number );


ESTIMATED_TOTAL_CAUGHT *estimated_total_caught_new(
				int begin_month,
				int end_month,
				int year,
				char *application_name );

ESTIMATED_TOTAL_CAUGHT_INPUT *total_caught_input_new(
				int begin_month,
				int end_month,
				int year,
				char *application_name );

DICTIONARY *total_caught_get_trailer_count_dictionary(
				char *application_name,
				int begin_month,
				int end_month,
				int year );

LIST *total_caught_get_species_list(
				char *application_name,
				char *family_list_string,
				char *genus_list_string,
				char *species_list_string );

HASH_TABLE *total_caught_get_fishing_trip_hash_table(
				LIST **fishing_trip_list,
				char *application_name,
				int begin_month,
				int end_month,
				int year );

char *total_caught_get_fishing_trip_key(
				char *fishing_purpose,
				char *census_date_string,
				char *interview_location,
				char *interview_number_string );

char *total_caught_get_species_key(
				char *family,
				char *genus,
				char *species_name );

void total_caught_populate_catch_list(
				HASH_TABLE *fishing_trip_hash_table,
				LIST *species_list,
				char *application_name,
				int begin_month,
				int end_month,
				int year );

ESTIMATED_TOTAL_CAUGHT_OUTPUT *total_caught_get_output(
				int begin_month,
				int end_month,
				int year,
				LIST *species_list,
				DICTIONARY *trailer_count_dictionary,
				LIST *fishing_trip_list,
				DICTIONARY *weekend_creel_census_dictionary );

void total_caught_get_begin_end_date_string(
				char *begin_date_string,
				char *end_date_string,
				int begin_month,
				int end_month,
				int year );

ESTIMATED_TOTAL_CAUGHT_OUTPUT *total_caught_output_new(
				void );

LIST *total_caught_get_month_sheet_list(
			int begin_month,
			int end_month,
			int year,
			DICTIONARY *trailer_count_dictionary,
			LIST *fishing_trip_list,
			LIST *species_list,
			DICTIONARY *weekend_creel_census_dictionary );

MONTH_SHEET *total_caught_get_month_sheet(
				int month,
				int year,
				DICTIONARY *trailer_count_dictionary,
				LIST *fishing_trip_list,
				LIST *species_list,
				DICTIONARY *weekend_creel_census_dictionary );

MONTH_SHEET *total_caught_month_sheet_new(
				int month );

MONTH_ROW *total_caught_month_row_new(
				int day );

MONTH_ROW *total_caught_get_month_row(
				int day,
				DATE *trailer_search_date,
				DATE *non_trailer_search_date,
				DICTIONARY *trailer_count_dictionary,
				LIST *fishing_trip_list,
				LIST *species_list,
				DICTIONARY *weekend_creel_census_dictionary );

int total_caught_get_fishing_trips_weekend(
				DATE *search_date,
				LIST *fishing_trip_list,
				boolean is_saturday,
				boolean is_fishing_trips,
				boolean is_flamingo );

char *total_caught_get_last_weekend_string(
				DATE *census_date,
				boolean is_saturday );

LIST *total_caught_get_catch_area_list(
			LIST *fishing_trip_list,
			DATE *search_date,
			LIST *species_list,
			double weekday_trailer_count_ratio_day,
			double flamingo_fishing_trips_day,
			double areas_1_5_estimated_total_fishing_vessels,
			double park_fishing_trips_day,
			double areas_1_6_estimated_total_fishing_vessels,
			enum performed_census_weekend performed_census_weekend);

CATCH_AREA *total_caught_catch_area_new(
				void );

void total_caught_set_catch_area(
				CATCH_AREA *catch_area,
				CATCH *catch,
				int area,
				int flamingo_fishing_trips_day,
				int flamingo_boating_trips_day,
				double areas_1_5_vessels,
				int park_fishing_trips_day,
				int park_boating_trips_day,
				double total_area_vessels );

SPECIES *total_caught_seek_species(
				LIST *species_list,
				char *family,
				char *genus,
				char *species_name );

CATCH *total_caught_get_or_set_fishing_trip_catch(
				LIST *catch_list,
				char *family,
				char *genus,
				char *species_name,
				SPECIES *species );

CATCH_AREA *total_caught_get_or_set_catch_area(
				LIST *catch_area_list,
				char *family,
				char *genus,
				char *species_name,
				SPECIES *species);

MONTH_ROW *total_caught_get_month_sheet_total_row(
				LIST *month_sheet_row_list );

void total_caught_get_month_row_fishing_trip_weekend(
			int *flamingo_fishing_trips_saturday,
			int *flamingo_fishing_trips_sunday,
			int *flamingo_pleasure_trips_saturday,
			int *flamingo_pleasure_trips_sunday,
			int *everglades_city_fishing_trips_saturday,
			int *everglades_city_fishing_trips_sunday,
			int *everglades_city_pleasure_trips_saturday,
			int *everglades_city_pleasure_trips_sunday,
			DATE *search_date,
			LIST *fishing_trip_list );

int total_caught_get_catches_weekend(
				DATE *search_date,
				LIST *fishing_trip_list,
				char *family,
				char *genus,
				char *species_name,
				boolean is_saturday,
				boolean is_areas_1_5,
				boolean is_kept );

TOTAL_SHEET *total_caught_get_total_sheet(
				LIST *month_sheet_list,
				int begin_month,
				int year );

TOTAL_SHEET *total_caught_total_sheet_new(
				int year );

TOTAL_ROW *total_caught_total_row_new(
				char *month );

TOTAL_ROW *total_caught_get_total_sheet_total_row(
				LIST *total_row_list );

void total_caught_populate_total_row(
				TOTAL_ROW *total_row,
				LIST *month_row_list );

void total_caught_populate_grand_totals(
				double *grand_areas_1_5_total_kept,
				double *grand_areas_1_5_total_released,
				double *grand_areas_1_5_total_caught,
				double *grand_areas_1_6_total_kept,
				double *grand_areas_1_6_total_released,
				double *grand_areas_1_6_total_caught,
				LIST *catch_area_list );

DICTIONARY *total_caught_get_weekend_creel_census_dictionary(
				char *application_name,
				int begin_month,
				int end_month,
				int year );

enum performed_census_weekend total_caught_get_performed_census_weekend(
				DATE *search_date,
				DICTIONARY *weekend_creel_census_dictionary );
#endif
