clear;
clc;
dataDir = 'D:/SocialNets/Steam/Results_Test/FF75_50Att/GED_25w3/test/';
files = dir(strcat(dataDir, 'res_Steam*.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('%sDumpResults_%s.txt',dataDir, dateNow);
fileID = fopen(outFile,'w');

ged = 0;
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,'\tfile\tinx\titer\tnodes\tedges\tattEdges\tattNodes\tmissInx\tmissNum\tnumPHs\tavgPHs');
        for i=1:line
            r=data.purity(1,i);
            if r.withAttr == 1
                fprintf(fileID,'\tAtt %d\tDiff %d',r.affinity_calculation_type,r.affinity_calculation_type);
            else
                fprintf(fileID,'\tAlg %d',r.affinity_calculation_type);
            end
        end
        fprintf(fileID,'\n');
        first = 0;
    end
    %print data
    for i=1:numResults
        r = data.purity(1,i);
        if mod(i,line)==1
            fprintf(fileID,'\t%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.graph_attr_edges); % 12.12.12
            fprintf(fileID,'\t%d', data.purity(1,i+1).num_attr_nodes);
            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);
        end   
        if ged == 1
            fprintf(fileID,'\t%d',r.edit_distance);
            if mod(i,2)==0
                fprintf(fileID,'\t%d',data.purity(1,i-1).edit_distance-r.edit_distance);
            end
        else
            fprintf(fileID,'\t%d',r.score);
            if mod(i,2)==0
                fprintf(fileID,'\t%d',data.purity(1,i-1).score-r.score);
            end
        end
        if mod(i,line)==0
            fprintf(fileID,'\n');
        end
    end
end

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