]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/JavaScript/statistics.js
b211691fa39f142894758ec8448173c434035b57
[bacula/bacula] / gui / baculum / protected / JavaScript / statistics.js
1 var Statistics = {
2         jobs: null,
3         clients: null,
4         pools: null,
5         jobtotals: null,
6         dbsize: null,
7         clients_occupancy: {},
8         pools_occupancy: {},
9         jobs_summary: [],
10         grab_statistics: function(data, jobstates) {
11                 this.jobs = data.jobs;
12                 this.clients = data.clients;
13                 this.pools = data.pools;
14                 this.jobtotals = data.jobtotals;
15                 this.dbsize = data.dbsize;
16                 var jobs_count = this.jobs.length;
17                 var clients_occupancy = {};
18                 var pools_occupancy = {};
19                 var jobs_occupancy = {};
20                 var jobs_summary = {
21                         ok: [],
22                         error: [],
23                         warning: [],
24                         cancel: [],
25                         running: []
26                 };
27                 var status_type;
28                 for (var i = 0; i < jobs_count; i++) {
29                         if (typeof(clients_occupancy[this.jobs[i].clientid]) === 'undefined') {
30                                 clients_occupancy[this.jobs[i].clientid] = 1;
31                         } else {
32                                 clients_occupancy[this.jobs[i].clientid] += 1;
33                         }
34
35                         if (typeof(pools_occupancy[this.jobs[i].poolid]) === 'undefined') {
36                                 pools_occupancy[this.jobs[i].poolid] = 1;
37                         } else {
38                                 pools_occupancy[this.jobs[i].poolid] += 1;
39                         }
40
41                         if (typeof(jobs_occupancy[this.jobs[i].name]) === 'undefined') {
42                                 jobs_occupancy[this.jobs[i].name] = 1;
43                         } else {
44                                 jobs_occupancy[this.jobs[i].name] += 1;
45                         }
46                         if (jobstates.hasOwnProperty(this.jobs[i].jobstatus)) {
47                                 status_type = jobstates[this.jobs[i].jobstatus].type;
48                                 if (status_type == 'ok' && this.jobs[i].joberrors > 0) {
49                                         status_type = 'warning';
50                                 }
51                                 jobs_summary[status_type].push(this.jobs[i]);
52                         }
53                 }
54                 var clients_ids = Object.keys(clients_occupancy);
55                 for (var i = 0; i < clients_ids.length; i++) {
56                         for (var j = 0; j < this.clients.length; j++) {
57                                 if (clients_ids[i] == this.clients[j].clientid) {
58                                         this.clients_occupancy[this.clients[j].name] = clients_occupancy[clients_ids[i]];
59                                 }
60                         }
61                 }
62
63                 var pools_ids = Object.keys(pools_occupancy);
64                 for (var i = 0; i < pools_ids.length; i++) {
65                         for (var j = 0; j < this.pools.length; j++) {
66                                 if (pools_ids[i] == this.pools[j].poolid) {
67                                         this.pools_occupancy[this.pools[j].name] = pools_occupancy[pools_ids[i]];
68                                 }
69                         }
70                 }
71
72                 this.jobs_occupancy = jobs_occupancy;
73                 this.jobs_summary = jobs_summary;
74         }
75 }