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
b5809eab
authored
May 27, 2017
by
John Doe
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
improved data loading performance
parent
750579a7
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
17 deletions
app/adapters/db_adapter.rb
app/services/data/load_element_data.rb
app/services/data/load_stream_data.rb
config/routes.rb
spec/controllers/db_elements_controller_spec.rb
app/adapters/db_adapter.rb
View file @
b5809eab
...
...
@@ -73,8 +73,8 @@ class DbAdapter
path:
entry
[
0
],
attributes:
{
data_type:
entry
[
1
],
start_time:
entry
[
2
]
||
0
,
end_time:
entry
[
3
]
||
0
,
start_time:
entry
[
2
],
end_time:
entry
[
3
],
total_rows:
entry
[
4
],
total_time:
entry
[
5
]
}.
merge
(
metadata
),
...
...
app/services/data/load_element_data.rb
View file @
b5809eab
...
...
@@ -59,10 +59,8 @@ class LoadElementData
req_streams
.
each
do
|
stream
|
adapter
=
DbAdapter
.
new
(
stream
.
db
.
url
)
data_service
=
LoadStreamData
.
new
(
adapter
)
time
=
Benchmark
.
measure
do
data_service
.
run
(
stream
,
@start_time
,
@end_time
,
elements
.
to_a
)
end
puts
"------ DataService
#{
time
}
"
data_service
.
run
(
stream
,
@start_time
,
@end_time
,
elements
.
to_a
)
if
data_service
.
success?
combined_data
.
concat
(
data_service
.
data
)
else
...
...
app/services/data/load_stream_data.rb
View file @
b5809eab
...
...
@@ -64,6 +64,7 @@ class LoadStreamData
@decimation_factor
=
plottable_decim
.
level
path
=
__build_path
(
db_stream
,
plottable_decim
.
level
)
resp
=
@db_adapter
.
get_data
(
path
,
start_time
,
end_time
)
if
resp
.
nil?
add_error
(
"cannot get data for [
#{
path
}
] @
#{
@db_adapter
.
url
}
"
)
return
self
...
...
@@ -77,11 +78,9 @@ class LoadStreamData
decimateable_elements
=
elements
.
select
{
|
e
|
%w(continuous discrete)
.
include?
e
.
display_type
}
interval_elements
=
elements
.
select
{
|
e
|
e
.
display_type
==
'event'
}
time
=
Benchmark
.
measure
do
@data
=
__build_decimated_data
(
decimateable_elements
,
resp
)
+
__build_intervals_from_decimated_data
(
interval_elements
,
resp
)
end
puts
"---- [LoadStreamData] Build Dataset
#{
time
}
"
@data
=
__build_decimated_data
(
decimateable_elements
,
resp
)
+
__build_intervals_from_decimated_data
(
interval_elements
,
resp
)
end
self
end
...
...
config/routes.rb
View file @
b5809eab
...
...
@@ -19,7 +19,7 @@ Rails.application.routes.draw do
end
resources
:db_elements
,
only:
[
:index
]
do
collection
do
pos
t
'data'
ge
t
'data'
end
end
...
...
spec/controllers/db_elements_controller_spec.rb
View file @
b5809eab
...
...
@@ -4,7 +4,7 @@ require 'rails_helper'
RSpec
.
describe
DbElementsController
,
type: :request
do
let
(
:user1
)
{
create
(
:user
,
first_name:
'John'
)
}
let
(
:user2
)
{
create
(
:user
,
first_name:
'Sam'
)
}
describe
'
POS
T #data'
do
describe
'
GE
T #data'
do
# retrieve data for elements listed by array of ids
context
'with authenticated user'
do
before
do
...
...
@@ -31,7 +31,7 @@ RSpec.describe DbElementsController, type: :request do
allow
(
LoadElementData
).
to
receive
(
:new
).
and_return
(
@mock_service
)
@auth_headers
=
user1
.
create_new_auth_token
pos
t
'/db_elements/data.json'
,
ge
t
'/db_elements/data.json'
,
params:
{
elements:
[
@elem1
.
id
,
@elem2
.
id
].
to_json
,
start_time:
0
,
end_time:
100
,
redux_json:
'new home view'
},
headers:
@auth_headers
...
...
@@ -44,7 +44,7 @@ RSpec.describe DbElementsController, type: :request do
end
it
'returns error if time bounds are invalid'
do
@auth_headers
=
user1
.
create_new_auth_token
pos
t
'/db_elements/data.json'
,
ge
t
'/db_elements/data.json'
,
params:
{
elements:
[
@elem1
.
id
,
@elem2
.
id
].
to_json
,
start_time:
100
,
end_time:
0
},
headers:
@auth_headers
...
...
@@ -59,7 +59,7 @@ RSpec.describe DbElementsController, type: :request do
stream2
.
db_elements
<<
@elem3
@auth_headers
=
user1
.
create_new_auth_token
pos
t
'/db_elements/data.json'
,
ge
t
'/db_elements/data.json'
,
params:
{
elements:
[
@elem1
.
id
,
@elem3
.
id
].
to_json
,
start_time:
100
,
end_time:
0
},
headers:
@auth_headers
...
...
@@ -68,7 +68,7 @@ RSpec.describe DbElementsController, type: :request do
end
context
'without sign-in'
do
it
'returns unauthorized'
do
pos
t
'/db_elements/data.json'
ge
t
'/db_elements/data.json'
expect
(
response
).
to
have_http_status
(
:unauthorized
)
end
end
...
...
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