clear;
clc;

name = 'Results4Spss';

dataDir = 'D:/SocialNets/__Steam/_Exp_Oct13/Train/results8_Th35_2K_Train/F1022_Iter_1120/';
dataDir = 'D:/__SN_Oct13/Datasets_10K/extNoise_Th358_10K/F922_Iter_13/';
%dataDir = 'D:/__SN_Oct13/Results/results8_Th35_10K_F/F1022_Iter_110/';
dataDir = 'D:/__SN_Jan14_FF50/Results/results9_Th358_100K/F922_Iter_610/';
files = dir(strcat(dataDir, 'res_*.mat')); 
dateNow = clock;
dateNow = strcat(num2str(dateNow(1)),'_',num2str(dateNow(2)),'_', num2str(dateNow(3)),'_', num2str(dateNow(4)), num2str(dateNow(5)),'_', num2str(dateNow(6)));
outFile = sprintf('%sDump%s_%s.txt',dataDir, name, dateNow);
fileID = fopen(outFile,'w');


withAttr = 1;
withAttrNoise = 0;
withAddMissingAtt = 1;

first = 1;
for f = files'
    data = load(strcat(dataDir,f.name));
    numResults = size(data.purity,2);
    numMissing = size(data.removed_nodes,2);
    line = numResults/numMissing;
    % print header
    if first == 1
        fprintf(fileID,'file\tinx\titer\tnodes\tedges\tmissInx\tmissNum\tnumPHs\tavgPHs');
        if withAttr == 1 || withAddMissingAtt == 1
            fprintf(fileID,'\tAlgId\tAttId\tgId');
        else
            fprintf(fileID,'\tAlgId');
        end
        if withAttrNoise == 1
            fprintf(fileID,'\tNoise');
        end
        fprintf(fileID,'\tPurity\tAffTime\tClusterTime\tTotalTime\n');
        first = 0;
    end
    
    %print data
    for i=1:numResults
        r = data.purity(1,i);
        fprintf(fileID,'%s',data.file);
        fprintf(fileID,'\t%d',data.i);
        fprintf(fileID,'\t%d',data.iter);
        fprintf(fileID,'\t%d',r.graph_size);
        fprintf(fileID,'\t%d',r.graph_edges); %12.12.12
        fprintf(fileID,'\t%d',r.num_missing_nodes_idx); 
        fprintf(fileID,'\t%d',r.num_missing_nodes);
        fprintf(fileID,'\t%d',r.num_placeholders);
        fprintf(fileID,'\t%d',r.num_placeholders/r.num_missing_nodes);
        fprintf(fileID,'\t%d',r.affinity_calculation_type);
        if withAddMissingAtt == 1
            p = r.addMissingAtt;
            if r.addMissingAtt == 1
                p = 0;
            end
            if withAttrNoise == 1
                n = 10000;
            else
                n = 1;
            end
            fprintf(fileID,'\t%d',r.withAttr);
            fprintf(fileID,'\t%d',p*100000+r.affinity_calculation_type*1000*n+r.withAttr);
        elseif withAttr == 1
            fprintf(fileID,'\t%d',r.withAttr);
            fprintf(fileID,'\t%d',r.affinity_calculation_type*1000+r.withAttr);
        end
        if withAttrNoise == 1
            fprintf(fileID,'\t%d',r.noiseNumAdded);
        end
        fprintf(fileID,'\t%d',r.score);
        time1_aff = r.affinity_calc_time; 
        time2_cluster = r.reduce_dim_time+r.graph_predict_time;
        fprintf(fileID,'\t%d',time1_aff);
        fprintf(fileID,'\t%d',time2_cluster);
        fprintf(fileID,'\t%d',time1_aff+time2_cluster);
        fprintf(fileID,'\n');
    end
end

fclose(fileID);
LogMsg(sprintf('Completed DumpResults at%s',outFile));
