1 var JobClass = Class.create({
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 = Class.create({
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 job = new JobClass(jobs.output[i]);
152 this.jobs_all = this.jobs;
157 alert('No jobs found.');
161 get_jobs: function() {
165 set_graph_container: function(id) {
166 this.graph_container = $(id);
169 get_graph_container: function() {
170 return this.graph_container;
173 set_legend_container: function(id) {
174 this.legend_container = $(id);
177 get_legend_container: function() {
178 return this.legend_container;
181 set_time_range_filter: function(id) {
183 this.time_range = $(id);
184 $(this.time_range).observe('change', function() {
185 var time_range = self.get_time_range();
186 self.set_time_range(time_range);
191 get_time_range: function() {
192 var time_range = parseInt(this.time_range.value, 10) * 1000;
196 set_date_from_el: function(date_from) {
197 this.date_from = $(date_from);
200 get_date_from_el: function() {
201 return this.date_from;
204 set_date_to_el: function(date_to) {
205 this.date_to = $(date_to);
208 get_date_to_el: function() {
212 set_time_range: function(timestamp) {
213 var to_stamp = Math.round(new Date().getTime());
214 this.set_xaxis_max(to_stamp, true);
215 var from_stamp = (Math.round(new Date().getTime()) - this.get_time_range());
216 this.set_xaxis_min(from_stamp, true);
220 set_xaxis_min: function(value, set_range) {
221 if (this.graph_options.xaxis.max && value > this.graph_options.xaxis.max) {
222 alert('Wrong time range.');
226 if (value == this.graph_options.xaxis.max) {
230 this.graph_options.xaxis.min = value;
233 var iso_date = timestamp_to_iso_date(value);
234 var from_el = this.get_date_from_el();
235 $(from_el).value = iso_date;
239 set_xaxis_max: function(value, set_range) {
240 if (value < this.graph_options.xaxis.min) {
241 alert('Wrong time range.');
245 if (value == this.graph_options.xaxis.min) {
249 this.graph_options.xaxis.max = value;
252 var iso_date = timestamp_to_iso_date(value);
253 var to_el = this.get_date_to_el();
254 $(to_el).value = iso_date;
258 set_date_fields_events: function(date_from, date_to) {
260 this.date_from = date_from;
261 this.date_to = date_to;
262 $(date_from).observe('change', function() {
263 var from_stamp = iso_date_to_timestamp(this.value);
264 self.set_xaxis_min(from_stamp);
268 $(date_to).observe('change', function() {
269 var to_stamp = iso_date_to_timestamp(this.value);
270 self.set_xaxis_max(to_stamp);
274 var date = this.get_time_range();
275 this.set_time_range(date);
278 set_clients_filter: function(client_filter) {
280 $(client_filter).observe('change', function() {
281 if (this.value == self.filter_all_mark) {
282 delete self.filter_include['clientid'];
284 self.filter_include['clientid'] = parseInt(this.value, 10);
290 set_jobs_filter: function(job_filter) {
292 $(job_filter).observe('change', function() {
293 if (this.value == self.filter_all_mark) {
294 delete self.filter_include['name'];
296 self.filter_include['name'] = this.value;
302 apply_jobs_filter: function() {
304 var jobs = this.jobs_all;
305 var filtred_jobs = [];
307 for (var i = 0; i < jobs.length; i++) {
309 $H(this.filter_include).each(function(pair) {
310 if (jobs[i].hasOwnProperty(pair.key) && jobs[i][pair.key] != pair.value) {
314 if (jobs[i].job.hasOwnProperty(pair.key) && jobs[i].job[pair.key] != pair.value) {
319 if (to_add === true) {
320 filtred_jobs.push(jobs[i]);
324 for (var i = 0; i < filtred_jobs.length; i++) {
325 $H(this.filter_exclude).each(function(pair) {
326 if (filtred_jobs[i].hasOwnProperty(pair.key) && filtred_jobs[i][pair.key] != pair.value) {
329 if (filtred_jobs[i].job.hasOwnProperty(pair.key) && filtred_jobs[i].job[pair.key] != pair.value) {
332 delete filtred_jobs[i];
335 this.set_jobs(filtred_jobs);
338 prepare_series: function() {
341 var series_uniq = {};
344 var jobs = this.get_jobs();
345 for (var i = 0; i < jobs.length; i++) {
346 if(jobs[i].start_stamp < this.graph_options.xaxis.min || jobs[i].end_stamp > this.graph_options.xaxis.max) {
349 if (series_uniq.hasOwnProperty(jobs[i].job.name) == false) {
350 series_uniq[jobs[i].job.name] = [];
352 series_uniq[jobs[i].job.name].push(jobs[i].start_point, jobs[i].end_point, [null, null]);
355 $H(series_uniq).each(function(pair) {
357 for (var i = 0; i<pair.value.length; i++) {
358 serie.push(pair.value[i]);
360 self.series.push({data: serie, label: pair.key});
364 extend_graph_options: function() {
365 this.graph_options.legend.container = this.get_legend_container();
366 this.graph_options.title = this.txt.graph_title;
367 this.graph_options.xaxis.title = this.txt.xaxis_title;
368 this.graph_options.yaxis.title = this.txt.yaxis_title;
371 draw_graph: function(opts) {
372 var options = Flotr._.extend(Flotr._.clone(this.graph_options), opts || {});
374 this.graph_obj = Flotr.draw(
375 this.get_graph_container(),
381 set_events: function() {
383 Flotr.EventAdapter.observe(this.graph_container, 'flotr:select', function(area) {
402 self.draw_graph(options);
405 Flotr.EventAdapter.observe(this.graph_container, 'flotr:click', function () {
412 var iso_date_to_timestamp = function(iso_date) {
413 var date_split = iso_date.split(' ');
414 var date = date_split[0].split('-');
416 var time = date_split[1].split(':');
417 var date_obj = new Date(date[0], (date[1] - 1), date[2], time[0], time[1], time[2]);
419 var date_obj = new Date(date[0], (date[1] - 1), date[2], 0, 0, 0);
421 return date_obj.getTime();
424 var timestamp_to_iso_date = function(timestamp) {
426 var date = new Date(timestamp);
428 var year = date.getFullYear();
429 var month = (date.getMonth() + 1).toString();
430 month = ('0' + month).substr(-2,2);
431 var day = date.getDate().toString();
432 day = ('0' + day).substr(-2,2);
433 var date_values = [year, month ,day];
435 var iso_date = date_values.join('-');