Log In
New Account
  
 
Home My Page Project Tree Code Snippets Project Openings NUTSS
 
 
Summary Tracker Lists CVS Files
 

CVS | Administration


File:  [GForge:cvsroot/nutss] / libnutss / examples / process_data.m
Revision 1.3: download - view: text, annotated - select for diffs
Fri Sep 21 04:23:17 2007 UTC (9 years, 7 months ago) by ths
Branches: MAIN
CVS tags: HEAD
small changes to test rig

function re = process_data(sampleclocks)

    % should be about mincapacity/mindegree
    capacityPerPeer = 400;

    fid = fopen('args.txt','r');
    n = fscanf(fid,'nodes: %d\n',1);
    fclose(fid);
    capacities = zeros(1,n);
    peers = zeros(n,1);
    peertimes = zeros(n,1);
    lengths = zeros(n,1);
    lengthtimes = zeros(n,1);
    capoverpeer = zeros(1,n);
    rejections = zeros(n,1);
    retirations = zeros(n,1);
    retirebucket = zeros(60,1);
    freecapacity = zeros(n,1);
    freecapacitytimes = zeros(n,1);
    f = cell(1,n);
    % read the files, get all the data organized
    for i=1:n
        fid=fopen(['peer_node' num2str(i) '.txt'],'r');
        if(fid > 0)
           numpeers = fscanf(fid,'%d %d');
           peers(i,1:length(numpeers(2:2:end))) = numpeers(2:2:end);
           peertimes(i,1:length(numpeers(1:2:end))) = numpeers(1:2:end);
           fclose(fid);
        end
    end    
    for i=1:n
        fid=fopen(['walk_node' num2str(i) '.txt'],'r');
        if(fid > 0)
           walk = fscanf(fid,'%d %d');
           lengths(i,1:length(walk(2:2:end))) = walk(2:2:end);
           lengthtimes(i,1:length(walk(1:2:end))) = walk(1:2:end);
           fclose(fid);
        end
    end
    for i=1:n
        fid=fopen(['data_node' num2str(i) '.txt'],'r');
        if(fid > 0)
            cap = fscanf(fid,'%d',1);
            if length(cap) > 0
                capacities(i) = cap;
            else
                continue;
            end
            t = textscan(fid,'%d%s');
            m = length(t{1});
            times = []; weights = [];
            durations = [];
            for j=1:m
                if(strcmp(t{2}{j},'reject'))
                    rejections(i,j) = t{1}(j);
                elseif(strcmp(t{2}{j},'retire'))
                    curminute = floor(t{1}(j) / 60);
                    retirebucket(curminute) = retirebucket(curminute)+1;
                    retirations(i,j) = t{1}(j);
                else
                    data = sscanf(t{2}{j},'%d;%d;%d;');
                    if(length(data) > 0)
                        times = [times t{1}(j)];
                        durations = [durations data(1)];
                        weights = [weights data(2)];
                    end
                end 
            end
            f{i} = [times;durations;weights];
            fclose(fid);
        end 
    end
    f1 = figure(); axes(); title('Load Versus Time');
    xlabel('Time (m)'); ylabel('Load'); hold on;
    d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
    samples = zeros(n,1); sampletimes = zeros(n,1);
