github.com/justinjmoses/evergreen@v0.0.0-20170530173719-1d50e381ff0d/public/static/js/scheduler_stats.js (about) 1 mciModule.controller('SchedulerStatsCtrl', function($scope, $http, $window, $filter) { 2 var url = '/scheduler/stats/utilization'; 3 $scope.userTz = $window.userTz; 4 5 // granularitySeconds represents the amount of seconds in a given bucket 6 $scope.granularitySeconds = [ 7 {display: "day", value: 24 * 60 * 60, format:"MM/DD"}, 8 {display: "hour", value: 60 * 60, format:"H:mm"}, 9 {display: "minute", value: 60, format:"H:mm"}, 10 ]; 11 $scope.currentGranularity = $scope.granularitySeconds[1]; 12 13 $scope.numberDays = [ 14 {display: "1 day", value: "1"}, 15 {display: "1 week", value: 7}, 16 {display: "2 weeks", value: 14}, 17 {display: "1 month",value: 30}, 18 {display: "2 Months", value: 60}, 19 {display: "3 months", value: 90} 20 ]; 21 $scope.currentNumberDays = $scope.numberDays[0]; 22 23 $scope.utilizationData = {}; 24 25 // disableDays sets the buttons to be disabled if the the granularity is a minute and 26 // there are too many days to load. 27 $scope.disableDays = function(numberDays){ 28 if ($scope.currentGranularity.display== "minute") { 29 if (numberDays.value >= 30) { 30 return true; 31 } 32 } 33 return false; 34 } 35 $scope.getHostUtilizationData = function(){ 36 var query = "granularity=" + encodeURIComponent($scope.currentGranularity.value) + 37 "&numberDays=" + encodeURIComponent($scope.currentNumberDays.value) 38 $http.get(url + "?" + query) 39 .success(function(data){ 40 $scope.utilizationData = data.reverse(); 41 }) 42 .error(function(data, status){ 43 console.log(status) 44 }); 45 }; 46 47 $scope.setNumberDays = function(numberDays){ 48 $scope.currentNumberDays = numberDays; 49 $scope.getHostUtilizationData(); 50 } 51 $scope.setGranularity = function(granularity){ 52 $scope.currentGranularity = granularity; 53 $scope.getHostUtilizationData(); 54 } 55 56 $scope.getPercentUtilization = function(data){ 57 if (data.static_host.total_time == 0 && data.dynamic_host.total_time == 0){ 58 return 0; 59 } 60 return (data.task/(data.static_host + data.dynamic_host)* 100).toFixed(2); 61 }; 62 63 64 $scope.getHostUtilizationData(); 65 });