Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
wattsworth
/
lumen-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2cafc01f
authored
Feb 23, 2021
by
John Donnal
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
automatically calculate data extents, fixed json parameter wrapping
parent
d13452e6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
7 deletions
app/services/data/load_element_data.rb
config/initializers/wrap_parameters.rb
spec/cassettes/LoadElementData/when_boundary_times_are_not_specified/updates_the_streams.yml
spec/services/data/load_element_data_spec.rb
app/services/data/load_element_data.rb
View file @
2cafc01f
...
...
@@ -93,6 +93,45 @@ class LoadElementData
#5 extract requested elements from the stream datasets
req_element_ids
=
elements
.
pluck
(
: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
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
config/initializers/wrap_parameters.rb
View file @
2cafc01f
...
...
@@ -5,7 +5,7 @@
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport
.
on_load
(
:action_controller
)
do
wrap_parameters
format:
[
:json
]
wrap_parameters
format:
[]
end
# To enable root element in JSON for ActiveRecord objects.
...
...
spec/cassettes/LoadElementData/when_boundary_times_are_not_specified/updates_the_streams.yml
View file @
2cafc01f
...
...
@@ -520,7 +520,7 @@ http_interactions:
recorded_at
:
Tue, 06 Jun 2017 16:35:20 GMT
-
request
:
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
:
encoding
:
US-ASCII
string
:
'
'
...
...
@@ -557,7 +557,44 @@ http_interactions:
recorded_at
:
Tue, 06 Jun 2017 16:35:20 GMT
-
request
:
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
:
encoding
:
US-ASCII
string
:
'
'
...
...
@@ -2580,7 +2617,7 @@ http_interactions:
recorded_at
:
Tue, 06 Jun 2017 16:35:20 GMT
-
request
:
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
:
encoding
:
US-ASCII
string
:
'
'
...
...
@@ -2617,7 +2654,7 @@ http_interactions:
recorded_at
:
Tue, 06 Jun 2017 16:35:20 GMT
-
request
:
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
:
encoding
:
US-ASCII
string
:
'
'
...
...
spec/services/data/load_element_data_spec.rb
View file @
2cafc01f
...
...
@@ -119,8 +119,10 @@ RSpec.describe 'LoadElementData' do
service
=
LoadElementData
.
new
service
.
run
([
elem1
,
elem2
],
nil
,
nil
)
#bounds taken from test nilm on vagrant instance
# expect(service.start_time).to eq(1360017784000000)
# expect(service.end_time).to eq(1435438182000001)
# ac-power: [1434408933000000 - 1435437553316406]
# pump: [1360018080779512 - 1361579475621010]
expect
(
service
.
start_time
).
to
eq
(
1360018080779512
)
expect
(
service
.
end_time
).
to
eq
(
1435437553316406
)
#make sure decimations are still here
expect
(
elem1
.
db_stream
.
reload
.
db_decimations
.
count
).
to
eq
ndecims1
expect
(
elem2
.
db_stream
.
reload
.
db_decimations
.
count
).
to
eq
ndecims2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment