/**
 * Analyzes HTTP requests and generates stats metrics
 */
exports.version = '0.1';

exports.module = function(phantomas) {
	var smallestResponse,
		biggestResponse,
		fastestResponse,
		slowestResponse;

	phantomas.on('recv', function(entry, res) {
		// ignore anything different than HTTP 200
		if (entry.status !== 200) {
			return;
		}

		// size
		if (!smallestResponse || smallestResponse.bodySize > entry.bodySize) {
			smallestResponse = entry;
		}

		if (!biggestResponse || biggestResponse.bodySize < entry.bodySize) {
			biggestResponse = entry;
		}

		// time
		if (!fastestResponse || fastestResponse.timeToLastByte > entry.timeToLastByte) {
			fastestResponse = entry;
		}

		if (!slowestResponse || slowestResponse.timeToLastByte < entry.timeToLastByte) {
			slowestResponse = entry;
		}
	});

	phantomas.on('report', function() {
		phantomas.setMetric('smallestResponse', smallestResponse.bodySize);
		phantomas.setMetric('biggestResponse', biggestResponse.bodySize);

		phantomas.addNotice('The smallest response (' + (smallestResponse.bodySize/1024).toFixed(2) + ' kB): ' + smallestResponse.url);
		phantomas.addNotice('The biggest response (' + (biggestResponse.bodySize/1024).toFixed(2) + ' kB): ' + biggestResponse.url);

		phantomas.addNotice();

		phantomas.setMetric('fastestResponse', fastestResponse.timeToLastByte);
		phantomas.setMetric('slowestResponse', slowestResponse.timeToLastByte);

		phantomas.addNotice('The fastest response (' + fastestResponse.timeToLastByte + ' ms): ' + fastestResponse.url);
		phantomas.addNotice('The slowest response (' + slowestResponse.timeToLastByte + ' ms): ' + slowestResponse.url);

		phantomas.addNotice();

		// TODO: mean response time
	});
};

@@ -201,16 +201,236 @@
 ponse;%0A%0A
+%09var responseTimes = %5B%5D;%0A%0A%09function median(arr) %7B%0A%09%09var half = Math.floor(arr.length/2);%0A%0A%09%09arr.sort(function(a,b) %7B%0A%09%09%09return a - b;%0A%09%09%7D);%0A%0A%09%09return (arr.length %25 2) ? arr%5Bhalf%5D : ((arr%5Bhalf-1%5D + arr%5Bhalf%5D) / 2.0);%0A%09%7D%0A%0A
 %09phantom
@@ -466,16 +466,16 @@
  res) %7B%0A
-
 %09%09// ign
@@ -1018,16 +1018,111 @@
 try;%0A%09%09%7D
+%0A%0A%09%09// store time to calculate median response time%0A%09%09responseTimes.push(entry.timeToLastByte);
 %0A%09%7D);%0A%0A%09
@@ -1992,30 +1992,61 @@
 %0A%0A%09%09
-// TODO: mean 
+phantomas.setMetric('medianResponse', median(
 response
  tim
@@ -2041,21 +2041,24 @@
 response
- t
+T
 ime
+s));
 %0A%09%7D);%0A%7D;

Add 'medianResponse' metric