% ONRmeeting_prep_stats.m

clear all;

workd='~/Documents/MATLAB/MBARI/mat/';
fname=which('ONRmeeting_prep_stats.m');

% year of interest
yr=2010:2014;


% filter by log
for n=1:length(yr)
    % load
    load([workd num2str(yr(n)) '-int-CRITICAL.mat']);
    clear compFiltMission pathFiltMission pathFiltLog mpath logCount...
        missionCount compCount
    
    % reduce log path to mission path
    for j=1:length(pathFilt)
        
        m = pathFilt{j};
        mpath{j,1} = m(1:end-21);
        
    end; clear j m;
    
    % eliminate redundant messages from same mission path
    c=1; neo=1;
    while c<=size(compFilt,1)
        
        ind = find(ismember(mpath,char(mpath(c))));
        [u, ui]   = unique(compFilt(ind,1));
        
        % concatenate
        compFiltMission(neo:neo+size(u,1)-1,:) = [u compFilt(ind(ui),2:end)];
        pathFiltMission(neo:neo+size(u,1)-1,:) = mpath(ind(ui));
        pathFiltLog(neo:neo+size(u,1)-1,:)     = pathFilt(ind(ui));
        neo = neo+size(u,1);
        % skip to next folder
        c = max(ind)+1;
    end; clear c neo ind u ui;
    
    % count critical fault per log
    logCount = unique(pathFiltLog(:,1));
    for c=1:length(logCount)
        logCount{c,2} = sum(strcmp(logCount(c,1),pathFiltLog(:,1)));
    end; clear c;
    
    % count critical fault per mission
    missionCount = unique(pathFiltMission(:,1));
    for c=1:length(missionCount)
        missionCount{c,2} = sum(strcmp(missionCount(c,1),pathFiltMission(:,1)));
    end; clear c;
    
    % count critical fault per componant
    compCount = unique(compFiltMission(:,1));
    for c=1:length(compCount)
        compCount{c,2} = sum(strcmp(compCount(c,1),compFiltMission(:,1)));
    end; clear c;

    % save
    %
    save([workd num2str(yr(n)) '-int-CRITICAL.mat'],...
        'cName','impLog','timeLog','path','comp','compHeader',...
        'timeFilt','compFilt','pathFilt','compFiltMission','missionCount',...
        'compCount');
    %}
end;
