-
Notifications
You must be signed in to change notification settings - Fork 12
/
dummy_data.rb
228 lines (202 loc) · 5.61 KB
/
dummy_data.rb
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
require 'faraday'
require 'json'
require 'yaml'
### Variables
@cid = 1 # Current User's id
CONF = YAML.load_file('config/config.yml')['development']
### Functions
def new_connection
conn = Faraday.new(:url => "#{CONF['API_URL']}/users/#{@cid}/") do |faraday|
faraday.request :url_encoded # form-encode POST params
faraday.response :logger # log requests to STDOUT
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
end
conn
end
def send_data(method, url, json)
conn = new_connection
conn.send(method) do |req|
req.url url
req.headers['Content-Type'] = 'application/json'
req.body = json
end
end
def post_resource json
url = "#{CONF['API_URL']}/resources/"
send_data(:post, url, json)
end
def put_resource rid, json
url = "#{CONF['API_URL']}/resources/" + rid
send_data(:put, url, json)
end
def post_stream rid, json
url = "#{CONF['API_URL']}/users/#{@cid}/resources/" + rid + "/streams/"
send_data(:post, url, json)
end
def put_stream rid, sid, json
url = "#{CONF['API_URL']}/users/#{@cid}/resources/" + rid + "/streams/" + sid
send_data(:put, url, json)
end
def deleteResources
url = "http://srv1.csproj13.student.it.uu.se:9200/sensorcloud/resource"
send_data(:delete, url, nil)
end
### Generate data elements in ES
def generate_resources
[
{
:name => "Weather Uppsala 1",
:description => "Sensor which measures the weather in different places from Uppsala",
:manufacturer => "Ericsson",
:model => "ee80",
# :make => "2",
# :serial_num => "1234-ABCD-987",
# :polling_freq => "60",
# :data_overview => "data data data",
# :location => "Uppsala, Sweden",
# :uri => "http =>//sensors.ericsson.se",
:tags => "temperature, weather, humidity, ericsson",
:resource_type => "sensor",
:active => "true",
:user_id => @cid
},
{
:name => "Weather Uppsala 2",
:description => "Sensor which measures the weather in Uppsala",
:manufacturer => "Ericsson",
:model => "ef90",
# :make => "2",
# :serial_num => "5678-ABCD-987",
# :polling_freq => "60",
# :resource_type => "sensor",
# :data_overview => "data data data",
# :location => "Uppsala, Sweden",
# :uri => "http =>//sensors.ericsson.se",
:tags => "temperature, weather, humidity, ericsson",
:resource_type => "sensor",
:active => "true",
:user_id => @cid
},
{
:name => "Siemens si5",
:description => "Sensor which measures the pollution",
:manufacturer => "Siemens",
:model => "s7",
# :make => "1",
# :serial_num => "1679-FGD-987",
# :polling_freq => "60",
# :resource_type => "sensor",
# :data_overview => "data data data",
# :location => "Stockholm, Sweden",
# :uri => "http =>//sensors.siemens.se",
:tags => "pollution, air, siemens",
:resource_type => "sensor",
:active => "true",
:user_id => @cid
}
]
end
def generate_streams
[
{
:name => "Temperature",
:description => "Uppsala Centrum",
:accuracy => "70",
:min_val => "-40",
:max_val => "100",
:longitude => "60",
:latitude => "18",
:stream_type => "temperature",
:user_ranking => "20",
:history_size => "100",
:subscribers => "78",
:tags => "temperature, uppsala, centrum",
:active => "true",
:private => "false"
},
{
:name => "Temperature",
:description => "Flogsta",
:accuracy => "70",
:min_val => "-40",
:max_val => "100",
:longitude => "60",
:latitude => "18",
:stream_type => "temperature",
:user_ranking => "20",
:history_size => "100",
:subscribers => "78",
:tags => "temperature, uppsala, centrum",
:active => "true",
:private => "true"
},
{
:name => "Temperature",
:description => "Kantorsgatan",
:accuracy => "70",
:min_val => "-40",
:max_val => "100",
:longitude => "60",
:latitude => "18",
:stream_type => "temperature",
:user_ranking => "20",
:history_size => "100",
:subscribers => "78",
:tags => "temperature, uppsala, kantorsgatan",
:active => "false",
:private => "false"
},
{
:name => "Humidity",
:description => "Uppsala Centrum",
:accuracy => "100",
:min_val => "0",
:max_val => "100",
:longitude => "60",
:latitude => "18",
:stream_type => "humidity",
:user_ranking => "20",
:history_size => "100",
:subscribers => "56",
:tags => "humidity, uppsala, centrum",
:active => "true",
:private => "false"
},
{
:name => "Pollution",
:description => "Engelska Park",
:accuracy => "100",
:min_val => "0",
:max_val => "400",
:longitude => "60",
:latitude => "18",
:stream_type => "pollution",
:user_ranking => "20",
:history_size => "100",
:subscribers => "56",
:tags => "pollution, engelska, park",
:active => "true",
:private => "false"
},
]
end
def createResource number, streamsList
resources = generate_resources
streams = generate_streams
r = resources[number]
puts "JSON: #{r.to_json}"
res = post_resource r.to_json
puts "RES: #{res.body}"
if res.status == 200
streamsList.each do |sNumber|
s = streams[sNumber]
rid = JSON.parse(res.body)['_id']
puts "RID: #{rid}"
post_stream rid, s.to_json
end
end
end
# deleteResources
createResource 0, [0,1,2]
createResource 1, [0,3]
createResource 2, [4]