add gantry_mounted attribute to ToolSlot

pull/1177/head
Rick Carlino 2019-05-02 11:52:33 -05:00
parent 74ed1ec296
commit 8eeac7e957
6 changed files with 73 additions and 47 deletions

View File

@ -254,13 +254,19 @@ module Devices
mode: mode)
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",
name: name,
x: x,
y: y,
z: z,
pullout_direction: pullout_direction,
gantry_mounted: gantry_mounted,
device: device)
end

View File

@ -18,43 +18,44 @@ module Points
# Smaller bed = higher resolution.
POINT_HARD_LIMIT = 1000 # Can't exceed this.
POINT_SOFT_LIMIT = (POINT_HARD_LIMIT * 0.8).to_i
BAD_TOOL_ID = "Can't find tool with id %s"
DEFAULT_NAME = "Untitled %s"
KINDS = Point::POINTER_KINDS
GETTING_CLOSE = "Your account is "\
"approaching the allowed point limit of "\
"#{POINT_HARD_LIMIT}. Consider deleting old"\
" points to avoid adverse performance."
TOO_MANY = "Your device has hit the "\
"max limit for point usage (currently "\
"#{POINT_HARD_LIMIT}). Please delete unused"\
" map points and plants to create more "
BAD_POINTER_TYPE = \
"Please provide a JSON object with a `poin"\
"ter_type` that matches one of the followi"\
BAD_TOOL_ID = "Can't find tool with id %s"
DEFAULT_NAME = "Untitled %s"
KINDS = Point::POINTER_KINDS
GETTING_CLOSE = "Your account is " \
"approaching the allowed point limit of " \
"#{POINT_HARD_LIMIT}. Consider deleting old" \
" points to avoid adverse performance."
TOO_MANY = "Your device has hit the " \
"max limit for point usage (currently " \
"#{POINT_HARD_LIMIT}). Please delete unused" \
" map points and plants to create more "
BAD_POINTER_TYPE =
"Please provide a JSON object with a `poin" \
"ter_type` that matches one of the followi" \
"ng values: #{KINDS.join(", ")}"
required do
float :x
float :y
float :z, default: 0
model :device, class: Device
float :x
float :y
float :z, default: 0
model :device, class: Device
string :pointer_type
end
optional do
hstore :meta
float :radius, default: 25
float :radius, default: 25
integer :pullout_direction,
min: ToolSlot::PULLOUT_DIRECTIONS.min,
max: ToolSlot::PULLOUT_DIRECTIONS.max
min: ToolSlot::PULLOUT_DIRECTIONS.min,
max: ToolSlot::PULLOUT_DIRECTIONS.max
integer :tool_id, empty: true
string :name
string :openfarm_slug, default: "not-set"
string :plant_stage,
in: CeleryScriptSettingsBag::PLANT_STAGES
time :created_at # TODO: Are we still using this?
time :planted_at, default: 0
string :name
string :openfarm_slug, default: "not-set"
string :plant_stage,
in: CeleryScriptSettingsBag::PLANT_STAGES
time :created_at # TODO: Are we still using this?
time :planted_at, default: 0
boolean :gantry_mounted
end
def validate
@ -68,18 +69,18 @@ module Points
klass_.create!(inputs)
end
private
private
def validate_resource_count
actual = \
actual =
Point.where(device_id: device.id).count
case actual
when POINT_SOFT_LIMIT
device.points.discarded.delete_all
device.tell(GETTING_CLOSE % { actual: actual }, ["fatal_email"])
when POINT_HARD_LIMIT...nil
device.points.discarded.delete_all
add_error(:point_limit, :point_limit, TOO_MANY)
when POINT_SOFT_LIMIT
device.points.discarded.delete_all
device.tell(GETTING_CLOSE % { actual: actual }, ["fatal_email"])
when POINT_HARD_LIMIT...nil
device.points.discarded.delete_all
add_error(:point_limit, :point_limit, TOO_MANY)
end
end

View File

@ -1,3 +1,3 @@
class ToolSlotSerializer < BasePointSerializer
attributes :tool_id, :pullout_direction
attributes :tool_id, :pullout_direction, :gantry_mounted
end

View File

@ -0,0 +1,6 @@
class AddGantryMountedToToolSlots < ActiveRecord::Migration[5.2]
safety_assured
def change
add_column :points, :gantry_mounted, :boolean, default: false
end
end

View File

@ -746,7 +746,8 @@ CREATE TABLE public.points (
tool_id integer,
pullout_direction integer DEFAULT 0,
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'),
('20190419174728'),
('20190419174811'),
('20190501143201');
('20190501143201'),
('20190502163453');

View File

@ -1,4 +1,4 @@
require 'spec_helper'
require "spec_helper"
describe Points::Create do
let(:device) { FactoryBot.create(:device) }
@ -21,21 +21,32 @@ describe Points::Create do
it "warns users when they hit the soft resource limit" do
with_fake_limits do
allow(device)
.to receive(:tell).with(Points::Create::GETTING_CLOSE, ["fatal_email"])
allow(device).to receive(:tell).with(Points::Create::GETTING_CLOSE, ["fatal_email"])
Points::Create::POINT_SOFT_LIMIT.times do
expect(Points::Create.run(params).errors).to be nil
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
with_fake_limits do
params = { x: 0,
y: 0,
z: 0,
device: device,
pointer_type: "GenericPointer", }
params = { x: 0,
y: 0,
z: 0,
device: device,
pointer_type: "GenericPointer" }
Points::Create::POINT_HARD_LIMIT.times do
expect(Points::Create.run(params).errors).to be nil