1 | var dataCollection = [];
|
---|
2 |
|
---|
3 | function initSaveData(id, coll) {//initial data save
|
---|
4 | var temp = dataConversion(coll);
|
---|
5 | temp.unshift(id); //add ID in front of array
|
---|
6 | dataCollection.push(temp);// [id,timearr, piearr]
|
---|
7 | console.log("#CREATION: " + id);
|
---|
8 | }
|
---|
9 | function saveData(id, coll) {
|
---|
10 | var temp = dataConversion(coll);
|
---|
11 | for (var i = 0; i < dataCollection.length; i++) {
|
---|
12 | if (dataCollection[i][0] == id) {
|
---|
13 | dataCollection[i][1] = temp[0];
|
---|
14 | dataCollection[i][2] = temp[1];
|
---|
15 | }
|
---|
16 | }
|
---|
17 | console.log("#SAVEDATA: " + id);
|
---|
18 | redrawGraph(id);
|
---|
19 | }
|
---|
20 | function getData(id) {
|
---|
21 | for (var i = 0; i < dataCollection.length; i++) {
|
---|
22 | if (dataCollection[i][0] == id) {
|
---|
23 | return dataCollection[i][1];
|
---|
24 | }
|
---|
25 | }
|
---|
26 | }
|
---|
27 | function getDataPie(id) {
|
---|
28 | for (var i = 0; i < dataCollection.length; i++) {
|
---|
29 | if (dataCollection[i][0] == id) {
|
---|
30 | return dataCollection[i][2];
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | }
|
---|
35 | function dataConversion(coll) {
|
---|
36 | var xarr = [];
|
---|
37 | var yarr = [];
|
---|
38 | var waiting = 0;
|
---|
39 | var transfer = 0;
|
---|
40 | var calc = 0;
|
---|
41 | for (var v = 0; v < coll.length; v++) {
|
---|
42 | xarr.push(coll[v].DateTime.substr(11, 8));
|
---|
43 | if (coll[v].State == 1) {
|
---|
44 | yarr.push("Waiting");
|
---|
45 | if (v < (coll.length - 1))
|
---|
46 | waiting += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
|
---|
47 | }
|
---|
48 | else if (coll[v].State == 2) {
|
---|
49 | yarr.push("Transferring");
|
---|
50 | if (v < (coll.length - 1))
|
---|
51 | transfer += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
|
---|
52 | }
|
---|
53 | else if (coll[v].State == 3) {
|
---|
54 | yarr.push("Calculating");
|
---|
55 | if (v < (coll.length - 1))
|
---|
56 | calc += Date.parse(coll[v + 1].DateTime) - Date.parse(coll[v].DateTime);
|
---|
57 | }
|
---|
58 | else if (coll[v].State == 5)
|
---|
59 | yarr.push("Finished");
|
---|
60 | else if (coll[v].State == 7)
|
---|
61 | yarr.push("Failed");
|
---|
62 | }
|
---|
63 | var data = [{//Time graph
|
---|
64 | x: xarr,
|
---|
65 | y: yarr,
|
---|
66 | type: 'scatter'
|
---|
67 | }];
|
---|
68 | var datap = [{//Pie graph
|
---|
69 | values: [
|
---|
70 | Math.round(waiting / 1000 / 60),
|
---|
71 | Math.round(transfer / 1000 / 60),
|
---|
72 | Math.round(calc / 1000 / 60)],
|
---|
73 | labels: [
|
---|
74 | 'Minutes waiting',
|
---|
75 | 'Minutes transferring',
|
---|
76 | 'Minutes calculating'],
|
---|
77 | type: 'pie'
|
---|
78 | }];
|
---|
79 | return [data, datap];
|
---|
80 | }
|
---|
81 |
|
---|
82 | function redrawGraph(val) {
|
---|
83 | if (document.getElementById("graphtoggle" + val).checked) {
|
---|
84 | setTimeout(function () {
|
---|
85 | Plotly.newPlot('graph' + val, getData(val));
|
---|
86 | }, 100);
|
---|
87 | console.log("#REDRAWN LINE: " + val);
|
---|
88 | } else {
|
---|
89 | setTimeout(function () {
|
---|
90 | Plotly.newPlot('graph' + val, getDataPie(val));
|
---|
91 | }, 100);
|
---|
92 | console.log("#REDRAWN PIE: " + val);
|
---|
93 | }
|
---|
94 |
|
---|
95 | } |
---|