<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
**/

// Controller for dataset parameter selection/modification
App.Controllers.controller('ParameterSelectCtrl', ['$rootScope', '$scope', '$http', '$timeout', 
						   'selectedDatasetInformation', 'regionSelectParams', 'evaluationSettings', 
function($rootScope, $scope, $http, $timeout, selectedDatasetInformation, regionSelectParams, evaluationSettings) {
	$scope.datasets = selectedDatasetInformation.getDatasets();

	// The min/max lat/lon values from the selected datasets
	$scope.latMin = -90;
	$scope.latMax = 90;
	$scope.lonMin = -180;
	$scope.lonMax = 180;
	$scope.start = "1980-01-01 00:00:00";
	$scope.end = "2030-01-01 00:00:00";

	// The min/max lat/lon values that are displayed
	$scope.displayParams = regionSelectParams.getParameters();

	$scope.runningEval = false;

	// Flag for toggling re-grid controls based on whether or not the user has selected a grid
	// base from the selected datasets. By default we have no datasets so we don't need to show
	// the controls!
	$scope.areInUserRegridState = false;

	// Initialization for the lat/lon grid step sliders
	// TODO There has to be a better way of dealing with this. Perhaps a directive??
	$scope.latSliderVal = 0;
	$scope.lonSliderVal = 0;

	$('#latSlider').slider({
		value: 0,
		step: 0.25,
		min: 0.25,
		max: 180,
		slide: function(event, ui) {
			$scope.updateLatSliderDisplayValue(ui.value);
		},
	});

	$('#lonSlider').slider({
		value: 0,
		step: 0.25,
		min: 0.25,
		max: 360,
		slide: function(event, ui) {
			$scope.updateLonSliderDisplayValue(ui.value);
		},
	});

	$scope.updateLatSliderDisplayValue = function(value) {
		$scope.latSliderVal = value;
		$scope.$apply();
	};

	$scope.updateLonSliderDisplayValue = function(value) {
		$scope.lonSliderVal = value;
		$scope.$apply();
	};

	// Settings for jQuery datepicker directives!
	$scope.datepickerSettings = {
		changeMonth: true,
		changeYear: true,
	};

	$scope.shouldDisableControls = function() {
		return (selectedDatasetInformation.getDatasetCount() < 2);
	}

	$scope.shouldDisableEvaluateButton = function() {
		return ($scope.shouldDisableControls() || $scope.runningEval);
	}

	$scope.shouldDisableResultsView = function() {
		var res = false;

		if ($rootScope.evalResults == "")
			res = true;

		return res;
	}

	$scope.runEvaluation = function() {
		$scope.runningEval = true;

		// TODO
		// Currently this has the 1 model, 1 observation format hard coded in. This shouldn't
		// be the long-term case! This needs to be changed!!!!!!!!
		var obsIndex = -1,
			modelIndex = -1;

		for (var i = 0; i < $scope.datasets.length; i++) {
			if ($scope.datasets[i]['isObs'] == 1)
				obsIndex = i;
			else
				modelIndex = i;
		}

		// TODO At the moment we aren't running all the metrics that the user selected. We're only
		// running the first available metric that the user provides. If the user un-checks all
		// metrics then the default of 'bias' is used.
		var metricToRun = 'bias';
		var settings = evaluationSettings.getSettings().metrics;
		for (var i = 0; i < settings.length; i++) {
			var setting = settings[i];

			if (setting.select) {
				metricToRun = setting.name;
				break;
			}
		};

		var data = {params: { 
			'obsDatasetId'     : $scope.datasets[obsIndex]['id'],
			'obsParameterId'   : $scope.datasets[obsIndex]['param'],
			'startTime'        : $scope.displayParams.start + " 00:00:00",
			'endTime'          : $scope.displayParams.end + " 00:00:00",
			'latMin'           : $scope.displayParams.latMin,
			'latMax'           : $scope.displayParams.latMax,
			'lonMin'           : $scope.displayParams.lonMin,
			'lonMax'           : $scope.displayParams.lonMax,
			'filelist'         : $scope.datasets[modelIndex]['id'],
			'modelVarName'     : $scope.datasets[modelIndex]['param'],
			'modelTimeVarName' : $scope.datasets[modelIndex]['time'],
			'modelLatVarName'  : $scope.datasets[modelIndex]['lat'],
			'modelLonVarName'  : $scope.datasets[modelIndex]['lon'],
			'regridOption'     : 'model',
			'timeRegridOption' : evaluationSettings.getSettings().temporal.selected,
			'metricOption'     : metricToRun,
			'callback'         : 'JSON_CALLBACK',
		}};

		$http.jsonp($rootScope.baseURL + '/rcmes/run/', data).
		success(function(data) {
			var comp = data['comparisonPath'].split('/');
			var model = data['modelPath'].split('/');
			var obs = data['obsPath'].split('/');

			$rootScope.evalResults = {};
			$rootScope.evalResults.comparisonPath = comp[comp.length - 1];
			$rootScope.evalResults.modelPath = model[model.length - 1];
			$rootScope.evalResults.obsPath = obs[obs.length - 1];

			$scope.runningEval = false;

			$timeout(function() {
				window.location = "/app/results.html";
			}, 100);
		}).error(function() {
			$scope.runningEval = false;
		});
	};
<commit_msg>CLIMATE-232 - redirect to correct path for results<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
**/

// Controller for dataset parameter selection/modification
App.Controllers.controller('ParameterSelectCtrl', ['$rootScope', '$scope', '$http', '$timeout', 
						   'selectedDatasetInformation', 'regionSelectParams', 'evaluationSettings', 
function($rootScope, $scope, $http, $timeout, selectedDatasetInformation, regionSelectParams, evaluationSettings) {
	$scope.datasets = selectedDatasetInformation.getDatasets();

	// The min/max lat/lon values from the selected datasets
	$scope.latMin = -90;
	$scope.latMax = 90;
	$scope.lonMin = -180;
	$scope.lonMax = 180;
	$scope.start = "1980-01-01 00:00:00";
	$scope.end = "2030-01-01 00:00:00";

	// The min/max lat/lon values that are displayed
	$scope.displayParams = regionSelectParams.getParameters();

	$scope.runningEval = false;

	// Flag for toggling re-grid controls based on whether or not the user has selected a grid
	// base from the selected datasets. By default we have no datasets so we don't need to show
	// the controls!
	$scope.areInUserRegridState = false;

	// Initialization for the lat/lon grid step sliders
	// TODO There has to be a better way of dealing with this. Perhaps a directive??
	$scope.latSliderVal = 0;
	$scope.lonSliderVal = 0;

	$('#latSlider').slider({
		value: 0,
		step: 0.25,
		min: 0.25,
		max: 180,
		slide: function(event, ui) {
			$scope.updateLatSliderDisplayValue(ui.value);
		},
	});

	$('#lonSlider').slider({
		value: 0,
		step: 0.25,
		min: 0.25,
		max: 360,
		slide: function(event, ui) {
			$scope.updateLonSliderDisplayValue(ui.value);
		},
	});

	$scope.updateLatSliderDisplayValue = function(value) {
		$scope.latSliderVal = value;
		$scope.$apply();
	};

	$scope.updateLonSliderDisplayValue = function(value) {
		$scope.lonSliderVal = value;
		$scope.$apply();
	};

	// Settings for jQuery datepicker directives!
	$scope.datepickerSettings = {
		changeMonth: true,
		changeYear: true,
	};

	$scope.shouldDisableControls = function() {
		return (selectedDatasetInformation.getDatasetCount() < 2);
	}

	$scope.shouldDisableEvaluateButton = function() {
		return ($scope.shouldDisableControls() || $scope.runningEval);
	}

	$scope.shouldDisableResultsView = function() {
		var res = false;

		if ($rootScope.evalResults == "")
			res = true;

		return res;
	}

	$scope.runEvaluation = function() {
		$scope.runningEval = true;

		// TODO
		// Currently this has the 1 model, 1 observation format hard coded in. This shouldn't
		// be the long-term case! This needs to be changed!!!!!!!!
		var obsIndex = -1,
			modelIndex = -1;

		for (var i = 0; i < $scope.datasets.length; i++) {
			if ($scope.datasets[i]['isObs'] == 1)
				obsIndex = i;
			else
				modelIndex = i;
		}

		// TODO At the moment we aren't running all the metrics that the user selected. We're only
		// running the first available metric that the user provides. If the user un-checks all
		// metrics then the default of 'bias' is used.
		var metricToRun = 'bias';
		var settings = evaluationSettings.getSettings().metrics;
		for (var i = 0; i < settings.length; i++) {
			var setting = settings[i];

			if (setting.select) {
				metricToRun = setting.name;
				break;
			}
		};

		var data = {params: { 
			'obsDatasetId'     : $scope.datasets[obsIndex]['id'],
			'obsParameterId'   : $scope.datasets[obsIndex]['param'],
			'startTime'        : $scope.displayParams.start + " 00:00:00",
			'endTime'          : $scope.displayParams.end + " 00:00:00",
			'latMin'           : $scope.displayParams.latMin,
			'latMax'           : $scope.displayParams.latMax,
			'lonMin'           : $scope.displayParams.lonMin,
			'lonMax'           : $scope.displayParams.lonMax,
			'filelist'         : $scope.datasets[modelIndex]['id'],
			'modelVarName'     : $scope.datasets[modelIndex]['param'],
			'modelTimeVarName' : $scope.datasets[modelIndex]['time'],
			'modelLatVarName'  : $scope.datasets[modelIndex]['lat'],
			'modelLonVarName'  : $scope.datasets[modelIndex]['lon'],
			'regridOption'     : 'model',
			'timeRegridOption' : evaluationSettings.getSettings().temporal.selected,
			'metricOption'     : metricToRun,
			'callback'         : 'JSON_CALLBACK',
		}};

		$http.jsonp($rootScope.baseURL + '/rcmes/run/', data).
		success(function(data) {
			var comp = data['comparisonPath'].split('/');
			var model = data['modelPath'].split('/');
			var obs = data['obsPath'].split('/');

			$rootScope.evalResults = {};
			$rootScope.evalResults.comparisonPath = comp[comp.length - 1];
			$rootScope.evalResults.modelPath = model[model.length - 1];
			$rootScope.evalResults.obsPath = obs[obs.length - 1];

			$scope.runningEval = false;

			$timeout(function() {
				window.location = "results.html";
			}, 100);
		}).error(function() {
			$scope.runningEval = false;
		});
	};

{'fraction_non_alphanumeric': 0.1373459546347562, 'fraction_numerical': 0.016342203964993748, 'mean_word_length': 3.6507475083056478, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, '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': '2558511', 'n_tokens_mistral': 3910, 'n_tokens_neox': 3463, 'n_words': 960}