<commit_before>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define([], function() {

	var PageController = ['$scope', 'auth', 'api', 'tags', '$stateParams', '$timeout', function($scope, auth, api, tags, $stateParams, $timeout) {
		$timeout(function() {
			// Call this asynchronously, so that loading icon doesn't get immediately clobbered by $stateChangeSuccess.
			$scope.globalFlags.isLoading = true;
		});
		
		if ($stateParams.userId) {
			$scope.progress = api.user.getProgress({ userId: $stateParams.userId });
		} else {
			$scope.progress = api.currentUser.getProgress();
		}

		$scope.progress.$promise.then(function() {
			$scope.globalFlags.isLoading = false;

			var attemptedFields = [];
			$scope.fields = [];
			for (var tid in $scope.progress.attemptsByTag) {
				var t = tags.getById(tid);
				if (t && t.level == 1) {
					attemptedFields.push(t);
					$scope.fields.push(t);
				}
			}

			$scope.field = {
				selection: tags.getById("mechanics"),
			};

			$scope.levelData = [
				{label: 'Level 1', val: $scope.progress.attemptsByLevel["1"] || 0},
				{label: 'Level 2', val: $scope.progress.attemptsByLevel["2"] || 0},
				{label: 'Level 3', val: $scope.progress.attemptsByLevel["3"] || 0},
				{label: 'Level 4', val: $scope.progress.attemptsByLevel["4"] || 0},
				{label: 'Level 5', val: $scope.progress.attemptsByLevel["5"] || 0},
				{label: 'Level 6', val: $scope.progress.attemptsByLevel["6"] || 0}
			];

			$scope.subjectData = [
				{label: 'Physics', val: $scope.progress.attemptsByTag["physics"] || 0},
				{label: 'Maths', val: $scope.progress.attemptsByTag["maths"] || 0}
			];


			$scope.$watch("field.selection", function(newField) {

				$scope.fieldData = [];

				var topics = tags.getDescendents($scope.field.selection.id);
				for(var i in topics) {
					var t = topics[i];
					$scope.fieldData.push({
						label: t.title,
						val: $scope.progress.attemptsByTag[t.id] || 0,
					})
				}

			})

		});
	}];

	return {
		PageController: PageController
	};
})<commit_msg>Add error handling to Progress Page load.<commit_after>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 *
 * You may obtain a copy of the License at
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
define([], function() {

	var PageController = ['$scope', 'auth', 'api', 'tags', '$stateParams', '$timeout', function($scope, auth, api, tags, $stateParams, $timeout) {
		$timeout(function() {
			// Call this asynchronously, so that loading icon doesn't get immediately clobbered by $stateChangeSuccess.
			$scope.globalFlags.isLoading = true;
		});
		
		if ($stateParams.userId) {
			$scope.progress = api.user.getProgress({ userId: $stateParams.userId });
		} else {
			$scope.progress = api.currentUser.getProgress();
		}

		$scope.progress.$promise.then(function() {
			$scope.globalFlags.isLoading = false;

			var attemptedFields = [];
			$scope.fields = [];
			for (var tid in $scope.progress.attemptsByTag) {
				var t = tags.getById(tid);
				if (t && t.level == 1) {
					attemptedFields.push(t);
					$scope.fields.push(t);
				}
			}

			$scope.field = {
				selection: tags.getById("mechanics"),
			};

			$scope.levelData = [
				{label: 'Level 1', val: $scope.progress.attemptsByLevel["1"] || 0},
				{label: 'Level 2', val: $scope.progress.attemptsByLevel["2"] || 0},
				{label: 'Level 3', val: $scope.progress.attemptsByLevel["3"] || 0},
				{label: 'Level 4', val: $scope.progress.attemptsByLevel["4"] || 0},
				{label: 'Level 5', val: $scope.progress.attemptsByLevel["5"] || 0},
				{label: 'Level 6', val: $scope.progress.attemptsByLevel["6"] || 0}
			];

			$scope.subjectData = [
				{label: 'Physics', val: $scope.progress.attemptsByTag["physics"] || 0},
				{label: 'Maths', val: $scope.progress.attemptsByTag["maths"] || 0}
			];


			$scope.$watch("field.selection", function(newField) {

				$scope.fieldData = [];

				var topics = tags.getDescendents($scope.field.selection.id);
				for(var i in topics) {
					var t = topics[i];
					$scope.fieldData.push({
						label: t.title,
						val: $scope.progress.attemptsByTag[t.id] || 0,
					})
				}

			})

		}).catch(function(e) {
			console.error("Unable to load user progress:", e);
			$scope.globalFlags.isLoading = false;
		});
	}];

	return {
		PageController: PageController
	};
})
{'fraction_non_alphanumeric': 0.1624336618650493, 'fraction_numerical': 0.011372251705837756, 'mean_word_length': 3.545219638242894, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '130015', 'n_tokens_mistral': 2017, 'n_tokens_neox': 1675, 'n_words': 447}