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

CVS | Administration

Annotation of libnutss/examples/process_data.m, revision 1.2

1.1       ths         1: function re = process_data(sampleclocks)
                      2:
                      3:     capacityPerPeer = 400;
                      4:
                      5:     fid = fopen('args.txt','r');
                      6:     n = fscanf(fid,'nodes: %d\n',1);
                      7:     fclose(fid);
                      8:     capacities = zeros(1,n);
                      9:     peers = zeros(n,1);
1.2     ! ths        10:     lengths = zeros(n,1);
1.1       ths        11:     rejections = zeros(n,1);
                     12:     retirations = zeros(n,1);
                     13:     f = cell(1,n);
                     14:     % read the files, get all the data organized
                     15:     for i=1:n
                     16:         fid=fopen(['peer_node' num2str(i) '.txt'],'r');
                     17:         if(fid > 0)
                     18:            numpeers = fscanf(fid,'%d %d');
                     19:            peers(i,1:length(numpeers)) = numpeers;
                     20:            fclose(fid);
                     21:         end
                     22:     end
                     23:     for i=1:n
1.2     ! ths        24:         fid=fopen(['walk_node' num2str(i) '.txt'],'r');
        !            25:         if(fid > 0)
        !            26:            walk = fscanf(fid,'%d %d');
        !            27:            lengths(i,1:length(walk)) = walk;
        !            28:            fclose(fid);
        !            29:         end
        !            30:     end
        !            31:     for i=1:n
1.1       ths        32:         fid=fopen(['data_node' num2str(i) '.txt'],'r');
                     33:         if(fid > 0)
                     34:             cap = fscanf(fid,'%d',1);
                     35:             if length(cap) > 0
                     36:                 capacities(i) = cap;
                     37:             else
                     38:                 continue;
                     39:             end
                     40:             t = textscan(fid,'%d%s');
                     41:             m = length(t{1});
                     42:             times = []; weights = [];
                     43:             durations = [];
                     44:             for j=1:m
                     45:                 if(strcmp(t{2}{j},'reject'))
                     46:                     rejections(i,j) = t{1}(j);
                     47:                 elseif(strcmp(t{2}{j},'retire'))
                     48:                     retirations(i,j) = t{1}(j);
                     49:                 else
                     50:                     data = sscanf(t{2}{j},'%d;%d;%d;');
                     51:                     if(length(data) > 0)
                     52:                         times = [times t{1}(j)];
                     53:                         durations = [durations data(1)];
                     54:                         weights = [weights data(2)];
                     55:                     end
                     56:                 end
                     57:             end
                     58:             f{i} = [times;durations;weights];
                     59:             fclose(fid);
                     60:         end
                     61:     end
1.2     ! ths        62:     f1 = figure(); axes(); title('Load Versus Time');
1.1       ths        63:     xlabel('Time (m)'); ylabel('Load'); hold on;
                     64:     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
                     65:     samples = zeros(n,1); sampletimes = zeros(n,1);
1.2     ! ths        66: %     f2 = figure(); axes(); title('Relative Load Versus Time');
        !            67: %     xlabel('Time (m)'); ylabel('Load / Capacity'); hold on;
        !            68: %     d = zeros(n,1); m = zeros(n,1); s = zeros(n,1);
        !            69: %     samples = zeros(n,1); sampletimes = zeros(n,1);
1.1       ths        70:
                     71:     first_denial = min(retirations(find(retirations > 0)));
                     72:     if length(first_denial) > 0
                     73:         sampleclocks = [first_denial(1)/60 sampleclocks];
                     74:     end
                     75:     % reconstruct load over time from recorded events
                     76:     for i=1:n
                     77:         if(length(f{i}) > 0)
                     78:             rqsts = length(f{i}(1,:));
                     79:             times = zeros(1,rqsts*2);
                     80:             delta = zeros(1,rqsts*2);
                     81:             k = 1;
                     82:             for j=1:rqsts
                     83:                 times(k) = f{i}(1,j);
                     84:                 delta(k) = f{i}(3,j);
                     85:                 times(k+1) = f{i}(1,j)+f{i}(2,j);
                     86:                 delta(k+1) = -f{i}(3,j);
                     87:                 k = k + 2;
                     88:             end
                     89:             [sortedtimes,permutation]=sort(times./60);
                     90:             d(i,1:2*rqsts) = cumsum(delta(permutation));
                     91:             %%
                     92:             if(length(sortedtimes(find(d(i,:) > capacities(i)))) > 0)
                     93:                 i
                     94:             end
                     95:             %%
                     96:             m(i) = mean(d(i,1:2*rqsts));
                     97:             s(i) = std(d(i,1:2*rqsts));
1.2     ! ths        98:             figure(f1);
1.1       ths        99:             plot(sortedtimes,d(i,1:2*rqsts));
                    100:             temp = rejections(i,find(rejections(i,:)))./60;
                    101:             plot(temp,ones(size(temp))*capacities(i),'g*');
                    102:             temp = retirations(i,find(retirations(i,:)))./60;
                    103:             plot(temp,ones(size(temp))*capacities(i),'r*');
1.2     ! ths       104: %             figure(f2);
        !           105: %             plot(sortedtimes,d(i,1:2*rqsts)./capacities(i));
