add gantry_mounted attribute to ToolSlot
parent
74ed1ec296
commit
8eeac7e957
|
@ -254,13 +254,19 @@ module Devices
|
||||||
mode: mode)
|
mode: mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_tool_slot(name, x, y, z, pullout_direction = ToolSlot::POSITIVE_X, gantry_mount = false)
|
def add_tool_slot(name,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
z,
|
||||||
|
pullout_direction = ToolSlot::POSITIVE_X,
|
||||||
|
gantry_mounted = false)
|
||||||
Points::Create.run!(pointer_type: "ToolSlot",
|
Points::Create.run!(pointer_type: "ToolSlot",
|
||||||
name: name,
|
name: name,
|
||||||
x: x,
|
x: x,
|
||||||
y: y,
|
y: y,
|
||||||
z: z,
|
z: z,
|
||||||
pullout_direction: pullout_direction,
|
pullout_direction: pullout_direction,
|
||||||
|
gantry_mounted: gantry_mounted,
|
||||||
device: device)
|
device: device)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -18,43 +18,44 @@ module Points
|
||||||
# Smaller bed = higher resolution.
|
# Smaller bed = higher resolution.
|
||||||
POINT_HARD_LIMIT = 1000 # Can't exceed this.
|
POINT_HARD_LIMIT = 1000 # Can't exceed this.
|
||||||
POINT_SOFT_LIMIT = (POINT_HARD_LIMIT * 0.8).to_i
|
POINT_SOFT_LIMIT = (POINT_HARD_LIMIT * 0.8).to_i
|
||||||
BAD_TOOL_ID = "Can't find tool with id %s"
|
BAD_TOOL_ID = "Can't find tool with id %s"
|
||||||
DEFAULT_NAME = "Untitled %s"
|
DEFAULT_NAME = "Untitled %s"
|
||||||
KINDS = Point::POINTER_KINDS
|
KINDS = Point::POINTER_KINDS
|
||||||
GETTING_CLOSE = "Your account is "\
|
GETTING_CLOSE = "Your account is " \
|
||||||
"approaching the allowed point limit of "\
|
"approaching the allowed point limit of " \
|
||||||
"#{POINT_HARD_LIMIT}. Consider deleting old"\
|
"#{POINT_HARD_LIMIT}. Consider deleting old" \
|
||||||
" points to avoid adverse performance."
|
" points to avoid adverse performance."
|
||||||
TOO_MANY = "Your device has hit the "\
|
TOO_MANY = "Your device has hit the " \
|
||||||
"max limit for point usage (currently "\
|
"max limit for point usage (currently " \
|
||||||
"#{POINT_HARD_LIMIT}). Please delete unused"\
|
"#{POINT_HARD_LIMIT}). Please delete unused" \
|
||||||
" map points and plants to create more "
|
" map points and plants to create more "
|
||||||
BAD_POINTER_TYPE = \
|
BAD_POINTER_TYPE =
|
||||||
"Please provide a JSON object with a `poin"\
|
"Please provide a JSON object with a `poin" \
|
||||||
"ter_type` that matches one of the followi"\
|
"ter_type` that matches one of the followi" \
|
||||||
"ng values: #{KINDS.join(", ")}"
|
"ng values: #{KINDS.join(", ")}"
|
||||||
|
|
||||||
required do
|
required do
|
||||||
float :x
|
float :x
|
||||||
float :y
|
float :y
|
||||||
float :z, default: 0
|
float :z, default: 0
|
||||||
model :device, class: Device
|
model :device, class: Device
|
||||||
string :pointer_type
|
string :pointer_type
|
||||||
end
|
end
|
||||||
|
|
||||||
optional do
|
optional do
|
||||||
hstore :meta
|
hstore :meta
|
||||||
float :radius, default: 25
|
float :radius, default: 25
|
||||||
integer :pullout_direction,
|
integer :pullout_direction,
|
||||||
min: ToolSlot::PULLOUT_DIRECTIONS.min,
|
min: ToolSlot::PULLOUT_DIRECTIONS.min,
|
||||||
max: ToolSlot::PULLOUT_DIRECTIONS.max
|
max: ToolSlot::PULLOUT_DIRECTIONS.max
|
||||||
integer :tool_id, empty: true
|
integer :tool_id, empty: true
|
||||||
string :name
|
string :name
|
||||||
string :openfarm_slug, default: "not-set"
|
string :openfarm_slug, default: "not-set"
|
||||||
string :plant_stage,
|
string :plant_stage,
|
||||||
in: CeleryScriptSettingsBag::PLANT_STAGES
|
in: CeleryScriptSettingsBag::PLANT_STAGES
|
||||||
time :created_at # TODO: Are we still using this?
|
time :created_at # TODO: Are we still using this?
|
||||||
time :planted_at, default: 0
|
time :planted_at, default: 0
|
||||||
|
boolean :gantry_mounted
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate
|
def validate
|
||||||
|
@ -68,18 +69,18 @@ module Points
|
||||||
klass_.create!(inputs)
|
klass_.create!(inputs)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def validate_resource_count
|
def validate_resource_count
|
||||||
actual = \
|
actual =
|
||||||
Point.where(device_id: device.id).count
|
Point.where(device_id: device.id).count
|
||||||
case actual
|
case actual
|
||||||
when POINT_SOFT_LIMIT
|
when POINT_SOFT_LIMIT
|
||||||
device.points.discarded.delete_all
|
device.points.discarded.delete_all
|
||||||
device.tell(GETTING_CLOSE % { actual: actual }, ["fatal_email"])
|
device.tell(GETTING_CLOSE % { actual: actual }, ["fatal_email"])
|
||||||
when POINT_HARD_LIMIT...nil
|
when POINT_HARD_LIMIT...nil
|
||||||
device.points.discarded.delete_all
|
device.points.discarded.delete_all
|
||||||
add_error(:point_limit, :point_limit, TOO_MANY)
|
add_error(:point_limit, :point_limit, TOO_MANY)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class ToolSlotSerializer < BasePointSerializer
|
class ToolSlotSerializer < BasePointSerializer
|
||||||
attributes :tool_id, :pullout_direction
|
attributes :tool_id, :pullout_direction, :gantry_mounted
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class AddGantryMountedToToolSlots < ActiveRecord::Migration[5.2]
|
||||||
|
safety_assured
|
||||||
|
def change
|
||||||
|
add_column :points, :gantry_mounted, :boolean, default: false
|
||||||
|
end
|
||||||
|
end
|
|
@ -746,7 +746,8 @@ CREATE TABLE public.points (
|
||||||
tool_id integer,
|
tool_id integer,
|
||||||
pullout_direction integer DEFAULT 0,
|
pullout_direction integer DEFAULT 0,
|
||||||
migrated_at timestamp without time zone,
|
migrated_at timestamp without time zone,
|
||||||
discarded_at timestamp without time zone
|
discarded_at timestamp without time zone,
|
||||||
|
gantry_mounted boolean DEFAULT false
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2960,6 +2961,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20190419052844'),
|
('20190419052844'),
|
||||||
('20190419174728'),
|
('20190419174728'),
|
||||||
('20190419174811'),
|
('20190419174811'),
|
||||||
('20190501143201');
|
('20190501143201'),
|
||||||
|
('20190502163453');
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'spec_helper'
|
require "spec_helper"
|
||||||
|
|
||||||
describe Points::Create do
|
describe Points::Create do
|
||||||
let(:device) { FactoryBot.create(:device) }
|
let(:device) { FactoryBot.create(:device) }
|
||||||
|
@ -21,21 +21,32 @@ describe Points::Create do
|
||||||
|
|
||||||
it "warns users when they hit the soft resource limit" do
|
it "warns users when they hit the soft resource limit" do
|
||||||
with_fake_limits do
|
with_fake_limits do
|
||||||
allow(device)
|
allow(device).to receive(:tell).with(Points::Create::GETTING_CLOSE, ["fatal_email"])
|
||||||
.to receive(:tell).with(Points::Create::GETTING_CLOSE, ["fatal_email"])
|
|
||||||
Points::Create::POINT_SOFT_LIMIT.times do
|
Points::Create::POINT_SOFT_LIMIT.times do
|
||||||
expect(Points::Create.run(params).errors).to be nil
|
expect(Points::Create.run(params).errors).to be nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "creates a gantry_mounted tool slot" do
|
||||||
|
p = { x: 0,
|
||||||
|
y: 10,
|
||||||
|
z: -100,
|
||||||
|
device: FactoryBot.create(:device),
|
||||||
|
gantry_mounted: true,
|
||||||
|
pointer_type: "ToolSlot" }
|
||||||
|
slot = Points::Create.run!(p)
|
||||||
|
|
||||||
|
p.map { |(k, v)| expect(slot.send(k)).to eq(v) }
|
||||||
|
end
|
||||||
|
|
||||||
it "stops users when they hit the hard limit" do
|
it "stops users when they hit the hard limit" do
|
||||||
with_fake_limits do
|
with_fake_limits do
|
||||||
params = { x: 0,
|
params = { x: 0,
|
||||||
y: 0,
|
y: 0,
|
||||||
z: 0,
|
z: 0,
|
||||||
device: device,
|
device: device,
|
||||||
pointer_type: "GenericPointer", }
|
pointer_type: "GenericPointer" }
|
||||||
|
|
||||||
Points::Create::POINT_HARD_LIMIT.times do
|
Points::Create::POINT_HARD_LIMIT.times do
|
||||||
expect(Points::Create.run(params).errors).to be nil
|
expect(Points::Create.run(params).errors).to be nil
|
||||||
|
|
Loading…
Reference in New Issue