%     f2 = figure(); axes(); title('Relative Load Versus Time');
%     xlabel('Time (m)'); ylabel('Load / Capacity'); hold on;
%     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
%     samples = zeros(n,1); sampletimes = zeros(n,1);
    
    first_denial = min(retirations(find(retirations > 0)));
    if length(first_denial) > 0
        sampleclocks = [first_denial(1)/60 sampleclocks];
    end
    % reconstruct load over time from recorded events
    for i=1:n
        if(length(f{i}) > 0)
            rqsts = length(f{i}(1,:));
            times = zeros(1,rqsts*2);
            delta = zeros(1,rqsts*2);
            k = 1;
            for j=1:rqsts
                times(k) = f{i}(1,j);
                delta(k) = f{i}(3,j);
                times(k+1) = f{i}(1,j)+f{i}(2,j);
                delta(k+1) = -f{i}(3,j);
                k = k + 2;
            end
            [sortedtimes,permutation]=sort(times./60);
            d(i,1:2*rqsts) = cumsum(delta(permutation));
            
            freecapacity(i,1:2*rqsts) = capacities(i)-d(i,1:2*rqsts);
            freecapacitytimes(i,1:2*rqsts) = sortedtimes;
            
            mypeers = [];
            for ii=1:length(sortedtimes)
                % find closest timestep
                newmin = inf;
                for jj=1:length(peertimes(i,:))
                    mine = inf;
                    if sortedtimes(ii)*60 > 0 && peertimes(i,jj) > 0 && ...
                       abs(sortedtimes(ii)*60-peertimes(i,jj)) < newmin
                        newmin = abs(sortedtimes(ii)*60-peertimes(i,jj));
                        mine = peers(i,jj);
                    end
                end
                mypeers = [mypeers mine];
            end
            nonzp = peers(i,find(peers(i,:)));
            capoverpeer(1:length(nonzp),i) = capacities(i)./nonzp';
            %%
            if(length(sortedtimes(find(d(i,:) > capacities(i)))) > 0)
                i
            end
            %%
            m(i) = mean(d(i,1:2*rqsts));
            s(i) = std(d(i,1:2*rqsts));
            figure(f1);
            plot(sortedtimes,d(i,1:2*rqsts));
            temp = rejections(i,find(rejections(i,:)))./60;
            plot(temp,ones(size(temp))*capacities(i),'g*');
            temp = retirations(i,find(retirations(i,:)))./60;
            plot(temp,ones(size(temp))*capacities(i),'r*');
%             figure(f2);
%             plot(sortedtimes,d(i,1:2*rqsts)./capacities(i));
            k = 1;
            for sampleclock=sampleclocks
                temp = abs(sortedtimes-sampleclock);
                samp = find(min(temp)==temp);
                sample(i,k) = d(i,samp(1));
                sampletimes(i,k) = sortedtimes(samp(1));
                k = k + 1;
                % this code below plots load with no gradation, the way it
                % works otherwise is as if load grows and shrinks gradually
                % rather than incrementally, this makes it completely discrete
    %             temp = zeros(1,3*rqsts+1);
    %             temptimes = zeros(1,3*rqsts);
    %             get = 1;
    %             temptimes(1) = sortedtimes(get);
    %             for put=1:2:3*rqsts
    %                 temp(put) = d(i,get);
    %                 temp(put+1) = d(i,get);
    %                 temptimes(put+1) = sortedtimes(get);
    %                 temptimes(put+2) = sortedtimes(get);
    %                 get = get+1;
    %             end
                
    %             points = min(length(temp),length(temptimes));
    %             plot(temptimes(1:points),temp(1:points));
            end
        end
    end
    hold off;
