%% Load data.

close all; clear; clc
%-----------------------------------------------
% Specify the name of the COMPASS root directory
dataPath='/path/to/COMPASS/repository/';
%-----------------------------------------------
addpath(genpath([dataPath 'Scripts/']))

[~, txtData, allData]=xlsread([dataPath 'Data/COMPASS_SceneInfo.xlsx']); 
header=txtData(1,:);sceneInfo=cell2table(allData(2:end,:),'VariableNames',header);

%% Calculate the number of scenes in each category.

numScenes=size(sceneInfo,1);
valCat=unique(sceneInfo.Valence); 
arousCat=unique(sceneInfo.Arousal); 
socCat=unique(sceneInfo.SocialContent); 
ethnCat=unique(sceneInfo.Ethnicity); 
sexCat=unique(sceneInfo.Gender); 
faceCat=unique(sceneInfo.VisibleFaces); 
pplCat=unique(sceneInfo.PeopleNumber); 
animalCat=unique(sceneInfo.Animal); 
locationCat=unique(sceneInfo.Location); 
disasterCat=unique(sceneInfo.Disaster); 

for ii=1:numel(valCat)
    disp([valCat{ii} ' ' num2str(sum(strcmp(sceneInfo.Valence,valCat{ii})))])
end
disp(' ')

for ii=1:numel(arousCat)
    disp([arousCat{ii} ' ' num2str(sum(strcmp(sceneInfo.Arousal,arousCat{ii})))])
end
disp(' ')

for ii=1:numel(socCat)
    disp([socCat{ii} ' ' num2str(sum(strcmp(sceneInfo.SocialContent,socCat{ii})))])
end
disp(' ')

for ii=1:numel(socCat)
    for jj=1:numel(valCat)
        kk=sum(strcmp(sceneInfo.SocialContent,socCat{ii}) & strcmp(sceneInfo.Valence,valCat{jj}));
        disp([socCat{ii} ' ' valCat{jj} ' ' num2str(kk)])
    end
    disp(' ')
end

for ii=1:numel(arousCat)
    for jj=1:numel(valCat)
        kk=sum(strcmp(sceneInfo.Arousal,arousCat{ii}) & strcmp(sceneInfo.Valence,valCat{jj}));
        disp([arousCat{ii} ' ' valCat{jj} ' ' num2str(kk)])        
    end
    disp(' ')
end

for ii=1:numel(arousCat)
    for jj=1:numel(valCat)
        for hh=1:numel(socCat)
            kk=sum(strcmp(sceneInfo.Arousal,arousCat{ii}) & strcmp(sceneInfo.Valence,valCat{jj}) ...
                & strcmp(sceneInfo.SocialContent,socCat{hh}));
            disp([arousCat{ii} ' ' valCat{jj} ' ' socCat{hh} ' ' num2str(kk)])
        end
        disp(' ')
    end
end

numSocScenes=sum(strcmp(sceneInfo.SocialContent,'Social'));
fprintf('%s\n','Race/Ethnicity')
for jj=1:numel(ethnCat)
    kk=sum(strcmp(sceneInfo.Ethnicity,ethnCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',ethnCat{jj},kk,kk/numSocScenes*100)
end

fprintf('\n%s\n','Gender')
for jj=1:numel(sexCat)
    kk=sum(strcmp(sceneInfo.Gender,sexCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',sexCat{jj},kk,kk/numSocScenes*100)
end

fprintf('\n%s\n','Faces')
for jj=1:numel(faceCat)
    kk=sum(strcmp(sceneInfo.VisibleFaces,faceCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',faceCat{jj},kk,kk/numSocScenes*100)
end

fprintf('\n%s\n','Number of people in the scene')
for jj=1:numel(pplCat)
    kk=sum(strcmp(sceneInfo.PeopleNumber,pplCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',pplCat{jj},kk,kk/numSocScenes*100)
end

fprintf('\n%s\n','Animals')
for jj=1:numel(animalCat)
    kk=sum(strcmp(sceneInfo.Animal,animalCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',animalCat{jj},kk,kk/numScenes*100)
end

fprintf('\n%s\n','Location')
for jj=1:numel(locationCat)
    kk=sum(strcmp(sceneInfo.Location,locationCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',locationCat{jj},kk,kk/numScenes*100)
end

fprintf('\n%s\n','Disaster')
for jj=1:numel(disasterCat)
    kk=sum(strcmp(sceneInfo.Disaster,disasterCat{jj}));
    fprintf('%s n=%d (%.1f%%) \n',disasterCat{jj},kk,kk/numScenes*100)
end
