%
% Copyright: bboom@inf.ed.ac.uk
%
% Script to retrieve fish counts from Fish4Knowledge website 
% 
% It retrieves the SQL data directly from the Fish4Knowledge website,
% but you can adapt the program to use lically stored CSV files
% 
% You need to set 
%   start_date_vector
%   end_date_vector 
%   site
%   camera
%   species
% as given in the example below.
% 
%     There are two plot options in the function species_extraction used below:
%     'day' - gives the daily plot of the 08:00 data;
%     '10min' - gives the full day plot
% 
% 
% The program then retrieves the data and plots a histogram of the count 
% of the selected species for the specified site and camer over the 
% given time range.
%


% date : year, month, day, hour, minutes, seconds
start_date_vector = [2011, 1, 1, 8, 0, 0];
start_date_str = datestr(start_date_vector);
end_date_vector = [2011, 2, 1, 8, 0, 0];
end_date_str = datestr(end_date_vector);

% site 'NPP-3' has camera 1,2,3,4 
% site 'LanYu' has camera 1,2
% site 'HoBiHu' has camera 1,2,3

site = 'NPP-3'
camera = 3;

% +------------+---------------------------+
% | species_id | name                      |
% +------------+---------------------------+
% |          1 | Dascyllus reticulatus     |
% |          2 | Chromis margaritifer      |
% |          3 | Plectroglyphidodon dickii |
% |          4 | Acanthurus nigrofuscus    |
% |          5 | Myripristis berndti       |
% |          6 | Chaetodon trifascialis    |
% |          7 | Zebrasoma scopas          |
% |          8 | Scolopsis bilineata       |
% |          9 | Amphiprion clarkii        |
% |         10 | Siganus fuscescens        |
% |         11 | Pomacentrus amboinensis   |
% |         34 | Pempheris vanicolensis    |
% |         33 | Neoniphon sammara         |
% |         31 | Chaetodon lunulatus       |
% |         24 | Hemigymnus fasciatus      |
% |         21 | Hemigymnus melapterus     |
% |         19 | Balistapus undulatus      |
% |         17 | Canthigaster valentini    |
% |         36 | Arothron hispidus         |
% |         27 | Lutjanus fulvus           |
% |         26 | Abudefduf vaigiensis      |
% |         13 | Calotomus zonarchus       |
% |         37 | Zanclus cornutus          |
% |         38 | Neoglyphidodon nigroris   |
% +------------+---------------------------+

species = 1;
 	
[fish_count valid_count] = species_extraction(site,camera,species,start_date_str,end_date_str,'day');

average_count = fish_count./valid_count;
average_count(valid_count == 0) = 0;

figure(1); 
bar(1:size(fish_count,2),average_count);
xlabel('days');
ylabel('counts');
title('Fish counts at 0800');

% date : year, month, day, hour, minutes, seconds
start_date_vector = [2011, 4, 22, 6, 0, 0];
start_date_str = datestr(start_date_vector);
end_date_vector = [2011, 4, 22, 18, 0, 0];
end_date_str = datestr(end_date_vector);

[fish_count valid_count] = species_extraction(site,camera,species,start_date_str,end_date_str,'10min');

average_count = fish_count./valid_count;
average_count(valid_count == 0) = 0;

figure(2);
bar((1:size(fish_count,2))*1/6,average_count);
xlabel('hours');
ylabel('counts');
title('Fish counts at 22 April 2011');

