1 var JobClass = jQuery.klass({
9 initialize: function(job) {
13 set_job: function(job) {
14 if (typeof(job) == "object") {
17 this.set_start_stamp();
19 this.set_start_point();
22 alert('Job is not object');
26 set_start_point: function() {
27 var xaxis = this.start_stamp;
28 var yaxis = this.job_size;
29 this.start_point = [xaxis, yaxis];
32 set_end_point: function() {
33 var xaxis = this.end_stamp;
34 var yaxis = this.job_size;
35 this.end_point = [xaxis, yaxis];
38 set_job_size: function(unit) {
39 var units = ['Bi', 'KiB', 'MiB', 'GiB', 'TiB'];
40 var pos = units.indexOf(unit);
50 this.job_size = this.job.jobbytes / (1 << (10 * unit));
53 set_start_stamp: function() {
54 this.start_stamp = iso_date_to_timestamp(this.job.starttime);
57 set_end_stamp: function() {
58 this.end_stamp = iso_date_to_timestamp(this.job.endtime);
62 var GraphClass = jQuery.klass({
67 graph_container: null,
68 legend_container: null,
122 initialize: function(jobs, txt, container, legend, time_range, date_from, date_to, client_filter, job_filter) {
125 this.set_graph_container(container);
126 this.set_legend_container(legend);
127 this.set_time_range_filter(time_range);
128 this.set_date_from_el(date_from);
129 this.set_date_to_el(date_to);
130 this.set_date_fields_events(date_from, date_to);
131 this.set_jobs_filter(job_filter);
132 this.set_clients_filter(client_filter);
138 this.extend_graph_options();
139 this.apply_jobs_filter();
140 this.prepare_series();
144 set_jobs: function(jobs) {
145 if (typeof(jobs) == "object") {
146 if (jobs.hasOwnProperty('output')) {
148 for (var i = 0; i<jobs.output.length; i++) {
149 if(jobs.output[i].jobstatus == 'R' || jobs.output[i].jobstatus == 'C' || jobs.output[i].endtime == null) {
152 job = new JobClass(jobs.output[i]);
155 this.jobs_all = this.jobs;
160 alert('No jobs found.');
164 get_jobs: function() {
168 set_graph_container: function(id) {
169 this.graph_container = document.getElementById(id);
172 get_graph_container: function() {
173 return this.graph_container;
176 set_legend_container: function(id) {
177 this.legend_container = $('#' + id);
180 get_legend_container: function() {
181 return this.legend_container;
184 set_time_range_filter: function(id) {
186 this.time_range = $('#' + id);
187 this.time_range.on('change', function() {
188 var time_range = self.get_time_range();
189 self.set_time_range(time_range);
194 get_time_range: function() {
195 var time_range = parseInt(this.time_range[0].value, 10) * 1000;
199 set_date_from_el: function(date_from) {
200 this.date_from = $('#' + date_from);
203 get_date_from_el: function() {
204 return this.date_from;
207 set_date_to_el: function(date_to) {
208 this.date_to = $('#' + date_to);
211 get_date_to_el: function() {
215 set_time_range: function(timestamp) {
216 var to_stamp = Math.round(new Date().getTime());
217 this.set_xaxis_max(to_stamp, true);
218 var from_stamp = (Math.round(new Date().getTime()) - this.get_time_range());
219 this.set_xaxis_min(from_stamp, true);
223 set_xaxis_min: function(value, set_range) {
224 if (this.graph_options.xaxis.max && value > this.graph_options.xaxis.max) {
225 alert('Wrong time range.');
229 if (value == this.graph_options.xaxis.max) {
233 this.graph_options.xaxis.min = value;
236 var iso_date = timestamp_to_iso_date(value);
237 var from_el = this.get_date_from_el();
238 from_el[0].value = iso_date;
242 set_xaxis_max: function(value, set_range) {
243 if (value < this.graph_options.xaxis.min) {
244 alert('Wrong time range.');
248 if (value == this.graph_options.xaxis.min) {
252 this.graph_options.xaxis.max = value;
255 var iso_date = timestamp_to_iso_date(value);
256 var to_el = this.get_date_to_el();
257 to_el[0].value = iso_date;
261 set_date_fields_events: function(date_from, date_to) {
263 this.date_from = date_from;
264 this.date_to = date_to;
265 $('#' + date_from).on('change', function() {
266 var from_stamp = iso_date_to_timestamp(this.value);
267 self.set_xaxis_min(from_stamp);
271 $('#' + date_to).on('change', function() {
272 var to_stamp = iso_date_to_timestamp(this.value);
273 self.set_xaxis_max(to_stamp);
277 var date = this.get_time_range();
278 this.set_time_range(date);
281 set_clients_filter: function(client_filter) {
283 $('#' + client_filter).on('change', function() {
284 if (this.value == self.filter_all_mark) {
285 delete self.filter_include['clientid'];
287 self.filter_include['clientid'] = parseInt(this.value, 10);
293 set_jobs_filter: function(job_filter) {
295 $('#' + job_filter).on('change', function() {
296 if (this.value == self.filter_all_mark) {
297 delete self.filter_include['name'];
299 self.filter_include['name'] = this.value;
305 apply_jobs_filter: function() {
307 var jobs = this.jobs_all;
308 var filtred_jobs = [];
310 for (var i = 0; i < jobs.length; i++) {
312 jQuery.each(this.filter_include, function(key, value) {
313 if (jobs[i].hasOwnProperty(key) && jobs[i][key] != value) {
317 if (jobs[i].job.hasOwnProperty(key) && jobs[i].job[key] != value) {
322 if (to_add === true) {
323 filtred_jobs.push(jobs[i]);
327 for (var i = 0; i < filtred_jobs.length; i++) {
328 jQuery.each(this.filter_exclude, function(key, value) {
329 if (filtred_jobs[i].hasOwnProperty(key) && filtred_jobs[i][key] != value) {
332 if (filtred_jobs[i].job.hasOwnProperty(key) && filtred_jobs[i].job[key] != value) {
335 delete filtred_jobs[i];
338 this.set_jobs(filtred_jobs);
341 prepare_series: function() {
344 var series_uniq = {};
347 var jobs = this.get_jobs();
348 for (var i = 0; i < jobs.length; i++) {
349 if(jobs[i].start_stamp < this.graph_options.xaxis.min || jobs[i].end_stamp > this.graph_options.xaxis.max) {
352 if (series_uniq.hasOwnProperty(jobs[i].job.name) == false) {
353 series_uniq[jobs[i].job.name] = [];
355 series_uniq[jobs[i].job.name].push(jobs[i].start_point, jobs[i].end_point, [null, null]);
358 jQuery.each(series_uniq, function(key, value) {
360 for (var i = 0; i<value.length; i++) {
361 serie.push(value[i]);
363 self.series.push({data: serie, label: key});
367 extend_graph_options: function() {
368 this.graph_options.legend.container = this.get_legend_container();
369 this.graph_options.title = this.txt.graph_title;
370 this.graph_options.xaxis.title = this.txt.xaxis_title;
371 this.graph_options.yaxis.title = this.txt.yaxis_title;
374 draw_graph: function(opts) {
375 var options = Flotr._.extend(Flotr._.clone(this.graph_options), opts || {});
377 this.graph_obj = Flotr.draw(
378 this.get_graph_container(),
384 set_events: function() {
386 Flotr.EventAdapter.observe(this.graph_container, 'flotr:select', function(area) {
405 self.draw_graph(options);
408 Flotr.EventAdapter.observe(this.graph_container, 'flotr:click', function () {
414 var GraphPieClass = jQuery.klass({
420 colors: ['#63c422', '#d70808', '#FFFF66', 'orange', 'blue'],
422 fontColor: '#ffffff',
424 verticalLines : false,
425 horizontalLines : false,
428 xaxis: { showLabels : false,},
429 yaxis: { showLabels : false },
433 labelFormatter: PieGraph.pie_label_formatter,
440 trackFormatter: PieGraph.pie_track_formatter,
445 backgroundColor : '#D2E8FF',
449 initialize: function(jobs, container_id) {
451 this.container = document.getElementById(container_id);
452 this.series = this.prepare_series();
455 prepare_series: function() {
458 var job_types = Object.keys(this.jobs);
460 for (var i = 0; i < job_types.length; i++) {
461 label = job_types[i];
462 jobs_count = this.jobs[label].length;
464 data: [[0, jobs_count]],
465 label: label + ' (' + jobs_count.toString() + ')'
471 draw_grah: function() {
472 this.pie = Flotr.draw(this.container, this.series, this.graph_options);
476 var iso_date_to_timestamp = function(iso_date) {
477 var date_split = iso_date.split(' ');
478 var date = date_split[0].split('-');
480 var time = date_split[1].split(':');
481 var date_obj = new Date(date[0], (date[1] - 1), date[2], time[0], time[1], time[2]);
483 var date_obj = new Date(date[0], (date[1] - 1), date[2], 0, 0, 0);
485 return date_obj.getTime();
488 var timestamp_to_iso_date = function(timestamp) {
490 var date = new Date(timestamp);
492 var year = date.getFullYear();
493 var month = (date.getMonth() + 1).toString();
494 month = ('0' + month).substr(-2,2);
495 var day = date.getDate().toString();
496 day = ('0' + day).substr(-2,2);
497 var date_values = [year, month ,day];
499 var iso_date = date_values.join('-');