<commit_before>/**
 * <p>Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
 * Please see the LICENSE file for information about licensing.</p>
 *
 * @module plugins/AnalysisCoverage
 * @author <NAME> &lt;<a href='mailto:<EMAIL>'><EMAIL></a>&gt;
 */


var path = require('path'),
	fs = require('fs'),
	existsSync = fs.existsSync || path.existsSync,

	wrench = require('wrench'),

	Runtime = require(path.join(global.titaniumCodeProcessorLibDir, 'Runtime')),
	AST = require(path.join(global.titaniumCodeProcessorLibDir, 'AST')),
	results = {
		summary: 'I am the analysis results',
		details: {},
		filesSkipped: [],
		numTotalFiles: 0,
		numFilesSkipped: 0,
		numNodesVisited: 0,
		numNodesSkipped: 0,
		numTotalNodes: 0
	};

// ******** Plugin API Methods ********

/**
 * Creates an instance of the require provider plugin
 *
 * @classdesc Provides a CommonJS compliant require() implementation, based on Titanium Mobile's implementations
 *
 * @constructor
 * @name module:plugins/AnalysisCoverage
 */
module.exports = function (options) {
	Runtime.on('projectProcessingEnd', function() {
		var astSet = Runtime.getASTSet(),
			id,
			result,
			outputDir,
			inputDir = path.dirname(Runtime.getEntryPointFile()),
			inputSource,
			styles,
			outputFilePath,
			annotationStyle,
			annotationData;

		function nodeVisitedCallback (node) {
			if (node._visited) {
				result.numNodesVisited++;
				results.numNodesVisited++;
			} else if (node._skipped) {
				result.numNodesSkipped++;
				results.numNodesSkipped++;
			} else {
				node._unvisited = true;
			}
			result.numTotalNodes++;
			results.numTotalNodes++;
		}

		// Analyze the files
		results.filesSkipped = Runtime.getUnprocessedFilesList();
		results.numTotalFiles = results.filesSkipped.length + Runtime.getProcessedFilesList().length;
		results.numFilesSkipped = results.filesSkipped.length;

		// Analyze the ASTs
		for (id in astSet) {
			result = results.details[id] = {
				numNodesVisited: 0,
				numNodesSkipped: 0,
				numTotalNodes: 0
			};
			AST.walk(astSet[id], [
				{
					callback: nodeVisitedCallback
				}
			]);
		}

		if (options && options.visualization) {

			// Calculate the output directory
			outputDir = options.visualization.outputDirectory;
			if (outputDir) {
				if (options.visualization.timestampOutputDirectory) {
					outputDir += '.' + (new Date()).toISOString();
				}
				if (existsSync(outputDir)) {
					wrench.rmdirSyncRecursive(outputDir);
				}
			}

			// Calculate the styles
			styles = options.visualization.styles;
			if (styles) {
				annotationStyle = [{
						property: '_visited',
						value: true,<commit_msg>[TIMOB-12833] Finished the analysis coverage plugin's results generation<commit_after>/**
 * <p>Copyright (c) 2012 by Appcelerator, Inc. All Rights Reserved.
 * Please see the LICENSE file for information about licensing.</p>
 *
 * @module plugins/AnalysisCoverage
 * @author <NAME> &lt;<a href='mailto:<EMAIL>'><EMAIL></a>&gt;
 */


var path = require('path'),
	fs = require('fs'),
	existsSync = fs.existsSync || path.existsSync,

	wrench = require('wrench'),

	Runtime = require(path.join(global.titaniumCodeProcessorLibDir, 'Runtime')),
	AST = require(path.join(global.titaniumCodeProcessorLibDir, 'AST')),
	results = {
		summary: '',
		details: {},
		filesSkipped: [],
		numTotalFiles: 0,
		numFilesSkipped: 0,
		numNodesVisited: 0,
		numNodesSkipped: 0,
		numTotalNodes: 0
	};

// ******** Plugin API Methods ********

/**
 * Creates an instance of the require provider plugin
 *
 * @classdesc Provides a CommonJS compliant require() implementation, based on Titanium Mobile's implementations
 *
 * @constructor
 * @name module:plugins/AnalysisCoverage
 */
module.exports = function (options) {
	Runtime.on('projectProcessingEnd', function() {
		var astSet = Runtime.getASTSet(),
			id,
			result,
			outputDir,
			inputDir = path.dirname(Runtime.getEntryPointFile()),
			inputSource,
			styles,
			outputFilePath,
			annotationStyle,
			annotationData;

		function nodeVisitedCallback (node) {
			if (node._visited) {
				result.numNodesVisited++;
				results.numNodesVisited++;
			} else if (node._skipped) {
				result.numNodesSkipped++;
				results.numNodesSkipped++;
			} else {
				node._unvisited = true;
			}
			result.numTotalNodes++;
			results.numTotalNodes++;
		}

		// Analyze the files
		results.filesSkipped = Runtime.getUnprocessedFilesList();
		results.numTotalFiles = results.filesSkipped.length + Runtime.getProcessedFilesList().length;
		results.numFilesSkipped = results.filesSkipped.length;

		// Analyze the ASTs
		for (id in astSet) {
			result = results.details[id] = {
				numNodesVisited: 0,
				numNodesSkipped: 0,
				numTotalNodes: 0
			};
			AST.walk(astSet[id], [
				{
					callback: nodeVisitedCallback
				}
			]);
		}

		// Create the summary report
		results.summary = (100 * results.numFilesSkipped / results.numTotalFiles *
			results.numNodesVisited / results.numTotalNodes).toFixed(1) +
			'% of the project\'s code was analyzed';

		if (options && options.visualization) {

			// Calculate the output directory
			outputDir = options.visualization.outputDirectory;
			if (outputDir) {
				if (options.visualization.timestampOutputDirectory) {
					outputDir += '.' + (new Date()).toISOString();
				}
				if (existsSync(outputDir)) {
					wrench.rmdirSyncRecursive(outputDir);
				}
			}

			// Calculate the styles
			styles = options.visualization.styles;
			if (styles) {
				annotationStyle = [{
						property: '_visited',
						value: true,
{'fraction_non_alphanumeric': 0.1315504156125768, 'fraction_numerical': 0.005963136971449223, 'mean_word_length': 3.7674418604651163, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '128718', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1720, 'n_words': 377}