Free cookie consent management tool by TermsFeed Policy Generator

source: branches/WebJobManager/HeuristicLab.Clients.Hive.WebJobManager/Scripts/Hubs/GraphDataCollector.js @ 16264

Last change on this file since 16264 was 13860, checked in by jlodewyc, 9 years ago

#2582 RC2 migration fixed. OKB query implemented. Preparing for OKB manager

File size: 9.6 KB
Line 
1/* HeuristicLab
2 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
3 *
4 * This file is part of HeuristicLab.
5 *
6 * HeuristicLab is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * HeuristicLab is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21//Keeps all the data for the job. Used to communicate through SignalR
22var dataCollection = [];
23//Possible task statusses
24var taskStatus = {
25    "Offline": "bar-off",
26    "Waiting": "bar-wait",
27    "Transferring": "bar-trans",
28    "Calculating": "bar-calc",
29    "Paused": "bar-paus",
30    "Finished": "bar-fin",
31    "Aborted": "bar-abo",
32    "Failed": "bar-fail"
33}
34
35
36function initSaveData(id, coll, name) {//initial data save
37    var temp = dataConversion(coll, name);
38    temp.unshift(id); //add ID in front of array
39    dataCollection.push(temp);// [id,timearr, piearr]
40    // console.log("#CREATION: " + id);
41}
42//Saves updated info in dataCollection
43function saveData(id, coll, name) {
44    var temp = dataConversion(coll, name);
45    for (var i = 0; i < dataCollection.length; i++) {
46        if (dataCollection[i][0] == id) {
47            dataCollection[i][1] = temp[0]; // [data,layout]
48            dataCollection[i][2] = temp[1]; // data
49            dataCollection[i][3] = temp[2]; // [tasks, name]
50        }
51    }
52    redrawGraph(id);
53}
54//Returns data for line graph
55//DISABLED FOR GANTT CHART
56/*
57function getData(id) {
58    for (var i = 0; i < dataCollection.length; i++) {
59        if (dataCollection[i][0] == id) {
60            return dataCollection[i][1];
61        }
62    }
63}*/
64//Returns data needed for Pie chart
65function getDataPie(id) {
66    for (var i = 0; i < dataCollection.length; i++) {
67        if (dataCollection[i][0] == id) {
68            return dataCollection[i][2];
69        }
70    }
71}
72//Returns data needed for Gantt chart
73function getDataGantt(id) {
74    for (var i = 0; i < dataCollection.length; i++) {
75        if (dataCollection[i][0] == id) {
76            return dataCollection[i][3];
77        }
78    }
79}
80//Converts received data from server to data needed for the graphs
81function dataConversion(coll, name) {
82    //var line = dataConversionLine(coll, name);
83    var pie = dataConversionPie(coll);
84    var gantt = dataConversionGantt(coll, name);
85    return [null, pie, gantt];
86}
87//Creates all data needed for drawing a single Gantt chart for one task
88function dataConversionGantt(coll, nam) {
89    var tasks = [];
90    for (var v = 0; v < coll.length; v++) {
91
92        var temp = {};
93        temp.startDate = Date.parse(coll[v].DateTime);
94        if (v < coll.length - 1)
95            temp.endDate = Date.parse(coll[v + 1].DateTime);
96        else {
97
98            var dat = Date.parse(coll[v].DateTime);
99            //console.log(dat);
100            temp.endDate = dat + 600000;
101            temp.last = true;
102        }
103        temp.taskName = nam;
104
105        if (coll[v].State == 0)
106            temp.status = "Offline";
107        else if (coll[v].State == 1)
108            temp.status = "Waiting";
109        else if (coll[v].State == 2)
110            temp.status = "Transferring";
111        else if (coll[v].State == 3)
112            temp.status = "Calculating";
113        else if (coll[v].State == 4)
114            temp.status = "Paused";
115        else if (coll[v].State == 5)
116            temp.status = "Finished";
117        else if (coll[v].State == 6)
118            temp.status = "Aborted";
119        else if (coll[v].State == 7)
120            temp.status = "Failed";
121        tasks.push(temp);
122    }
123    return [tasks, nam];
124}
125/* DISABLED FOR GANTT CHART
126function dataConversionLine(coll, nam) {
127    var xarr = [];
128    var yarr = [];
129
130    for (var v = 0; v < coll.length; v++) {
131
132        xarr.push(Date.parse(coll[v].DateTime));
133        // console.log(xarr[v]);
134        // xarr[v] = xarr[v] - 3600000;
135        if (coll[v].State == 1)
136            yarr.push("Waiting");
137        else if (coll[v].State == 2)
138            yarr.push("Transferring");
139        else if (coll[v].State == 3)
140            yarr.push("Calculating");
141        else if (coll[v].State == 5)
142            yarr.push("Finished");
143        else if (coll[v].State == 7)
144            yarr.push("Failed");
145    }
146
147
148    var data = [{//Time graph
149        x: xarr,
150        y: yarr,
151        type: 'scatter',
152        mode: 'lines',
153        name: nam,
154        connectgaps: true,
155        line: { shape: 'hvh' }
156    }];
157    layout = {
158        "showlegend": true,
159        "width": "100%",
160        "xaxis": {
161            "autorange": true,
162            "range": [
163                Date.parse(coll[0].DateTime),
164                Date.parse(coll[coll.length - 1].DateTime)
165            ],
166            "title": "Time",
167            "type": "date"
168        }
169
170    }
171
172    return [data, layout];
173}*/
174//Calculates data necessary for drawing  a pie chart for a single task.
175function dataConversionPie(coll) {
176    var waiting = 0;
177    var transfer = 0;
178    var calc = 0;
179    for (var v = 0; v < coll.length - 1; v++) {
180        if (coll[v].State == 1)
181            waiting += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
182        else if (coll[v].State == 2)
183            transfer += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
184        else if (coll[v].State == 3)
185            calc += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
186    }
187    var datap = [{//Pie graph
188        values: [
189            Math.round(waiting / 1000 / 60),
190            Math.round(transfer / 1000 / 60),
191            Math.round(calc / 1000 / 60)],
192        labels: [
193            'Minutes waiting',
194            'Minutes transferring',
195            'Minutes calculating'],
196        type: 'pie',
197        marker: {
198            colors: ['#f0a742', '#80d4ff', '#2f6fa6']
199        }
200    }];
201    return datap;
202}
203
204//Draws and redraws a graph from a single task
205function redrawGraph(val) {
206    document.getElementById("graph" + val).style.width = "100%";
207    document.getElementById("graph" + val).style.height = "400px";
208    document.getElementById("graph" + val).innerHTML = "";
209    document.getElementById("graph" + val).style.marginLeft = "0px";
210    if (document.getElementById("graphtoggle" + val).checked)
211    {//Redraws a Gantt chart
212        setTimeout(function () {
213
214            var temp = getDataGantt(val);
215            var w = $("#graph" + val).parent().width() - 30;
216            document.getElementById("graph" + val).style.height = "300px";
217            var gantt = d3.gantt().selector('#graph' + val).height('200').width(w).margin({
218                top: 20,
219                right: 40,
220                bottom: 20,
221                left: 20
222            }).drawytitles(false).taskTypes([temp[1]]).taskStatus(taskStatus);
223            gantt(temp[0]);
224           document.getElementById("legend" + val).style.display = "";
225        }, 100);
226
227
228        /* DISABLED FOR GANTT CHART
229        setTimeout(function () {
230            Plotly.newPlot('graph' + val, getData(val)[0], getData(val)[1]);
231        }, 100);*/
232    }
233    else
234    {//Redraws a pie chart
235        document.getElementById("legend" + val).style.display = "none";
236        setTimeout(function () {
237            Plotly.newPlot('graph' + val, getDataPie(val));
238        }, 100);
239    }
240
241
242}
243//Draws and redraws the main Gantt chart. Taking info from the single task charts
244//And combining these into one big chart
245function redrawMain() {
246    document.getElementById("graphMain").innerHTML = "";
247
248    var tempdata = [];
249    var tempnames = [];
250    for (var i = 0; i < dataCollection.length; i++) {
251        var t = dataCollection[i][3][0].slice();
252        var name =  t[0].taskName.substring(0, 5) + " | " + (i+1);
253
254        for (var v = 0; v < t.length; v++) {
255            t[v].taskName = name;
256        }
257        tempdata = tempdata.concat(t);
258        tempnames = tempnames.concat(name)
259    }
260    var h = (tempnames.length * 20) + 100;
261    document.getElementById("graphMain").style.height = h + "px";
262
263    var w = $("#graphMain").parent().width() - 100;
264
265    var gantt = d3.gantt().selector("#graphMain").height(h - 50).width(w).taskTypes(tempnames).taskStatus(taskStatus);
266    document.getElementById("graphMain").style.marginLeft = "20px";
267    gantt(tempdata);
268
269
270    /* LINE VERSION
271    var temp = [];
272    var min = dataCollection[0][1][0][0].x[0];
273    var max = min;
274    for (var i = 0; i < dataCollection.length; i++) {
275        temp.push(dataCollection[i][1][0][0]);
276        if (dataCollection[i][1][0][0].x[dataCollection[i][1][0][0].x.length - 1] > max)
277            max = dataCollection[i][1][0][0].x[dataCollection[i][1][0][0].x.length - 1];
278        if (dataCollection[i][1][0][0].x[0] < min)
279            min = dataCollection[i][1][0][0].x[0];
280    }
281    layout = {
282        "showlegend": true,
283        "title": new Date(min).toUTCString() + " to " + new Date(max).toUTCString(),
284        "xaxis": {
285            "autorange": true,
286            "range": [
287                min,
288                max
289            ],
290            "title": "Time",
291            "type": "date"
292        }
293
294    }
295     Plotly.newPlot('graphMain', temp, layout);
296     */
297
298}
Note: See TracBrowser for help on using the repository browser.