-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.js
86 lines (74 loc) · 3.12 KB
/
utility.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
function Utility() {
this.initializeData = function (scope,uuid) {
scope.data[uuid]={temp:[],hum:[],light:[],gyro:[],acc:[],mag:[],name:'', currTempC:'', currTempF:'', currHum:'', currLight:'', currGyro:'', currAcc:'', currMag:''};
this.initializeSingleData(scope,'temp','Temperature',uuid);
this.initializeSingleData(scope,'hum','Humidity',uuid);
this.initializeSingleData(scope, 'light','Light',uuid);
this.initializeTripleData(scope,'gyro',uuid);
this.initializeTripleData(scope, 'acc',uuid);
this.initializeTripleData(scope, 'mag',uuid);
};
this.initializeSingleData = function(scope,item,name,uuid) {
scope.data[uuid][item] = [{ values: [], key: name, color: '#2287c1' }];
};
this.initializeTripleData = function(scope,item,uuid) {
scope.data[uuid][item] = [{ values: [], key: 'x',color: '#2287c1' },{ values: [], key: 'y',color: '#b3e5fc' },{ values: [], key: 'z',color: '#fbae20' }];
};
this.pushSingleData = function(time, value, label, data) {
data[0].values.push(
{
x: time,
y: value,
label: label
}
);
};
this.pushTripleData = function(time, value, label, data) {
for (var i=0; i<3; i++){
data[i].values.push(
{
x: time,
y: value[i],
label: label
}
)
}
};
this.handleData = function(data) {
for (var i = 0, len = data.values.length; i < len; i++) {
data.values[i].x = data.values[i].x - 1;
}
if (data.values[data.values.length - 2]) {
if ((data.values[data.values.length - 1].label) == ( data.values[data.values.length - 2].label)) {
data.values.pop();
}
}
if (Math.abs(data.values[0].x) > 299) {
data.values.shift();
}
};
this.handleTripleData = function(data) {
this.handleData(data[0]);
this.handleData(data[1]);
this.handleData(data[2]);
};
this.preapareSingleGraph = function(inputData,outputData){
if (!isNaN(inputData.timeNum) && !isNaN(inputData.value)) {
this.pushSingleData(inputData.timeNum,inputData.value,inputData.date,outputData);
this.handleData(outputData[0]);
}
};
this.prepareLightData = function(inputData,outputData) {
if (!isNaN(inputData.timeNum) && !isNaN(inputData.value[0])) {
this.pushSingleData(inputData.timeNum, inputData.value[0], inputData.date, outputData);
this.handleData(outputData[0]);
}
};
this.prepareTripleGraph = function(inputData,outputData) {
if (!isNaN(inputData.timeNum) && !isNaN(inputData.value[0]) && !isNaN(inputData.value[1]) && !isNaN(inputData.value[2])) {
this.pushTripleData(inputData.timeNum,inputData.value,inputData.date,outputData);
this.handleTripleData(outputData);
}
};
return this;
}