function [score, global_score] = MyMain(filePath)
% Funkce slouzi ke klasifikaci automaticke extrakce sinove aktivity pomoci
% Dice skore.
%
% vstup: cesta k ulozenym json souborum, slozka obsahuje take titles.mat s 
%        nazvy  jednotlivych soboru
%        
% výstup: score - bunkove pole, kde první sloupec je tvořen nazvy souboru a 
%                 poslední dice skore hodnocenim pro funkci automatickou 
%                 extrakci pomoci funkce Extraction, 2. az 5. sloupec
%                 obsahuje hodnoty TP, TN, FP, FN
%         global_score - vysledné hodnoceni Dice score
%
% funkce: Extraction - funkce pro predzpracovani dat a extrakci sinove
%                      aktivity jednoho objektu
%         GetScore - vypocita Dice skore jednoho objektu, na vystupu i
%                    hodnoty TP, TN, FP, FN
%
%% checking filepath
if ~isfolder( filePath )
    error('Error filePath.')
end

%% setting variables

load([filePath '\titles.mat']); % titles = titles of files in cell array 100x1
number_files = size(titles, 1);
score = cell(number_files, 6); %fisrt column - title, last column - score

chyba = 0;

for i = 1 : number_files
    %% loading 1 file
    title = titles{i, 1};
    file = jsondecode(fileread([ filePath '\' title ]));

    %% output of extraction
    output_model = Extraction(file);
    
    %% reference 
    output_reference = zeros(1, size(file.data(13).content , 1));
    atrial_onset = file.annotations(1).content; %starts od atrial activity
    atrial_offset = file.annotations(2).content; %ends of atrial activity
    
    for a = 1:length(atrial_onset)
        output_reference(atrial_onset(a, 1) : atrial_offset(a, 1)) = 1; %reference in binary vector
    end
    
    %% Dice score
    [TP, TN, FP, FN, similarity] = GetScore(output_model, output_reference);
    %similarity = dice(output_model, output_reference); %Dice score
    %cell array of title and score of extraction of each file
    score{i, 1} = title;
    score{i, 2} = TP;
    score{i, 3} = TN;
    score{i, 4} = FP;
    score{i, 5} = FN;
    score{i, 6} = similarity; 

end

%% final dice score
TP = sum([score{:, 2}]);
%TN = sum([score{:, 3}]);
FP = sum([score{:, 4}]);
FN = sum([score{:, 5}]);

global_score = 2 * TP / (2 * TP + FP + FN);
end