Add `scenic` gem for view management
parent
2040feece1
commit
2d2d80d5cf
1
Gemfile
1
Gemfile
|
@ -28,6 +28,7 @@ gem "secure_headers"
|
||||||
gem "valid_url"
|
gem "valid_url"
|
||||||
gem "font-awesome-rails"
|
gem "font-awesome-rails"
|
||||||
gem "discard", "~> 1.0"
|
gem "discard", "~> 1.0"
|
||||||
|
gem "scenic"
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
gem "hashdiff"
|
gem "hashdiff"
|
||||||
|
|
|
@ -282,6 +282,9 @@ GEM
|
||||||
rspec-support (3.7.1)
|
rspec-support (3.7.1)
|
||||||
ruby-graphviz (1.2.3)
|
ruby-graphviz (1.2.3)
|
||||||
rubyzip (1.2.1)
|
rubyzip (1.2.1)
|
||||||
|
scenic (1.4.1)
|
||||||
|
activerecord (>= 4.0.0)
|
||||||
|
railties (>= 4.0.0)
|
||||||
secure_headers (5.0.5)
|
secure_headers (5.0.5)
|
||||||
useragent (>= 0.15.0)
|
useragent (>= 0.15.0)
|
||||||
selenium-webdriver (3.11.0)
|
selenium-webdriver (3.11.0)
|
||||||
|
@ -369,6 +372,7 @@ DEPENDENCIES
|
||||||
rollbar
|
rollbar
|
||||||
rspec
|
rspec
|
||||||
rspec-rails
|
rspec-rails
|
||||||
|
scenic
|
||||||
secure_headers
|
secure_headers
|
||||||
selenium-webdriver
|
selenium-webdriver
|
||||||
simplecov
|
simplecov
|
||||||
|
|
|
@ -59,6 +59,7 @@ class ApplicationRecord < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def broadcast!
|
def broadcast!
|
||||||
|
# `espeak "ding"`
|
||||||
AutoSyncJob.perform_later(broadcast_payload,
|
AutoSyncJob.perform_later(broadcast_payload,
|
||||||
Device.current.id,
|
Device.current.id,
|
||||||
chan_name,
|
chan_name,
|
||||||
|
|
|
@ -1,35 +1,7 @@
|
||||||
class CreateSequenceToolsView < ActiveRecord::Migration[5.1]
|
class CreateSequenceToolsView < ActiveRecord::Migration[5.1]
|
||||||
def up
|
def change
|
||||||
execute 'CREATE VIEW in_use_tools AS
|
# I goofed up on this migration and deployed to staging before I could fix.
|
||||||
SELECT
|
# See later migration that creates a new view using the `scenic` gem.
|
||||||
tools.id as tool_id,
|
|
||||||
tools.name as tool_name,
|
|
||||||
sequences.name as sequence_name,
|
|
||||||
sequences.id as sequence_id,
|
|
||||||
sequences.device_id as device_id
|
|
||||||
FROM "edge_nodes"
|
|
||||||
INNER JOIN "sequences" ON sequences.id=sequences.id
|
|
||||||
INNER JOIN "tools" ON (edge_nodes.value)::int=tools.id
|
|
||||||
WHERE "edge_nodes"."kind" = \'tool_id\';'
|
|
||||||
|
|
||||||
execute 'CREATE VIEW in_use_points AS
|
|
||||||
SELECT
|
|
||||||
points.x as x,
|
|
||||||
points.y as y,
|
|
||||||
points.z as z,
|
|
||||||
(edge_nodes.value)::int as point_id,
|
|
||||||
points.pointer_type as pointer_type,
|
|
||||||
points.name as pointer_name,
|
|
||||||
sequences.id as sequence_id,
|
|
||||||
sequences.name as sequence_name,
|
|
||||||
edge_nodes.id as edge_node_id
|
|
||||||
FROM "edge_nodes"
|
|
||||||
INNER JOIN "sequences" ON edge_nodes.sequence_id=sequences.id
|
|
||||||
INNER JOIN "points" ON (edge_nodes.value)::int=points.id
|
|
||||||
WHERE "edge_nodes"."kind" = \'pointer_id\';'
|
|
||||||
end
|
|
||||||
|
|
||||||
def down
|
|
||||||
execute "DROP VIEW IF EXISTS in_use_tools;"
|
execute "DROP VIEW IF EXISTS in_use_tools;"
|
||||||
execute "DROP VIEW IF EXISTS in_use_points;"
|
execute "DROP VIEW IF EXISTS in_use_points;"
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
class CreateInUseResources < ActiveRecord::Migration[5.1]
|
||||||
|
# I goofed up on this migration and deployed to staging before I could fix.
|
||||||
|
# See later migration that creates a new view using the `scenic` gem. - RC
|
||||||
|
def up
|
||||||
|
execute "DROP VIEW IF EXISTS in_use_tools;"
|
||||||
|
execute "DROP VIEW IF EXISTS in_use_points;"
|
||||||
|
|
||||||
|
create_view :in_use_tools
|
||||||
|
create_view :in_use_points
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
drop_view :in_use_tools
|
||||||
|
drop_view :in_use_points
|
||||||
|
end
|
||||||
|
end
|
31
db/schema.rb
31
db/schema.rb
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20180410180929) do
|
ActiveRecord::Schema.define(version: 20180410192539) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -483,4 +483,33 @@ ActiveRecord::Schema.define(version: 20180410180929) do
|
||||||
add_foreign_key "sensor_readings", "devices"
|
add_foreign_key "sensor_readings", "devices"
|
||||||
add_foreign_key "sensors", "devices"
|
add_foreign_key "sensors", "devices"
|
||||||
add_foreign_key "token_issuances", "devices"
|
add_foreign_key "token_issuances", "devices"
|
||||||
|
|
||||||
|
create_view "in_use_tools", sql_definition: <<-SQL
|
||||||
|
SELECT tools.id AS tool_id,
|
||||||
|
tools.name AS tool_name,
|
||||||
|
sequences.name AS sequence_name,
|
||||||
|
sequences.id AS sequence_id,
|
||||||
|
sequences.device_id
|
||||||
|
FROM ((edge_nodes
|
||||||
|
JOIN sequences ON ((sequences.id = sequences.id)))
|
||||||
|
JOIN tools ON (((edge_nodes.value)::integer = tools.id)))
|
||||||
|
WHERE ((edge_nodes.kind)::text = 'tool_id'::text);
|
||||||
|
SQL
|
||||||
|
|
||||||
|
create_view "in_use_points", sql_definition: <<-SQL
|
||||||
|
SELECT points.x,
|
||||||
|
points.y,
|
||||||
|
points.z,
|
||||||
|
(edge_nodes.value)::integer AS point_id,
|
||||||
|
points.pointer_type,
|
||||||
|
points.name AS pointer_name,
|
||||||
|
sequences.id AS sequence_id,
|
||||||
|
sequences.name AS sequence_name,
|
||||||
|
edge_nodes.id AS edge_node_id
|
||||||
|
FROM ((edge_nodes
|
||||||
|
JOIN sequences ON ((edge_nodes.sequence_id = sequences.id)))
|
||||||
|
JOIN points ON (((edge_nodes.value)::integer = points.id)))
|
||||||
|
WHERE ((edge_nodes.kind)::text = 'pointer_id'::text);
|
||||||
|
SQL
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
41
db/seeds.rb
41
db/seeds.rb
|
@ -9,8 +9,8 @@ unless Rails.env == "production"
|
||||||
LogDispatch.destroy_all
|
LogDispatch.destroy_all
|
||||||
|
|
||||||
User.destroy_all
|
User.destroy_all
|
||||||
POINT_COUNT = 2
|
POINT_COUNT = 8
|
||||||
PLANT_COUNT = 2
|
PLANT_COUNT = 8
|
||||||
DATE_RANGE_LO = 1..3
|
DATE_RANGE_LO = 1..3
|
||||||
DATE_RANGE_HI = 3..8
|
DATE_RANGE_HI = 3..8
|
||||||
ENV['MQTT_HOST'] = "blooper.io"
|
ENV['MQTT_HOST'] = "blooper.io"
|
||||||
|
@ -51,29 +51,26 @@ unless Rails.env == "production"
|
||||||
end
|
end
|
||||||
|
|
||||||
PLANT_COUNT.times do
|
PLANT_COUNT.times do
|
||||||
Point.create(
|
Plant.create(device: u.device,
|
||||||
device: u.device,
|
x: rand(40...970),
|
||||||
x: rand(40...970),
|
y: rand(40...470),
|
||||||
y: rand(40...470),
|
radius: rand(10...50),
|
||||||
radius: rand(10...50),
|
name: Faker::StarWars.call_sign,
|
||||||
name: Faker::StarWars.call_sign,
|
pointer_id: 0,
|
||||||
pointer: Plant.new(
|
openfarm_slug: ["tomato", "carrot", "radish", "garlic"].sample)
|
||||||
openfarm_slug: ["tomato", "carrot", "radish", "garlic"].sample
|
|
||||||
))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
POINT_COUNT.times do
|
POINT_COUNT.times do
|
||||||
Point.create(
|
GenericPointer.create(device: u.device,
|
||||||
device: u.device,
|
x: rand(40...970) + rand(40...970),
|
||||||
x: rand(40...970) + rand(40...970),
|
y: rand(40...470) + rand(40...470),
|
||||||
y: rand(40...470) + rand(40...470),
|
z: 5,
|
||||||
z: 5,
|
radius: (rand(1...150) + rand(1...150)) / 20,
|
||||||
radius: (rand(1...150) + rand(1...150)) / 20,
|
pointer_id: 0,
|
||||||
pointer: GenericPointer.new(),
|
meta: {
|
||||||
meta: {
|
created_by: "plant-detection",
|
||||||
created_by: "plant-detection",
|
color: (Sequence::COLORS + [nil]).sample
|
||||||
color: (Sequence::COLORS + [nil]).sample
|
})
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
s = Sequences::Create.run!(device: u.device,
|
s = Sequences::Create.run!(device: u.device,
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
SELECT
|
||||||
|
points.x as x,
|
||||||
|
points.y as y,
|
||||||
|
points.z as z,
|
||||||
|
(edge_nodes.value)::int as point_id,
|
||||||
|
points.pointer_type as pointer_type,
|
||||||
|
points.name as pointer_name,
|
||||||
|
sequences.id as sequence_id,
|
||||||
|
sequences.name as sequence_name,
|
||||||
|
edge_nodes.id as edge_node_id
|
||||||
|
FROM "edge_nodes"
|
||||||
|
INNER JOIN "sequences" ON edge_nodes.sequence_id=sequences.id
|
||||||
|
INNER JOIN "points" ON (edge_nodes.value)::int=points.id
|
||||||
|
WHERE "edge_nodes"."kind" = 'pointer_id';
|
|
@ -0,0 +1,10 @@
|
||||||
|
SELECT
|
||||||
|
tools.id as tool_id,
|
||||||
|
tools.name as tool_name,
|
||||||
|
sequences.name as sequence_name,
|
||||||
|
sequences.id as sequence_id,
|
||||||
|
sequences.device_id as device_id
|
||||||
|
FROM "edge_nodes"
|
||||||
|
INNER JOIN "sequences" ON sequences.id=sequences.id
|
||||||
|
INNER JOIN "tools" ON (edge_nodes.value)::int=tools.id
|
||||||
|
WHERE "edge_nodes"."kind" = 'tool_id';
|
Loading…
Reference in New Issue