//speed test processing for mums BT
d=fscanfMat("proced.txt");

if ~isdef("pAvg");
	x=[];
	p=[];
	pAvg=[]; pSum=0; nPAvg=1;
	xAvg=[]; xSum=0; nXAvg=1;
	t=0;
	tl=0;
	for i=1:size(d,1);
		if d(i,1) == 1; 
			tl=d(i,2);
			dy = int(d(i,2)/1000000);
			h = int((d(i,2) - dy*1000000)/10000);
			m = int((d(i,2) - dy*1000000 - h*10000)/100);
			s = d(i,2) - dy*1000000 - h*10000 - m*100;
			t = (dy-19)*24 + h + m/60 + s/3600;
		end;
		if d(i,1) == 2;
			if t == p($,1);
				t = t + 4/3600;
				pSum = pSum + d(i,2);
				nPAvg = nPAvg + 1;
			elseif nPAvg > 0;
				pAvg = [pAvg; t, tl, pSum / nPAvg];
				pSum = 0; nPAvg = 0;
			end;
			p = [p; t, tl, d(i,2)];
		end;
		if d(i,1) == 3;
			if t == x($,1);
				t = t + 1/3600;
				xSum = xSum + d(i,2);
				nXAvg = nXAvg + 1;
			elseif nXAvg > 0;
				xAvg = [xAvg; t, tl, xSum / nXAvg];
				xSum = 0; nXAvg = 0;
			end;	
			x = [x; t, tl, d(i,2)];
		end;
	end;
end;


clf;
subplot(2,1,1);
plot(xAvg(:,1), xAvg(:,3)*8, "b");
ax1=gca();
ax1.x_label.text = "time / hours since 0:00 19/12/11";
ax1.y_label.text = "blue: Download rate / Kbps";

subplot(2,1,2);
//ax2 = newaxes();
//ax2.axes_bounds=ax1.axes_bounds;
//ax2.background=-99;
//ax2.y_location="right";
plot(pAvg(:,1), pAvg(:,3), "r");
ax2=gca();
ax2.x_label.text = "time / hours since 0:00 19/12/11";
ax2.y_label.text = "red: Ping time to google.co.uk / ms";

xs2eps(0,"/home/oliford/mumsBTSpeed/log");
