-
Notifications
You must be signed in to change notification settings - Fork 5
/
iot.mocked.js
129 lines (122 loc) · 3.26 KB
/
iot.mocked.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const SENSORS = {
'sensor-1': {
name: 'Living Room',
description: 'Basic sensor in the middle of the living room.',
groupName: 'Level 1',
location: {
x: 31.92,
y: 11.49,
z: -12.97
},
objectId: 4124
},
'sensor-2': {
name: 'Dining Table',
description: 'Basic sensor at the dining table.',
groupName: 'Level 1',
location: {
x: -10,
y: 41.64,
z: -12.15
},
objectId: 4111
},
'sensor-3': {
name: 'Kitchen',
description: 'Basic sensor in the kitchen.',
groupName: 'Level 1',
location: {
x: 10,
y: 41.64,
z: -12.15
},
objectId: 4111
},
'sensor-4': {
name: 'Bedroom',
description: 'Basic sensor in the bedroom.',
groupName: 'Level 2',
location: {
x: -7.46,
y: 41.47,
z: 2.97
},
objectId: 4085
}
};
const CHANNELS = {
'temp': {
name: 'Temperature',
description: 'External temperature in degrees Celsius.',
type: 'double',
unit: '°C',
min: 18.0,
max: 28.0
},
'co2': {
name: 'CO₂',
description: 'Level of carbon dioxide.',
type: 'double',
unit: 'ppm',
min: 482.81,
max: 640.00
}
};
async function getSensors() {
return SENSORS;
}
async function getChannels() {
return CHANNELS;
}
async function getSamples(timerange, resolution = 32) {
return {
count: resolution,
timestamps: generateTimestamps(timerange.start, timerange.end, resolution),
data: {
'sensor-1': {
'temp': generateRandomValues(18.0, 28.0, resolution, 1.0),
'co2': generateRandomValues(540.0, 600.0, resolution, 5.0)
},
'sensor-2': {
'temp': generateRandomValues(20.0, 24.0, resolution, 1.0),
'co2': generateRandomValues(540.0, 600.0, resolution, 5.0)
},
'sensor-3': {
'temp': generateRandomValues(24.0, 28.0, resolution, 1.0),
'co2': generateRandomValues(500.0, 620.0, resolution, 5.0)
},
'sensor-4': {
'temp': generateRandomValues(20.0, 24.0, resolution, 1.0),
'co2': generateRandomValues(600.0, 640.0, resolution, 5.0)
}
}
};
}
function generateTimestamps(start, end, count) {
const delta = Math.floor((end.getTime() - start.getTime()) / (count - 1));
const timestamps = [];
for (let i = 0; i < count; i++) {
timestamps.push(new Date(start.getTime() + i * delta));
}
return timestamps;
}
function generateRandomValues(min, max, count, maxDelta) {
const values = [];
let lastValue = min + Math.random() * (max - min);
for (let i = 0; i < count; i++) {
values.push(lastValue);
lastValue += (Math.random() - 0.5) * 2.0 * maxDelta;
if (lastValue > max) {
lastValue = max;
}
if (lastValue < min) {
lastValue = min;
}
}
return values;
}
module.exports = {
getSensors,
getChannels,
getSamples
};