<commit_before>/**
 * Domains monitor
 */
exports.version = '0.1';

exports.module = function(phantomas) {
	// count requests per domain
	var domains = {},
		domainsCount = 0;

	phantomas.on('recv', function(entry,res) {
		var domain = entry.domain;

		// base64?
		if (!domain) {
			return;
		}

		// init domain entry
		if (!domains[domain]) {
			domainsCount++;

			domains[domain] = {
				requests: []
			};
		}

		domains[domain].requests.push(res.url);
	});

	// add metrics
	phantomas.on('loadFinished', function() {
		//console.log(domains);
		phantomas.setMetric('domains', domainsCount);

		phantomas.addNotice('Requests per domain:');
		for(var domain in domains) {
			var entry = domains[domain],
				requests = entry.requests;

			// report URLs from each domain
			phantomas.addNotice(' ' + domain + ': ' + requests.length + ' request(s)');
			/**
			requests.forEach(function(url) {
				//phantomas.addNotice('   * ' + url);
			});
			**/
		}
		phantomas.addNotice();
	});
};
<commit_msg>domains: sort list of domains<commit_after>/**
 * Domains monitor
 */
exports.version = '0.2';

exports.module = function(phantomas) {
	var domains = {};
	phantomas.setMetric('domains');

	phantomas.on('recv', function(entry,res) {
		var domain = entry.domain;

		// base64?
		if (!domain) {
			return;
		}

		// init domain entry
		if (!domains[domain]) {
			domains[domain] = {
				requests: []
			};
		}

		domains[domain].requests.push(res.url);
	});

	// add metrics
	phantomas.on('report', function() {
		var domainsStats = [];

		Object.keys(domains).forEach(function(domain) {
			var cnt = domains[domain].requests.length;

			domainsStats.push({
				name: domain,
				cnt: cnt
			});
		});

		domainsStats.sort(function(a, b) {
			return (a.cnt > b.cnt) ? -1 : 1;
		});

		phantomas.setMetric('domains', domainsStats.length);

		phantomas.addNotice('Requests per domain:');
		domainsStats.forEach(function(domain) {
			phantomas.addNotice(' ' + domain.name + ': ' + domain.cnt + ' request(s)');
		});
		phantomas.addNotice();
	});
};

{'fraction_non_alphanumeric': 0.17839687194525905, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 3.2734864300626305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5294092', 'n_tokens_mistral': 814, 'n_tokens_neox': 680, 'n_words': 129}