Commit 2cafc01f by John Donnal

automatically calculate data extents, fixed json parameter wrapping

parent d13452e6
...@@ -93,6 +93,45 @@ class LoadElementData ...@@ -93,6 +93,45 @@ class LoadElementData
#5 extract requested elements from the stream datasets #5 extract requested elements from the stream datasets
req_element_ids = elements.pluck(:id) req_element_ids = elements.pluck(:id)
@data = combined_data.select{|d| req_element_ids.include? d[:id] } @data = combined_data.select{|d| req_element_ids.include? d[:id] }
#6 set the time boundaries if they were nil
@start_time = @start_time.nil? ? _data_start : @start_time
@end_time = @end_time.nil? ? _data_end : @end_time
self self
end end
def _data_start
min_start = nil
@data.each do |data|
# find the first row of data (interval boundaries are nil)
start_idx = 0
while start_idx < data[:values].count
break unless data[:values][start_idx].nil?
start_idx +=1
end
start_row=data[:values][start_idx]
unless start_row.nil?
data_start = start_row[0]
min_start = min_start.nil? ? data_start : [data_start,min_start].min
end
end
min_start
end
def _data_end
max_end = nil
@data.each do |data|
# find the last row of data (interval boundaries are nil)
end_idx = data[:values].count-1
while end_idx >=0
break unless data[:values][end_idx].nil?
end_idx -=1
end
last_row=data[:values][end_idx]
unless last_row.nil?
data_end = last_row[0]
max_end = max_end.nil? ? data_end : [data_end,max_end].max
end
end
max_end
end
end end
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json] wrap_parameters format: []
end end
# To enable root element in JSON for ActiveRecord objects. # To enable root element in JSON for ActiveRecord objects.
......
...@@ -520,7 +520,7 @@ http_interactions: ...@@ -520,7 +520,7 @@ http_interactions:
recorded_at: Tue, 06 Jun 2017 16:35:20 GMT recorded_at: Tue, 06 Jun 2017 16:35:20 GMT
- request: - request:
method: get method: get
uri: http://localhost:8080/nilmdb/stream/extract?count=1&end=1435438182000001&path=/tutorial/ac-power&start=1360017784000000 uri: http://localhost:8080/nilmdb/stream/extract?count=1&path=/tutorial/ac-power
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
...@@ -557,7 +557,44 @@ http_interactions: ...@@ -557,7 +557,44 @@ http_interactions:
recorded_at: Tue, 06 Jun 2017 16:35:20 GMT recorded_at: Tue, 06 Jun 2017 16:35:20 GMT
- request: - request:
method: get method: get
uri: http://localhost:8080/nilmdb/stream/extract?end=1435438182000001&markup=1&path=/tutorial/ac-power~decim-256&start=1360017784000000 uri: http://localhost:8080/nilmdb/stream/extract?count=1&path=/tutorial/ac-power~decim-256
body:
encoding: US-ASCII
string: ''
headers:
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- Ruby
response:
status:
code: 200
message: OK
headers:
Date:
- Tue, 06 Jun 2017 16:35:20 GMT
Server:
- Apache/2.4.18 (Ubuntu)
X-Jim-Is-Awesome:
- yeah
Allow:
- GET, HEAD
Content-Length:
- '7'
Content-Type:
- text/plain;charset=utf-8
body:
encoding: UTF-8
string: '506
'
http_version:
recorded_at: Tue, 06 Jun 2017 16:35:20 GMT
- request:
method: get
uri: http://localhost:8080/nilmdb/stream/extract?markup=1&path=/tutorial/ac-power~decim-256
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
...@@ -2580,7 +2617,7 @@ http_interactions: ...@@ -2580,7 +2617,7 @@ http_interactions:
recorded_at: Tue, 06 Jun 2017 16:35:20 GMT recorded_at: Tue, 06 Jun 2017 16:35:20 GMT
- request: - request:
method: get method: get
uri: http://localhost:8080/nilmdb/stream/extract?count=1&end=1435438182000001&path=/tutorial/pump-events&start=1360017784000000 uri: http://localhost:8080/nilmdb/stream/extract?count=1&path=/tutorial/pump-events
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
...@@ -2617,7 +2654,7 @@ http_interactions: ...@@ -2617,7 +2654,7 @@ http_interactions:
recorded_at: Tue, 06 Jun 2017 16:35:20 GMT recorded_at: Tue, 06 Jun 2017 16:35:20 GMT
- request: - request:
method: get method: get
uri: http://localhost:8080/nilmdb/stream/extract?end=1435438182000001&markup=1&path=/tutorial/pump-events&start=1360017784000000 uri: http://localhost:8080/nilmdb/stream/extract?markup=1&path=/tutorial/pump-events
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
......
...@@ -119,8 +119,10 @@ RSpec.describe 'LoadElementData' do ...@@ -119,8 +119,10 @@ RSpec.describe 'LoadElementData' do
service = LoadElementData.new service = LoadElementData.new
service.run([elem1,elem2], nil, nil) service.run([elem1,elem2], nil, nil)
#bounds taken from test nilm on vagrant instance #bounds taken from test nilm on vagrant instance
# expect(service.start_time).to eq(1360017784000000) # ac-power: [1434408933000000 - 1435437553316406]
# expect(service.end_time).to eq(1435438182000001) # pump: [1360018080779512 - 1361579475621010]
expect(service.start_time).to eq(1360018080779512)
expect(service.end_time).to eq(1435437553316406)
#make sure decimations are still here #make sure decimations are still here
expect(elem1.db_stream.reload.db_decimations.count).to eq ndecims1 expect(elem1.db_stream.reload.db_decimations.count).to eq ndecims1
expect(elem2.db_stream.reload.db_decimations.count).to eq ndecims2 expect(elem2.db_stream.reload.db_decimations.count).to eq ndecims2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment