%% BOS 2018A Operational Requirements
% For the R2018A design, the system must expand to accommodate 8 total cameras, which will bring an opportunity to purchase a cable specifically suited to these new needs.

clear; close all; LastRun = datetime

%
%% Haul Rate Determinations
% The function requirements relative to the daily operations encompass a day must perform 10-15 drops per area of interest, and 5-10 areas per day.  Set A is more drops less sites and set b is more sites less drops.

clear; 
DropsPerSite = [10 15 3 4];
SitesPerDay  = [5  4 10 10];
DropDepth = 150;
LiftAltitude = 30; %distance lifted between drops
DistanceBtDrops = 100; %meters
DistanceBtSites = 2000; %meters
DropTransitSpeed = 2; %knots 
SiteTransitSpeed = 10; %knots
knotsTomm = 30.8667; %conversion for knots to meter/min
HaulRates =  30; %meters per minute
DropTimeOnBottom = 5; %min
TimeOnOffDeck = 10; %min

% Determine the total time spent in hauling:

TimeFullDrop  = DropDepth./HaulRates + TimeOnOffDeck; % min
TimeLift  = LiftAltitude./HaulRates; % min
NumLift   = SitesPerDay.*(DropsPerSite*2-2);
NumDrops  = SitesPerDay*2;
TimeInHauling = NumLift.*TimeLift + NumDrops.*TimeFullDrop;
TimeInHaulingHours = TimeInHauling./60

% Determine the total time spent on bottom:

TimeOnBottom = SitesPerDay.*DropsPerSite.*DropTimeOnBottom;
TimeOnBottomHours = TimeOnBottom ./60

% Determine the total time spent in transit:

SingleTransitBtDropTime = DistanceBtDrops/(DropTransitSpeed.*knotsTomm);
TimeInTransitBtDrops = ((DropsPerSite-1).*SingleTransitBtDropTime).*SitesPerDay;

SingleTransitBtSite = DistanceBtSites/(SiteTransitSpeed.*knotsTomm);
TimeInTransitBtSites = (SitesPerDay-1).*SingleTransitBtSite;

TimeInTransit = TimeInTransitBtDrops + TimeInTransitBtSites;
TimeInTransitHours = TimeInTransit./60

% Determine the total length of the operational day:

TotalTimeInOperation = TimeInHauling + TimeOnBottom + TimeInTransit;
TotalTimeInOperationHours = TotalTimeInOperation ./60

% What does that leave for transit to site in a typical day?

TotalDayHours = [12];
NonscienceTransitTime = TotalDayHours - TotalTimeInOperationHours

StrikingDistance = floor(NonscienceTransitTime .* SiteTransitSpeed/2) %nautical miles

%
% Plot the two scenarios

for (n = 1:length(DropsPerSite))
PlotData(n,:) = [
    TimeInHauling(n),...
    TimeOnBottom(n),...
    TimeInTransitBtDrops(n),...
    TimeInTransitBtSites(n)
    ]/(60);
lbl{n} = char(sprintf("%i drops, %i sites, %inm", DropsPerSite(n), SitesPerDay(n),StrikingDistance(n)));

end
Labels = {'Hauling','On Bottom','Transit b/t Drops','Transit b/t Sites'};

figure();
c = categorical(lbl);
bar(c,PlotData,'stacked');
ylabel('Time (hours)');
legend(Labels,'Location','northwest');
title([num2str(DropDepth) '-m Depth, ' num2str(DistanceBtDrops) '-m Drop Spacing, ' num2str(DistanceBtSites) '-m Site Spacing, ' num2str(HaulRates) '-m/min Haul Rate']);