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.1: download - view: text, annotated - select for diffs
Thu Aug 23 22:13:44 2007 UTC (10 years ago) by ths
Branches: MAIN
CVS tags: HEAD
added a matlab file to interpret and plot the data generated by swaplinks experiments

function re = process_data(sampleclocks)

    capacityPerPeer = 400;

    fid = fopen('args.txt','r');
    n = fscanf(fid,'nodes: %d\n',1);
    fclose(fid);
    capacities = zeros(1,n);
    peers = zeros(n,1);
    rejections = zeros(n,1);
    retirations = 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)) = numpeers;
           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'))
                    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
    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);
    
    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));
            %%
            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));
            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*');
            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;
    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.*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,'ascend');
        loads = (sample(:,k)'./capacities.*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
%     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