<commit_before>"use strict";
(function(window, $){
	var userScores = localStorage.userScores ? JSON.parse(localStorage.userScores) : null;
	var tempScores = [];
	
	var perf;
	var colors = {
		gray:["rgba(220,220,220,0.5)", "rgba(220,220,220,1)"], 
		blue:["rgba(151,187,205,0.5)", "rgba(151,187,205,1)"], 
		purple:["rgba(201, 198, 229, 0.5)", "rgba(201, 198, 229, 1)"], 
		green:["rgba(151, 205, 158, 0.5)","rgba(151, 205, 158, 1)"],
		gold:["rgba(237, 235, 65, 0.5)", "rgba(207, 205, 65, 1)"],
		red: ["rgba(237, 65, 65, 0.5)", "#DB7D7D"],
		darkgray: ["rgba(190, 190, 190, 0.5)","#ccc"]
	};
	var extraColorKeys = ["green", "blue", "gold", "red", "purple"];
	
	$.ajax({
		type: 'GET',
		dataType: 'xml',
		url: 'competencies/performance-frameworks/v1/demonstrate-warrior-athlete-ethos.xml',
		success: function(data){
		
			perf = parsePerformanceFramework(data);
			
			var tempArr = [];
			for(var i = 0; i < perf.Component.length; i++){
				for(var g = 0; g < perf.Component[i].PerformanceLevelSet.PerformanceLevel.length; g++){
					tempArr.push(perf.Component[i].PerformanceLevelSet.PerformanceLevel[g]);
				}
			}
			
			generateTestData();
			
			perf.getImgURL = getImgURL;
			perf.isCurrentScore = isCurrentScore;
			perf.reset = reset;
			ko.applyBindings(perf);
			
			var collection = (new ADL.Collection(tempArr)).groupBy('Indicator.Description');
			
			drawHorizontalBar();
			drawChart(collection);

			console.log("Medbiquitous performance framework (JS): ", perf);
			console.log("Generated test data: ", userScores);
		},
		error: function(err, status, mess){
			console.error("ERROR!!", err, status, mess);
		}
	});
	
	function reset(){
		localStorage.clear();
		location.reload();
		
		return false;
	}

	function drawChart(collection){
		var sum = userScores.reduce(function(a, b){ return a + b});
		var sumRemaining = perf.Component.reduce(function(a, b){ return (a>0?a:a.PerformanceLevelSet.total) + (b>0?b:b.PerformanceLevelSet.total)}) - sum;
		var options = {percentageInnerCutout: 45, segmentStrokeColor : sumRemaining > 0 ? "#FFF" : "#FDB45C"};
		var data = [];
		
		data.push({
			value: sum,
			color:colors.darkgray[0],
			highlight: colors.darkgray[1],
			label: "Your Total Score"
		});
		
		for(var i = 0; i < collection.contents.length; i++){
			var totalCount = 0;
			for(var g = 0; g < collection.contents[i].data.length; g++){

				var item =  collection.contents[i].data[g];
				
				if(item._pie != "over"){
					totalCount += item._pointValue;
				}
			}

			data.push({
				value: totalCount,
				color: colors[extraColorKeys[i]][0],
				highlight: colors[extraColorKeys[i]][1],
				label: collection.contents[i].group
			});	
		}
		
		var chart = new Chart(document.getElementById('myChart').getContext('2d')).Doughnut(data, options);
		$("#legend").html(chart.generateLegend());
	}
	
	function drawHorizontalBar(){
		for(var i = 0; i < perf.Component.length; i++){
		
			var data = {labels: ["Performance Levels","You"], datasets: []};
			var perfLevel = perf.Component[i].PerformanceLevelSet;
			var totalDiff = 0;
			
			data.datasets.push({
				fillColor : colors.darkgray[0],
				strokeColor : colors.darkgray[1],
				data: [0,userScores[i]],
				title: "Current"
			});
			
			for(var g = 0; g < perfLevel.PerformanceLevel.length-1; g++){
				if(!Array.isArray(perfLevel.PerformanceLevel[g]._include.match(/both|max/))){
					perfLevel.PerformanceLevel[g].max--;
				}
				
				var color = perfLevel.PerformanceLevel[g].Indicator.Description.toLowerCase() == "not competent" ? colors.gray : colors[extraColorKeys[g]];
				perfLevel.PerformanceLevel[g]._pointValue = perfLevel.PerformanceLevel[g].max-totalDiff;
				
				data.datasets.push({
					fillColor : color[0],
					strokeColor : color[1],
					data: [perfLevel.PerformanceLevel[g]._pointValue],
					title: perfLevel.PerformanceLevel[g].Indicator.Description,
				});
				
				totalDiff = perfLevel.PerformanceLevel[g].max;
				
				handlePieChartInfo(perfLevel.PerformanceLevel[g], i);
			}
			
			perfLevel.PerformanceLevel[g]._pointValue = perfLevel.total-totalDiff;
			data.datasets.push({
			    fillColor : colors.gold[0],
				strokeColor : colors.gold[1],
				data: [perfLevel.total-totalDiff],
				title: perfLevel.PerformanceLevel[g].Indicator.Description
			});
			handlePieChartInfo(perfLevel.PerformanceLevel[g], i);

			var options = {
				annotateLabel: "<%=(v1 == '' ? '' : v1) %>",
				graphMin: 0,
				annotateDisplay: true				
			};
			var chart = new ChartNew(document.getElementById('canvas' + i).getContext('2d')).HorizontalStackedBar(data, options);
		}
	}
	
	function handlePieChartInfo(perf, index){
		if(perf._pie == "over"){
			tempScores[index] -= perf._pointValue;
			perf._pointValue = 0;
		}		
		else if(perf._pie == "current"){
			
			perf._pointValue -= tempScores[index];<commit_msg>Removed legend items that do not contribute to pie<commit_after>"use strict";
(function(window, $){
	var userScores = localStorage.userScores ? JSON.parse(localStorage.userScores) : null;
	var tempScores = [];
	
	var perf;
	var colors = {
		gray:["rgba(220,220,220,0.5)", "rgba(220,220,220,1)"], 
		blue:["rgba(151,187,205,0.5)", "rgba(151,187,205,1)"], 
		purple:["rgba(201, 198, 229, 0.5)", "rgba(201, 198, 229, 1)"], 
		green:["rgba(151, 205, 158, 0.5)","rgba(151, 205, 158, 1)"],
		gold:["rgba(237, 235, 65, 0.5)", "rgba(207, 205, 65, 1)"],
		red: ["rgba(237, 65, 65, 0.5)", "#DB7D7D"],
		darkgray: ["rgba(190, 190, 190, 0.5)","#ccc"]
	};
	var extraColorKeys = ["green", "blue", "gold", "red", "purple"];
	
	$.ajax({
		type: 'GET',
		dataType: 'xml',
		url: 'competencies/performance-frameworks/v1/demonstrate-warrior-athlete-ethos.xml',
		success: function(data){
		
			perf = parsePerformanceFramework(data);
			
			var tempArr = [];
			for(var i = 0; i < perf.Component.length; i++){
				for(var g = 0; g < perf.Component[i].PerformanceLevelSet.PerformanceLevel.length; g++){
					tempArr.push(perf.Component[i].PerformanceLevelSet.PerformanceLevel[g]);
				}
			}
			
			generateTestData();
			
			perf.getImgURL = getImgURL;
			perf.isCurrentScore = isCurrentScore;
			perf.reset = reset;
			ko.applyBindings(perf);
			
			var collection = (new ADL.Collection(tempArr)).groupBy('Indicator.Description');
			
			drawHorizontalBar();
			drawChart(collection);

			console.log("Medbiquitous performance framework (JS): ", perf);
			console.log("Generated test data: ", userScores);
		},
		error: function(err, status, mess){
			console.error("ERROR!!", err, status, mess);
		}
	});
	
	function reset(){
		localStorage.clear();
		location.reload();
		
		return false;
	}

	function drawChart(collection){
		var sum = userScores.reduce(function(a, b){ return a + b});
		var sumRemaining = perf.Component.reduce(function(a, b){ return (a>0?a:a.PerformanceLevelSet.total) + (b>0?b:b.PerformanceLevelSet.total)}) - sum;
		var options = {percentageInnerCutout: 45, segmentStrokeColor : sumRemaining > 0 ? "#FFF" : "#FDB45C"};
		var data = [];
		
		data.push({
			value: sum,
			color:colors.darkgray[0],
			highlight: colors.darkgray[1],
			label: "Your Total Score"
		});
		
		for(var i = 0; i < collection.contents.length; i++){
			var totalCount = 0;
			for(var g = 0; g < collection.contents[i].data.length; g++){

				var item =  collection.contents[i].data[g];
				
				if(item._pie != "over"){
					totalCount += item._pointValue;
				}
			}
			
			if(totalCount > 0){
				data.push({
					value: totalCount,
					color: colors[extraColorKeys[i]][0],
					highlight: colors[extraColorKeys[i]][1],
					label: collection.contents[i].group
				});	
			}
		}
		
		var chart = new Chart(document.getElementById('myChart').getContext('2d')).Doughnut(data, options);
		$("#legend").html(chart.generateLegend());
	}
	
	function drawHorizontalBar(){
		for(var i = 0; i < perf.Component.length; i++){
		
			var data = {labels: ["Performance Levels","You"], datasets: []};
			var perfLevel = perf.Component[i].PerformanceLevelSet;
			var totalDiff = 0;
			
			data.datasets.push({
				fillColor : colors.darkgray[0],
				strokeColor : colors.darkgray[1],
				data: [0,userScores[i]],
				title: "Current"
			});
			
			for(var g = 0; g < perfLevel.PerformanceLevel.length-1; g++){
				if(!Array.isArray(perfLevel.PerformanceLevel[g]._include.match(/both|max/))){
					perfLevel.PerformanceLevel[g].max--;
				}
				
				var color = perfLevel.PerformanceLevel[g].Indicator.Description.toLowerCase() == "not competent" ? colors.gray : colors[extraColorKeys[g]];
				perfLevel.PerformanceLevel[g]._pointValue = perfLevel.PerformanceLevel[g].max-totalDiff;
				
				data.datasets.push({
					fillColor : color[0],
					strokeColor : color[1],
					data: [perfLevel.PerformanceLevel[g]._pointValue],
					title: perfLevel.PerformanceLevel[g].Indicator.Description,
				});
				
				totalDiff = perfLevel.PerformanceLevel[g].max;
				
				handlePieChartInfo(perfLevel.PerformanceLevel[g], i);
			}
			
			perfLevel.PerformanceLevel[g]._pointValue = perfLevel.total-totalDiff;
			data.datasets.push({
			    fillColor : colors.gold[0],
				strokeColor : colors.gold[1],
				data: [perfLevel.total-totalDiff],
				title: perfLevel.PerformanceLevel[g].Indicator.Description
			});

			handlePieChartInfo(perfLevel.PerformanceLevel[g], i);

			var options = {
				annotateLabel: "<%=(v1 == '' ? '' : v1) %>",
				graphMin: 0,
				annotateDisplay: true				
			};
			var chart = new ChartNew(document.getElementById('canvas' + i).getContext('2d')).HorizontalStackedBar(data, options);
		}
	}
	
	function handlePieChartInfo(perf, index){
		if(perf._pie == "over"){
			tempScores[index] -= perf._pointValue;
			perf._pointValue = 0;
		}		
		else if(perf._pie == "current"){
			
			perf._pointValue -= tempScores[index];
{'fraction_non_alphanumeric': 0.17339911604481448, 'fraction_numerical': 0.03278857025388015, 'mean_word_length': 3.848031888390633, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3979868', 'n_tokens_mistral': 4211, 'n_tokens_neox': 3292, 'n_words': 605}