{"size": 1795, "ext": "js", "max_stars_repo_path": "js/modules/cohortbuilder/components/FeasibilityAttritionReport.js", "max_stars_repo_name": "mi-erasmusmc/Atlas", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "js/modules/cohortbuilder/components/FeasibilityAttritionReport.js", "max_issues_repo_name": "mi-erasmusmc/Atlas", "max_issues_repo_issues_event_min_datetime": "2017-03-22T18:18:26.000Z", "max_issues_repo_issues_event_max_datetime": "2017-03-29T07:40:11.000Z", "max_forks_repo_path": "js/modules/cohortbuilder/components/FeasibilityAttritionReport.js", "max_forks_repo_name": "mi-erasmusmc/Atlas", "max_forks_repo_forks_event_min_datetime": "2021-08-18T17:09:15.000Z", "max_forks_repo_forks_event_max_datetime": "2021-08-18T17:09:15.000Z"}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": 1, "avg_line_length": 26.3970588235, "max_line_length": 119, "alphanum_fraction": 0.6479108635}
define(['knockout',
				'jquery',
				'text!./FeasibilityAttritionReport.html',
				'd3',
			  'css!../css/report.css'
			 ], function (
	ko,
	$,
	template) {

	function FeasibilityAttritionReport(params) {
		var self = this;

		function countMatch(node, mask) {
			var count = 0;
			if (node.hasOwnProperty("children"))
			{
				node.children.forEach(function(c) {
					count += countMatch(c,mask);
				});
			} else {
				count = node.name.startsWith(mask) ? node.size : 0;
			}
			return count;
		}
		
		self.report = params.report;
		self.attritionStats = ko.pureComputed(function () {
			var treemapData = JSON.parse(self.report().treemapData);
			// create the attrition counts based on the index of the inclusion rule.
			// index 0 must match startWith('1'), index 1 must startWith('11'), etc.
			var priorPct = 1.0;
			var stats = self.report().inclusionRuleStats.map(function (d, i) {
				var countSatisfying = countMatch(treemapData, '1'.repeat(i+1));
				var percentSatisfying = self.report().summary.baseCount != 0 ? countSatisfying/self.report().summary.baseCount : 0;
				var pctDiff = priorPct - percentSatisfying;
				priorPct = percentSatisfying;
				return {
					name: d.name,
					countSatisfying: countSatisfying,
					percentSatisfying: percentSatisfying,
					pctDiff : pctDiff
				};
			});
			return stats;
		});
		
		self.formatPercent = function (value) {
			return (100.0 * value).toFixed(2) + '%';	
		}
		
		self.color = d3.scale.quantize()
				.domain([1.0, .75, .5, .25, .10])
				.range(["#7BB209", "#95B90A", "#C9C40D", "#E77F13", "#FF3D19"]);
	}


	var component = {
		viewModel: FeasibilityAttritionReport,
		template: template
	};

	ko.components.register('feasibility-attrition-report', component);

	// return compoonent definition
	return component;
	
});