[STABLE] Dead code removal
parent
2785563e21
commit
1cc7aa4d69
|
@ -26,25 +26,25 @@ module Resources
|
|||
|
||||
# Map ActiveRecord class to a Mutations::Command class.
|
||||
MUTATION_MAPPING = {
|
||||
FarmEvent => FarmEvents,
|
||||
FarmwareInstallations => FarmwareInstallations,
|
||||
Image => Images,
|
||||
Log => Logs,
|
||||
Peripheral => Peripherals,
|
||||
PinBinding => PinBindings,
|
||||
PlantTemplate => PlantTemplates,
|
||||
Regimen => Regimens,
|
||||
SavedGarden => SavedGardens,
|
||||
Sensor => Sensors,
|
||||
SensorReading => SensorReadings,
|
||||
Sequence => Sequences,
|
||||
Tool => Tools,
|
||||
WebcamFeed => WebcamFeeds,
|
||||
FarmEvent => FarmEvents,
|
||||
Image => Images,
|
||||
Log => Logs,
|
||||
Peripheral => Peripherals,
|
||||
PinBinding => PinBindings,
|
||||
PlantTemplate => PlantTemplates,
|
||||
Regimen => Regimens,
|
||||
SavedGarden => SavedGardens,
|
||||
Sensor => Sensors,
|
||||
SensorReading => SensorReadings,
|
||||
Sequence => Sequences,
|
||||
Tool => Tools,
|
||||
WebcamFeed => WebcamFeeds,
|
||||
# SPECIAL CASES =============================
|
||||
# These reasources don't follow usual
|
||||
# naming coonventions.
|
||||
Plants => Points,
|
||||
Point => Points,
|
||||
ToolSlot => Points,
|
||||
Plant => Points,
|
||||
Point => Points,
|
||||
ToolSlot => Points,
|
||||
}
|
||||
end # Resources
|
||||
|
|
|
@ -20,7 +20,6 @@ module Resources
|
|||
case action
|
||||
when DESTROY then do_deletion
|
||||
when SAVE then do_save
|
||||
else; never
|
||||
end
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
add_error :not_found, :not_found, NOT_FOUND
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
module Plants
|
||||
class Create < Mutations::Command
|
||||
required do
|
||||
model :device, class: Device
|
||||
float :x
|
||||
float :y
|
||||
end
|
||||
|
||||
optional do
|
||||
string :name, default: "Unknown Plant"
|
||||
string :openfarm_slug, default: "not-set"
|
||||
time :created_at
|
||||
float :radius, default: 25
|
||||
float :z, default: 0
|
||||
time :planted_at, default: 0
|
||||
string :plant_stage, in: CeleryScriptSettingsBag::PLANT_STAGES
|
||||
end
|
||||
|
||||
def execute
|
||||
stub = { pointer_type: "Plant" }
|
||||
Plant.create!(inputs.merge(stub))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,8 +9,8 @@ module Points
|
|||
# many plants
|
||||
# * An XL bot at 100% capacity and 1000 evenly space plants =
|
||||
# 5 inch point grid. Smaller bed = higher resolution.
|
||||
POINT_HARD_LIMIT = 1000 # Not allowed to exceed this.
|
||||
POINT_SOFT_LIMIT = (POINT_HARD_LIMIT * 0.8).to_i
|
||||
POINT_HARD_LIMIT = 1 # 1000 # Not allowed to exceed this.
|
||||
POINT_SOFT_LIMIT = 2 # (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
|
||||
|
@ -57,11 +57,12 @@ module Points
|
|||
private
|
||||
|
||||
def validate_resource_count
|
||||
# case Point.where(device_id: device.id).count
|
||||
# when (0..POINT_SOFT_LIMIT)
|
||||
# when (POINT_SOFT_LIMIT..POINT_HARD_LIMIT)
|
||||
# when (POINT_HARD_LIMIT..nil)
|
||||
# end
|
||||
case Point.where(device_id: device.id).count
|
||||
when (POINT_SOFT_LIMIT..POINT_HARD_LIMIT)
|
||||
binding.pry
|
||||
when (POINT_HARD_LIMIT..nil)
|
||||
binding.pry
|
||||
end
|
||||
end
|
||||
|
||||
def default_name
|
||||
|
@ -82,10 +83,6 @@ module Points
|
|||
@klass_ ||= pointer_type.constantize
|
||||
end
|
||||
|
||||
def has_tool_id
|
||||
!!tool_id
|
||||
end
|
||||
|
||||
def bad_tool_id?
|
||||
tool_id.present? && !device.tools.where(id: tool_id).any?
|
||||
end
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
module ToolSlots
|
||||
class Create < Mutations::Command
|
||||
FIELDS = [:tool_id, :pullout_direction, :x, :y, :z, :name]
|
||||
|
||||
required do
|
||||
model :device, class: Device
|
||||
string :name, default: "Untitled Slot"
|
||||
float :x
|
||||
float :y
|
||||
float :z
|
||||
end
|
||||
|
||||
optional do
|
||||
integer :tool_id, empty: true
|
||||
integer :pullout_direction,
|
||||
min: ToolSlot::PULLOUT_DIRECTIONS.min,
|
||||
max: ToolSlot::PULLOUT_DIRECTIONS.max
|
||||
end
|
||||
|
||||
def validate
|
||||
validate_tool
|
||||
end
|
||||
|
||||
def execute
|
||||
stub = {pointer_type: "ToolSlot", device_id: device.id}
|
||||
ToolSlot.create!(inputs.slice(*FIELDS).merge(stub))
|
||||
end
|
||||
|
||||
def has_tool_id
|
||||
!!tool_id
|
||||
end
|
||||
|
||||
def validate_tool
|
||||
if has_tool_id && !device.tools.where(id: tool_id).any?
|
||||
add_error :tool_id,
|
||||
:not_found,
|
||||
"Can't find tool with id #{tool_id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
db/seeds.rb
13
db/seeds.rb
|
@ -108,12 +108,13 @@ if Rails.env == "development"
|
|||
WebcamFeeds::Create.run!(device: u.device,
|
||||
name: "My Feed 1",
|
||||
url: "https://nature.nps.gov/air/webcams/parks/yosecam/yose.jpg")
|
||||
ts = ToolSlots::Create.run!(device: u.device,
|
||||
tool_id: t.id,
|
||||
name: "Slot One.",
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10)
|
||||
ts = Points::Create.run!(device: u.device,
|
||||
tool_id: t.id,
|
||||
name: "Slot One.",
|
||||
x: 10,
|
||||
y: 10,
|
||||
z: 10,
|
||||
pointer_type: "ToolSlot")
|
||||
d = u.device
|
||||
Sensors::Create
|
||||
.run!(device: d, pin: 14, label: "Stub sensor", mode: 0)
|
||||
|
|
|
@ -20,11 +20,12 @@ module Points
|
|||
self.device = FactoryBot.create(:device)
|
||||
self.tool = Tools::Create.run!(device: self.device,
|
||||
name: "Scenario Tool")
|
||||
self.tool_slot = ToolSlots::Create.run!(device: self.device,
|
||||
name: "Scenario Tool Slot",
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0)
|
||||
self.tool_slot = Points::Create.run!(device: self.device,
|
||||
name: "Scenario Tool Slot",
|
||||
x: 0,
|
||||
y: 0,
|
||||
z: 0,
|
||||
pointer_type: "ToolSlot")
|
||||
self.sequence = Sequences::Create.run!(device: self.device,
|
||||
body: self.body,
|
||||
name: "Scenario Sequence")
|
||||
|
|
Loading…
Reference in New Issue