Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApp/groups/details/groupDetailsCtrl.js @ 12778

Last change on this file since 12778 was 12778, checked in by dglaser, 9 years ago

#2388:

HeuristicLab.Services.WebApp.Statistics-3.3:

  • Added QuickSelection button to the client and group pag

HeuristicLab.Services.WebApp-3.3:
HeuristicLab.Services.WebApp.Statistics-3.3:

  • Changed 'User Name' to 'Username' to be consistent throughout the whole WebApp
File size: 8.1 KB
Line 
1(function () {
2    var module = appStatisticsPlugin.getAngularModule();
3    module.controller('app.statistics.groupDetailsCtrl',
4        ['$scope', '$stateParams', '$interval', 'app.statistics.clientService', 'app.statistics.groupService',
5        function ($scope, $stateParams, $interval, clientService, groupService) {
6            $scope.interval = defaultPageUpdateInterval;
7            $scope.curClientsPage = 1;
8            $scope.clientsPageSize = 20;
9
10
11            // details
12            $scope.knobOptions = {
13                'fgColor': "#f7921d",
14                'angleOffset': -125,
15                'angleArc': 250,
16                'readOnly': true,
17                'width': "80%",
18                'targetvalue': "100",
19                'format': function (value) {
20                    return value;
21                },
22                draw: function () {
23                    $(this.i).val(this.cv + '%');
24                }
25            };
26
27            $scope.knobData = {
28                cores: 0,
29                cpu: 0,
30                memory: 0
31            };
32
33            var getGroupDetails = function() {
34                groupService.getGroupDetails({ id: $stateParams.id }, function (group) {
35                    $scope.group = group;
36                    $scope.knobData.cores = (group.UsedCores / group.TotalCores) * 100;
37                    $scope.knobData.cpu = group.ActiveCpuUtilization;
38                    $scope.knobData.memory = (group.UsedMemory / group.TotalMemory) * 100;
39
40                    var length = group.TasksStates.length;
41                    var total = 0;
42                    for (var i = 0; i < length; ++i) {
43                        total += group.TasksStates[i].Count;
44                    }
45                    $scope.totalGroupTasks = total;
46                });
47            };
48
49            var getClients = function () {
50                clientService.getClientsByGroupId({id: $stateParams.id, page: $scope.curClientsPage, size: $scope.clientsPageSize, expired: false },
51                    function (clientPage) {
52                        $scope.clientPage = clientPage;
53                    }
54                );
55            };
56
57            // charts
58            $scope.chartOptions = {
59                grid: {
60                    borderWidth: 1,
61                    labelMargin: 15
62                },
63                series: {
64                    shadowSize: 0
65                },
66                yaxis: {
67                    min: 0,
68                    max: 100,
69                    zoomRange: false,
70                    panRange: false
71                },
72                xaxis: {
73                    mode: "time",
74                    twelveHourClock: false
75                }
76            };
77
78            $scope.fillChartOptions = {
79                grid: {
80                    borderWidth: 1,
81                    labelMargin: 15
82                },
83                series: {
84                    shadowSize: 0,
85                    lines: {
86                        show: true,
87                        fill: true
88                    }
89                },
90                yaxis: {
91                    zoomRange: false,
92                    panRange: false
93                },
94                xaxis: {
95                    mode: "time",
96                    twelveHourClock: false
97                }
98            };
99
100            $scope.fromDate = new Date();
101            $scope.toDate = new Date();
102
103            $scope.fromIsOpen = false;
104            $scope.toIsOpen = false;
105
106            $scope.quickSelectionList = [
107                { id: 0, name: 'Custom' },
108                { id: 1, name: 'Today' },
109                { id: 2, name: 'Yesterday' },
110                { id: 3, name: 'Last 7 Days' },
111                { id: 4, name: 'Last 30 Days' }
112            ];
113            $scope.changeQuickSelection = function (quickSelection) {
114                var today = new Date();
115                var oneDayInMs = 24 * 60 * 60 * 1000;
116                switch (quickSelection.id) {
117                    case 1:
118                        $scope.fromDate = new Date(today.valueOf());
119                        $scope.toDate = new Date(today.valueOf());
120                        break;
121                    case 2:
122                        $scope.fromDate = new Date(today.valueOf() - oneDayInMs);
123                        $scope.toDate = new Date(today.valueOf() - oneDayInMs);
124                        break;
125                    case 3:
126                        $scope.fromDate = new Date(today.valueOf() - (7 * oneDayInMs));
127                        $scope.toDate = new Date(today.valueOf());
128                        break;
129                    case 4:
130                        $scope.fromDate = new Date(today.valueOf() - (30 * oneDayInMs));
131                        $scope.toDate = new Date(today.valueOf());
132                        break;
133                }
134                $scope.curQuickSelection = quickSelection;
135            };
136            // set default 'today'
137            $scope.changeQuickSelection($scope.quickSelectionList[1]);
138
139            $scope.openFromDateSelection = function ($event) {
140                $event.preventDefault();
141                $event.stopPropagation();
142                $scope.toIsOpen = false;
143                $scope.fromIsOpen = true;
144                $scope.curQuickSelection = $scope.quickSelectionList[0];
145            };
146
147            $scope.openToDateSelection = function ($event) {
148                $event.preventDefault();
149                $event.stopPropagation();
150                $scope.fromIsOpen = false;
151                $scope.toIsOpen = true;
152                $scope.curQuickSelection = $scope.quickSelectionList[0];
153            };
154
155            $scope.dateOptions = {
156                formatYear: 'yy',
157                startingDay: 1
158            };
159
160            $scope.cpuSeries = [[]];
161            $scope.coreSeries = [[]];
162            $scope.memorySeries = [[]];
163
164            $scope.updateCharts = function () {
165                clientService.getClientHistoryByGroupId({ id: $stateParams.id, start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
166                    var noOfStatus = status.length;
167                    var cpuSeries = [];
168                    var coreSeries = [[], []];
169                    var memorySeries = [[], []];
170                    for (var i = 0; i < noOfStatus; ++i) {
171                        var curStatus = status[i];
172                        var cpuData = Math.round(curStatus.CpuUtilization);
173                        cpuSeries.push([curStatus.Timestamp, cpuData]);
174                        coreSeries[0].push([curStatus.Timestamp, curStatus.TotalCores]);
175                        coreSeries[1].push([curStatus.Timestamp, curStatus.UsedCores]);
176                        memorySeries[0].push([curStatus.Timestamp, curStatus.TotalMemory]);
177                        memorySeries[1].push([curStatus.Timestamp, curStatus.UsedMemory]);
178                    }
179                    $scope.cpuSeries = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
180                    $scope.coreSeries = [
181                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
182                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
183                    ];
184                    $scope.memorySeries = [
185                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
186                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
187                    ];
188
189                });
190            };
191
192            var update = function () {
193                getGroupDetails();
194                getClients();
195            };
196
197            $scope.updateInterval = $interval(update, $scope.interval);
198            var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
199                $interval.cancel($scope.updateInterval);
200                cancelInterval();
201            });
202            update(); // init page
203            $scope.updateCharts();
204        }]
205    );
206})();
Note: See TracBrowser for help on using the repository browser.