clear;
clc;

%affinity calculation types
% affinity_calculation_shortest_path = 0;
% affinity_calculation_euclid = 1;
% affinity_calculation_common_friends = 2;
% affinity_calculation_random_clustering = 3;
% affinity_calculation_adamic_adar = 4;
% affinity_calculation_katz_beta_0_5 = 5;
% affinity_calculation_katz_beta_0_05 = 6;
% affinity_calculation_katz_beta_0_005 = 7;

affinities = 3; %%[2,3,4,6]; %3,4]; %,6]; 
num_missing_nodes_arr = 11; %%[11 21 31 41 50]; %%5:5:30; %10:10:50; %%[11 21 31 41 50]; %10:10:50;
percentKnownPHsVec = 1;

datasetDir = 'D:/SocialNets/Steam/Results_Test/FF75_50Att/' ;   
results_dir = strcat(datasetDir,'GED_25w3/test/');
filePrefix = 'Steam_*';
netSizes = 1000; %%[2048];
runAlgFlag = 1;
debugFlag = 0;
dumpFlag = 0;
numThreshold = 0;
maxAttStat = 0.25; % use this attribute only if it appears less than this percentage
numAttrCols = 50;
attSelected = ones(1,numAttrCols);
%selectedAttr(1) = 0; %skip country
attWeight = 0.3;

%skip all games
for gm=2:1:11
    selectedAttr(1) = 0;
end
    

date_now = clock;
date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)),'_', num2str(date_now(4)), num2str(date_now(5)),'_', num2str(date_now(6)));
LogMsg(sprintf('%s Strating CheckProperties ...',date_now));

for nodes = netSizes

    prefix = sprintf('%s%s%d_%s',datasetDir,filePrefix,nodes,'*.mat');
    files = dir(prefix);
    firstIter = 1;

    for iter = 1 %1:2 %100         % loop over same network with different missing nodes

        for i = 1:size(files,1)     % loop over the list of networks

            file = files(i).name;

            attFile = strrep(file, '.txt.mat', '.usr.txt');
            [attributes, attUpperRange, attSelected, attStat] = PrepareAttributes2(datasetDir, attFile, nodes, numAttrCols, maxAttStat, attSelected);
            
           if runAlgFlag == 1
                date_now = clock;
                date_now = strcat(num2str(date_now(1)),'_',num2str(date_now(2)),'_', num2str(date_now(3)),'_', num2str(date_now(4)), num2str(date_now(5)),'_', num2str(date_now(6)));

                % make sure dump & results directories exist
                if (firstIter == 1 && i == 1)
                    firstIter = 0;
                    if isdir(results_dir) == 0
                        mkdir(results_dir);
                    end
                    dump_data_dir = sprintf('%sdumpPropertiesData_%s/', results_dir, date_now);
                    if isdir(dump_data_dir) == 0
                        mkdir(dump_data_dir)
                    end
                end

                fprintf('reading network information from file %s%s ...\n', datasetDir, file);
                load(strcat(datasetDir, file), 'data');
                % pre process attributes (translate to binary attributes) 
                [attData, totalAttNum] = PreProcessDataAttributes(data, attributes, attUpperRange);
                % Calc Attributes Affinity - similarity score 
                fprintf('calculating attribtes affinity matrix...\n');
                [attAffinity] = CalcAttributesAffinity(attData, nodes, 0, 0); 

                % save Attributes Affinity
                fileSuffix = strrep(file, '.txt.mat', '');
                out_file = sprintf('%sPropertiesData40_%s', dump_data_dir, fileSuffix);
                SavePropertiesData(out_file, data, attAffinity);

                %LogMsg(sprintf('Results for file %s,iter %d at %s',file,iter,out_file));
                %fprintf('Completed RunExperiment cycle - results at %s.\n',out_file);
            end

          %  beep;
        end
    end
end

LogMsg(sprintf('%s Completed RunExperiment.',date_now));