1.1       ths       106:             k = 1;
                    107:             for sampleclock=sampleclocks
                    108:                 temp = abs(sortedtimes-sampleclock);
                    109:                 samp = find(min(temp)==temp);
                    110:                 sample(i,k) = d(i,samp(1));
                    111:                 sampletimes(i,k) = sortedtimes(samp(1));
                    112:                 k = k + 1;
                    113:                 % this code below plots load with no gradation, the way it
                    114:                 % works otherwise is as if load grows and shrinks gradually
                    115:                 % rather than incrementally, this makes it completely discrete
                    116:     %             temp = zeros(1,3*rqsts+1);
                    117:     %             temptimes = zeros(1,3*rqsts);
                    118:     %             get = 1;
                    119:     %             temptimes(1) = sortedtimes(get);
                    120:     %             for put=1:2:3*rqsts
                    121:     %                 temp(put) = d(i,get);
                    122:     %                 temp(put+1) = d(i,get);
                    123:     %                 temptimes(put+1) = sortedtimes(get);
                    124:     %                 temptimes(put+2) = sortedtimes(get);
                    125:     %                 get = get+1;
                    126:     %             end
                    127:
                    128:     %             points = min(length(temp),length(temptimes));
                    129:     %             plot(temptimes(1:points),temp(1:points));
                    130:             end
                    131:         end
                    132:     end
                    133:     hold off;
1.2     ! ths       134:
        !           135:
        !           136:
1.1       ths       137:     for k=1:length(sampleclocks)
                    138: %         figure(); axes(); title(['Distribution of Load per Peer at ' num2str(sampleclocks(k)) ' Minutes']);
                    139: %         xlabel('Load per Peer'); ylabel('Number of Nodes'); hold on;
                    140: %         hist(sample(:,k)'./peers,35); hold off;
                    141: %         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
                    142: %         xlabel('Node'); ylabel('Percent Load'); hold on;
                    143: %         bar(sample(:,k)'./peers./capacityPerPeer.*100); hold off;
                    144:         figure(); axes(); title(['Sorted Relative Load at ' num2str(sampleclocks(k)) ' Minutes']);
                    145:         xlabel('Node'); ylabel('Percent Load'); hold on;
1.2     ! ths       146:         loads = sort(sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
1.1       ths       147:      bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
                    148:         % also show loads sorted by capacity
                    149:         figure(); axes(); title(['Relative Load at ' num2str(sampleclocks(k)) ' Minutes Sorted by Capacity']);
                    150:         xlabel('Node (Capacities Low to High)'); ylabel('Percent Load'); hold on;
1.2     ! ths       151:         [garbage,permu] = sort(capacities(1:length(sample(:,k)')),'ascend');
        !           152:         loads = (sample(:,k)'./capacities(1:length(sample(:,k)')).*100);
1.1       ths       153:         loads = loads(permu);
                    154:         bar(loads(find(~isnan(loads) & loads ~= 0))); hold off;
                    155:     end
                    156:
1.2     ! ths       157: %{
1.1       ths       158:     return;
1.2     ! ths       159:
1.1       ths       160:     [n,t] = size(peers);
                    161:     f1 = figure(); f2 = figure();
                    162:     for i=1:n
                    163:         times = [];
                    164:         degree = [];
                    165:         mypeers = [];
                    166:         for k=2:2:t
                    167:             if peers(i,k) > 0
                    168:                 mypeers(k/2) = peers(i,k);
                    169:                 degree(k/2) = capacities(i) / peers(i,k);
                    170:                 times(k/2) = peers(i,k-1) / 60;
                    171:             else
                    172:                 break;
                    173:             end
                    174:         end
                    175:         figure(f1);
                    176:         plot(times,degree);
                    177:         axis([0 45 0 1200]);
                    178:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
                    179:         xlabel('Time'); ylabel('Capacity / Peer');
                    180:         figure(f2);
                    181:         plot(times,mypeers);
                    182:         axis([0 45 0 42]);
                    183:         title(['Node ' num2str(i) ' Capacity ' num2str(capacities(i))]);
                    184:         xlabel('Time'); ylabel('Peers');
1.2     ! ths       185: end
        !           186: %}
        !           187:     [n,t] = size(lengths);
        !           188:     f1 = figure();
        !           189:     title([' Extensions versus Time']);
        !           190:     xlabel('Time'); ylabel('Extensions');
        !           191:     for i=1:n
        !           192:         times = [];
        !           193:         mylengths = [];
        !           194:         for k=2:2:t
        !           195:             if lengths(i,k) > 0
        !           196:                 mylengths(k/2) = lengths(i,k);
        !           197:                 times(k/2) = lengths(i,k-1) / 60;
        !           198:             else
        !           199:                 break;
        !           200:             end
        !           201:         end
        !           202: %        figure(f1);
        !           203:         hold on;
        !           204:         plot(times,mylengths);
        !           205:         hold off;
1.1       ths       206:     end
1.2     ! ths       207:
1.1       ths       208: %     figure(); axes(); title('Distribution of Mean Load');
                    209: %     xlabel('Mean Load'); ylabel('Nodes'); hold on;
                    210: %     hist(m,35); hold off;
                    211: %     figure(); axes(); title('Distribution of Standard Deviation of Load');
                    212: %     xlabel('Standard Deviation of Load'); ylabel('Nodes'); hold on;
                    213: %     hist(s,35); hold off;
                    214: 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