Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApp/clients/details/clientDetailsCtrl.js @ 12516

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

#2388:

HeuristicLab.Services.Hive.DataAccess-3.3:

  • updated daos
  • changed statistics database schema
  • updated HiveStatisticsGenerator

HeuristicLab.Services.WebApp.Statistics-3.3:

  • added jobs, client and user page
File size: 11.1 KB
Line 
1(function () {
2    var module = appStatisticsPlugin.getAngularModule();
3    module.controller('app.statistics.clientDetailsCtrl',
4        ['$scope', '$stateParams', '$interval', 'app.statistics.clientService', 'app.statistics.taskService', '$modal',
5        function ($scope, $stateParams, $interval, clientService, taskService, $modal) {
6            $scope.interval = defaultPageUpdateInterval;
7            $scope.curTaskPage = 1;
8            $scope.taskPageSize = 12;
9
10            // details
11            $scope.knobOptions = {
12                'fgColor': "#f7921d",
13                'angleOffset': -125,
14                'angleArc': 250,
15                'readOnly': true,
16                'width': "80%",
17                'targetvalue': "100",
18                'format': function (value) {
19                    return value;
20                },
21                draw: function () {
22                    $(this.i).val(this.cv + '%');
23                }
24            };
25
26            $scope.knobData = {
27                cores: 0,
28                cpu: 0,
29                memory: 0
30            };
31
32            var getClientDetails = function () {
33                clientService.getClientDetails({ id: $stateParams.id }, function (client) {
34                    $scope.client = client;
35                    $scope.client.TotalMemory = Math.round($scope.client.TotalMemory / 1024);
36                    $scope.client.UsedMemory = Math.round($scope.client.UsedMemory / 1024);
37                    $scope.knobData.cores = (client.UsedCores / client.TotalCores) * 100;
38                    $scope.knobData.cpu = client.CpuUtilization;
39                    $scope.knobData.memory = (client.UsedMemory / client.TotalMemory) * 100;
40                    $scope.client.LastUpdate = CSharpDateToString($scope.client.LastUpdate);
41                    $scope.client.UpTime = $scope.client.UpTime.toHHMMSS();
42                    $scope.client.TotalUnavailableTime = $scope.client.TotalUnavailableTime.toHHMMSS();
43                    $scope.client.TotalCalculatingTime = $scope.client.TotalCalculatingTime.toHHMMSS();
44                    $scope.client.TotalIdleTime = $scope.client.TotalIdleTime.toHHMMSS();
45                    $scope.client.TotalOfflineTime = $scope.client.TotalOfflineTime.toHHMMSS();
46                    $scope.client.TotalTransferringTime = $scope.client.TotalTransferringTime.toHHMMSS();
47
48                    var length = client.TasksStates.length;
49                    var total = 0;
50                    var jsStates = [];
51                    for (var i = 0; i < length; ++i) {
52                        var state = client.TasksStates[i];
53                        var selected = true;
54                        if (isDefined($scope.states)) {
55                            for (var j = 0; j < $scope.states.length; ++j) {
56                                if (state.State == $scope.states[j].State) {
57                                    selected = $scope.states[j].Selected;
58                                    break;
59                                }
60                            }
61                        }
62                        jsStates.push({
63                            State: state.State,
64                            Count: state.Count,
65                            Selected: selected
66                        });
67                        total += state.Count;
68                    }
69                    $scope.totalClientTasks = total;
70                    $scope.states = jsStates;
71                    getTasks();
72                });
73            };
74
75            // tasks
76            var getTasks = function () {
77                var states = [];
78                var length = $scope.states.length;
79                for (var i = 0; i < length; ++i) {
80                    var state = $scope.states[i];
81                    if (state.Selected) {
82                        states.push(state.State);
83                    }
84                }
85
86                taskService.getTasksByClientId({ id: $stateParams.id, page: $scope.curTaskPage, size: $scope.taskPageSize }, states,
87                    function (taskPage) {
88                        $scope.taskPage = taskPage;
89                        var length = $scope.taskPage.Tasks.length;
90                        for (var i = 0; i < length; ++i) {
91                            $scope.taskPage.Tasks[i].TotalTime = $scope.taskPage.Tasks[i].TotalTime.toHHMMSS();
92                            $scope.taskPage.Tasks[i].InitialWaitingTime = $scope.taskPage.Tasks[i].InitialWaitingTime.toHHMMSS();
93                            $scope.taskPage.Tasks[i].WaitingTime = $scope.taskPage.Tasks[i].WaitingTime.toHHMMSS();
94                            $scope.taskPage.Tasks[i].CalculatingTime = $scope.taskPage.Tasks[i].CalculatingTime.toHHMMSS();
95                            $scope.taskPage.Tasks[i].TransferTime = $scope.taskPage.Tasks[i].TransferTime.toHHMMSS();
96                            var startTime = $scope.taskPage.Tasks[i].StartTime;
97                            if (isDefined(startTime)) {
98                                $scope.taskPage.Tasks[i].StartTime = CSharpDateToString(startTime);
99                            } else {
100                                $scope.taskPage.Tasks[i].StartTime = 'Not started';
101                            }
102                            var endTime = $scope.taskPage.Tasks[i].EndTime;
103                            if (isDefined(endTime)) {
104                                $scope.taskPage.Tasks[i].EndTime = CSharpDateToString(endTime);
105                            } else {
106                                $scope.taskPage.Tasks[i].EndTime = 'Not finished';
107                            }
108                        }
109                    }
110                );
111            };
112
113            $scope.changeTaskPage = function () {
114                getClientDetails();
115                $('html, body').animate({
116                    scrollTop: $("#tasks-filter").offset().top
117                }, 10);
118            };
119
120            $scope.filterTaskState = function (state) {
121                state.Selected = !state.Selected;
122                $scope.curTaskPage = 1;
123                getClientDetails();
124            };
125
126            $scope.openDialog = function (taskNo, task) {
127                $scope.currentTaskNo = taskNo;
128                $scope.currentTask = task;
129                $modal.open({
130                    templateUrl: 'plugin=statistics&view=WebApp/clients/details/clientTaskDetailsDialog.cshtml',
131                    controller: 'app.statistics.clientTaskDetailsDialogCtrl',
132                    windowClass: 'app-modal-window',
133                    resolve: {
134                        task: function () {
135                            return $scope.currentTask;
136                        },
137                        taskNo: function () {
138                            return $scope.currentTaskNo;
139                        }
140                    }
141                });
142            };
143
144            // charts
145            $scope.chartOptions = {
146                grid: {
147                    borderWidth: 1,
148                    labelMargin: 15
149                },
150                series: {
151                    shadowSize: 0
152                },
153                yaxis: {
154                    min: 0,
155                    max: 100,
156                    zoomRange: false,
157                    panRange: false
158                },
159                xaxis: {
160                    mode: "time",
161                    twelveHourClock: false
162                }
163            };
164
165            $scope.fillChartOptions = {
166                grid: {
167                    borderWidth: 1,
168                    labelMargin: 15
169                },
170                series: {
171                    shadowSize: 0,
172                    lines: {
173                        show: true,
174                        fill: true
175                    }
176                },
177                yaxis: {
178                    zoomRange: false,
179                    panRange: false
180                },
181                xaxis: {
182                    mode: "time",
183                    twelveHourClock: false
184                }
185            };
186
187            $scope.fromDate = new Date();
188            $scope.toDate = new Date();
189
190            $scope.fromIsOpen = false;
191            $scope.toIsOpen = false;
192
193            $scope.openFromDateSelection = function ($event) {
194                $event.preventDefault();
195                $event.stopPropagation();
196                $scope.toIsOpen = false;
197                $scope.fromIsOpen = true;
198            };
199
200            $scope.openToDateSelection = function ($event) {
201                $event.preventDefault();
202                $event.stopPropagation();
203                $scope.fromIsOpen = false;
204                $scope.toIsOpen = true;
205            };
206
207            $scope.dateOptions = {
208                formatYear: 'yy',
209                startingDay: 1
210            };
211
212            $scope.cpuSeries = [[]];
213            $scope.coreSeries = [[]];
214            $scope.memorySeries = [[]];
215
216            $scope.updateCharts = function () {
217                clientService.getClientHistory({ id: $stateParams.id, start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
218                    var noOfStatus = status.length;
219                    var cpuSeries = [];
220                    var coreSeries = [[], []];
221                    var memorySeries = [[], []];
222                    for (var i = 0; i < noOfStatus; ++i) {
223                        var curStatus = status[i];
224                        var cpuData = Math.round(curStatus.CpuUtilization);
225                        cpuSeries.push([curStatus.Timestamp, cpuData]);
226                        coreSeries[0].push([curStatus.Timestamp, curStatus.TotalCores]);
227                        coreSeries[1].push([curStatus.Timestamp, curStatus.UsedCores]);
228                        memorySeries[0].push([curStatus.Timestamp, curStatus.TotalMemory]);
229                        memorySeries[1].push([curStatus.Timestamp, curStatus.UsedMemory]);
230                    }
231                    $scope.cpuSeries = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
232                    $scope.coreSeries = [
233                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
234                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
235                    ];
236                    $scope.memorySeries = [
237                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
238                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
239                    ];
240
241                });
242            };
243
244            var update = function () {
245                getClientDetails();
246            };
247
248            $scope.updateInterval = $interval(update, $scope.interval);
249            var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
250                $interval.cancel($scope.updateInterval);
251                cancelInterval();
252            });
253            update(); // init page
254            $scope.updateCharts();
255        }]
256    );
257})();
Note: See TracBrowser for help on using the repository browser.