%{
    freecapbucket = zeros(1,60);
    
    for i=1:n
        buckets = zeros(2,60);
        for j=1:length(freecapacity)
           curminute = floor(freecapacitytimes(i,j));
           buckets(1,curminute+1) = buckets(1,curminute+1)+freecapacity(i,j);
           buckets(2,curminute+1) = buckets(2,curminute+1)+1;
        end
        freecapbucket = freecapbucket + buckets(1,:)./buckets(2,:);
        freecapbucket(find(isnan(freecapbucket))) = 0;
    end
  %}  
    tot = 0;
    num = 0;
    freecapbucket = zeros(1,length(freecapacity));
    numalive = zeros(1,length(freecapacity));
    for j=1:length(freecapacity)
        tot = 0;
        num = 0;
        for i=1:n
            if freecapacity(i,j) > 0
                tot = tot + freecapacity(i,j);
                num = num + 1;
            end
        end
        freecapbucket(j) = tot / num;
        numalive(j) = num;
    end
    
    figure();
    title('average free capacity vs time');
    hold on;
    plot((1:length(freecapacity))./8,freecapbucket);
    hold off;
    figure();
    title('rejections per minute');
    hold on;
    plot(retirebucket);
    hold off;
    figure();
    title('num alive');
    hold on;
    plot(numalive);
    hold off;
    
    t = length(capoverpeer(:,1));
    md = zeros(1,t);
    for i=1:t
        sn = capoverpeer(i,:);
        md(i) = mean(abs(sn(find(sn))-capacityPerPeer));
    end
    figure();
    title('mean capacity / peer');
    hold on;
    plot((1:t)./8,md)
    hold off;
    
    figure();
    xlabel('Time (min)'); ylabel('Capacity / Peers');
    title('Comparison of Capacity / Peers Ratio to Optimal');
    for i=1:n
        if i == 1
            hold on;
            plot(1:round(t/8),capacityPerPeer*ones(1,round(t/8)),'r')
            hold off;
        end
        hold on;
        cpop = capoverpeer(:,i);
        plot((1:length(find(cpop)))./8,cpop(find(cpop)));
        hold off;
    end
    
    
%{    
    for k=1:length(sampleclocks)
%         figure(); axes(); title(['Distribution of Load per Peer at ' num2str(sampleclocks(k)) ' Minutes']);
%         xlabel('Load per Peer'); ylabel('Number of Nodes'); hold on;
%         hist(sample(:,k)'./peers,35); hold off;
%         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
%         xlabel('Node'); ylabel('Percent Load'); hold on;
%         bar(sample(:,k)'./peers./capacityPerPeer.*100); hold off;
        figure(); axes(); title(['Sorted Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
        xlabel('Node'); ylabel('Percent Load'); hold on;
        loads = sort(sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
		bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
        % also show loads sorted by capacity
        figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes Sorted by Capacity']);
        xlabel('Node (Capacities Low to High)'); ylabel('Percent Load'); hold on;
        [garbage,permu] = sort(capacities(1:length(sample(:,k)')),'ascend');
        loads = (sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
        loads = loads(permu);
        bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
    end
%}        
    
%{
    return;
     
    [n,t] = size(peers);    
    f1 = figure(); f2 = figure(); 
    for i=1:n
        times = [];
        degree = [];
        mypeers = [];
        for k=2:2:t
            if peers(i,k) > 0
                mypeers(k/2) = peers(i,k);
                degree(k/2) = capacities(i) / peers(i,k);
                times(k/2) = peers(i,k-1) / 60;
            else
                break;
            end
        end
        figure(f1);
        plot(times,degree);
        axis([0 45 0 1200]);
        title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
        xlabel('Time'); ylabel('Capacity / Peer'); 
        figure(f2);
        plot(times,mypeers);
        axis([0 45 0 42]);
        title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
        xlabel('Time'); ylabel('Peers');
end
    
    [n,t] = size(lengths);    
    f1 = figure();
    title([' Extensions versus Time']);
    xlabel('Time'); ylabel('Extensions');
    for i=1:n
        times = [];
        mylengths = [];
        for k=2:2:t
            if lengths(i,k) > 0
                mylengths(k/2) = lengths(i,k);
                times(k/2) = lengths(i,k-1) / 60;
            else
                break;
            end
        end
%        figure(f1);
        hold on;
        plot(times,mylengths);
        hold off;
    end
%}    
%     figure(); axes(); title('Distribution of Mean Load');
%     xlabel('Mean Load'); ylabel('Nodes'); hold on;
%     hist(m,35); hold off;
%     figure(); axes(); title('Distribution of Standard Deviation of Load');
%     xlabel('Standard Deviation of Load'); ylabel('Nodes'); hold on;
%     hist(s,35); hold off;
end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
 

GForge.cis.cornell.edu is brought to you by

Cornell Computing and Information Science


Powered By GForge Collaborative Development Environment