Farmbot-Web-App/db/seeds.rb

121 lines
4.9 KiB
Ruby
Raw Normal View History

2018-09-21 11:34:41 -06:00
if Rails.env == "development"
2018-04-20 10:45:01 -06:00
POINT_COUNT = 8
PLANT_COUNT = 8
DATE_RANGE_LO = 1..3
DATE_RANGE_HI = 3..8
ENV['MQTT_HOST'] = "blooper.io"
ENV['OS_UPDATE_SERVER'] = "http://non_legacy_update_url.com"
2019-01-08 09:19:52 -07:00
# CREDIT: Faker Ruby Gem
VEGGIES = %w(artichoke arugula asparagus broccoli
cabbage carrot cauliflower celery chive cucumber
2019-01-11 08:47:47 -07:00
eggplant endive garlic jicama kale kohlrabi leek lettuce okra onion
parsnip pepper potato pumpkin radicchio radish raspberry rhubarb spinach
2019-02-04 18:54:59 -07:00
squash tomato turnip zucchini)
2019-01-11 08:47:47 -07:00
[
Sensor,
Peripheral,
Log,
PinBinding,
Point,
Point,
TokenIssuance,
ToolSlot,
User,
PlantTemplate,
SavedGarden,
SensorReading,
FarmwareInstallation,
Device,
Tool,
2019-02-06 14:08:18 -07:00
Delayed::Job,
Delayed::Backend::ActiveRecord::Job,
2019-01-11 08:47:47 -07:00
].map(&:delete_all)
Users::Create.run!(name: "Test",
email: "test@test.com",
password: "password123",
password_confirmation: "password123",
confirmed_at: Time.now,
agreed_to_terms_at: Time.now)
User.all.update_all(confirmed_at: Time.now,
agreed_to_terms_at: Time.now)
u = User.last
u.update_attributes(device: Devices::Create.run!(user: u))
# === Parameterized Sequence stuff
json = JSON.parse(File.read("spec/lib/celery_script/ast_fixture5.json")).deep_symbolize_keys
Sequences::Create.run!(json, device: u.device)
# === Parameterized Sequence stuff
2016-12-08 13:05:05 -07:00
Log.transaction do
2017-10-22 07:19:50 -06:00
FactoryBot.create_list(:log, 35, device: u.device)
2016-12-08 13:05:05 -07:00
end
[ "https://via.placeholder.com/350x250?text=Image%20Zero",
"https://i.imgur.com/XvFBGA4.jpg",
"https://via.placeholder.com/350x250?text=Image%20Two",
"https://i.imgur.com/XsFczCY.jpg",
"https://via.placeholder.com/350x250?text=Image%20Four"
].each do |url|
2017-03-06 11:48:50 -07:00
Images::Create.run!(attachment_url: url,
device: u.device,
2017-04-27 14:53:28 -06:00
meta: {x: rand(40...970),
y: rand(40...470),
2017-04-27 14:26:25 -06:00
z: rand(1...300)})
end
2017-05-24 12:57:42 -06:00
PLANT_COUNT.times do
2019-01-08 09:19:52 -07:00
veggie = VEGGIES.sample
2018-04-10 13:43:27 -06:00
Plant.create(device: u.device,
x: rand(40...970),
y: rand(40...470),
radius: rand(10...50),
name: veggie,
openfarm_slug: veggie.downcase.gsub(" ", "-"))
end
2017-05-24 12:57:42 -06:00
2018-04-20 10:45:01 -06:00
Device.all.map { |device| SavedGardens::Snapshot.run!(device: device) }
2017-05-24 12:57:42 -06:00
POINT_COUNT.times do
2018-04-10 13:43:27 -06:00
GenericPointer.create(device: u.device,
x: rand(40...970) + rand(40...970),
y: rand(40...470) + rand(40...470),
z: 5,
radius: (rand(1...150) + rand(1...150)) / 20,
meta: {
created_by: "plant-detection",
color: (Sequence::COLORS + [nil]).sample
})
2017-02-07 12:26:01 -07:00
end
s = Sequences::Create.run!(device: u.device,
name: "Goto 0, 0, 0",
body: [{kind:"move_absolute",args:{location:{kind:"coordinate", args:{x:0,
y:0, z:0}}, offset:{kind:"coordinate", args:{x:0, y:0, z:0}}, speed:100}}])
2017-03-08 16:00:12 -07:00
t = Tools::Create.run!(name: "Trench Digging Tool", device: u.device)
body_txt = File.read("spec/lib/celery_script/ast_fixture4.json")
.gsub("__SEQUENCE_ID__", s[:id].to_s)
.gsub("__TOOL_ID__", t.id.to_s)
2017-03-03 09:34:33 -07:00
Sequences::Create.run!(device: u.device,
name: "Every Node",
body: JSON.parse(body_txt))
Regimens::Create.run(device: u.device,
name:"Test Regimen 456",
color:"gray",
regimen_items: [
{time_offset:300000, sequence_id:s[:id]},
{time_offset:173100000, sequence_id:s[:id]},
{time_offset:345900000, sequence_id:s[:id]}
])
Peripherals::Create.run!(device: u.device, pin: 13, label: "LED")
WebcamFeeds::Create.run!(device: u.device,
name: "My Feed 1",
url: "https://nature.nps.gov/air/webcams/parks/yosecam/yose.jpg")
2019-02-08 13:38:13 -07:00
ts = Points::Create.run!(device: u.device,
tool_id: t.id,
name: "Slot One.",
x: 10,
y: 10,
z: 10,
pointer_type: "ToolSlot")
2018-03-14 11:37:01 -06:00
d = u.device
Sensors::Create
.run!(device: d, pin: 14, label: "Stub sensor", mode: 0)
end