summaryrefslogtreecommitdiff
path: root/db/seeds
diff options
context:
space:
mode:
Diffstat (limited to 'db/seeds')
-rw-r--r--db/seeds/1_nutrients.rb24
-rw-r--r--db/seeds/2_nutrient_measurements.rb27
-rw-r--r--db/seeds/3_crops.rb125
-rw-r--r--db/seeds/4_beds_and_rafts.rb24
-rw-r--r--db/seeds/5_fertilizer_components.rb.bkp38
-rw-r--r--db/seeds/6_fertilizer_products.rb143
6 files changed, 381 insertions, 0 deletions
diff --git a/db/seeds/1_nutrients.rb b/db/seeds/1_nutrients.rb
new file mode 100644
index 0000000..dab2249
--- /dev/null
+++ b/db/seeds/1_nutrients.rb
@@ -0,0 +1,24 @@
+NUTRIENTS = [
+ [ "nno3", "nitrate" ],
+ [ "p", "phosphore" ],
+ [ "k", "potassium" ],
+ [ "ca", "calcium" ],
+ [ "mg", "magnésium" ],
+ [ "s", "soufre" ],
+ [ "na", "sodium" ],
+ [ "cl", "chlore" ],
+ [ "si", "silice" ],
+ [ "fe", "fer" ],
+ [ "zn", "zinc" ],
+ [ "b", "bore" ],
+ [ "mn", "manganèse" ],
+ [ "cu", "cuivre" ],
+ [ "mo", "molybdène" ],
+ [ "nnh4", "ammonium" ]
+]
+
+NUTRIENTS.each do |formula, name|
+ Nutrient.find_or_create_by!(formula:) { |n| n.name = name }
+end
+
+puts "Nutrients: #{Nutrient.count}"
diff --git a/db/seeds/2_nutrient_measurements.rb b/db/seeds/2_nutrient_measurements.rb
new file mode 100644
index 0000000..0ca14f1
--- /dev/null
+++ b/db/seeds/2_nutrient_measurements.rb
@@ -0,0 +1,27 @@
+require "csv"
+
+csv_path = Rails.root.join("db", "data", "dolibarr_measurements.csv")
+abort "CSV not found: #{csv_path}" unless File.exist?(csv_path)
+
+CSV.foreach(csv_path, headers: true) do |row|
+ NutrientMeasurement.find_or_create_by!(measured_on: Date.parse(row["date"])) do |m|
+ m.nno3 = row["nno3"]
+ m.p = row["p"]
+ m.k = row["k"]
+ m.ca = row["ca"]
+ m.mg = row["mg"]
+ m.s = row["s"]
+ m.na = row["na"]
+ m.cl = row["cl"]
+ m.si = row["si"]
+ m.fe = row["fe"]
+ m.zn = row["zn"]
+ m.b = row["b"]
+ m.mn = row["mn"]
+ m.cu = row["cu"]
+ m.mo = row["mo"]
+ m.nnh4 = row["nnh4"]
+ end
+end
+
+puts "NutrientMeasurements: #{NutrientMeasurement.count}"
diff --git a/db/seeds/3_crops.rb b/db/seeds/3_crops.rb
new file mode 100644
index 0000000..2957188
--- /dev/null
+++ b/db/seeds/3_crops.rb
@@ -0,0 +1,125 @@
+# crop_type: 0=leafy greens, 1=fruits, 2=herbs
+
+LEAFY = {
+ nno3: 150,
+ p: 31,
+ k: 210,
+ ca: 90,
+ mg: 24,
+ s: 32,
+ fe: 1.0,
+ mn: 0.25,
+ zn: 0.13,
+ b: 0.16,
+ cu: 0.023,
+ mo: 0.024,
+ nnh4: 5,
+ # keep low for leafy
+ na: 10,
+ cl: 5,
+ si: 20
+}
+
+HERB = LEAFY # Herbs run well on the Cornell leafy recipe
+
+TOMATO = {
+ # CEAC Stage 3 "multi-crop" / mature tomato
+ nno3: 190,
+ p: 47,
+ k: 350,
+ ca: 200,
+ mg: 65,
+ s: 102,
+ fe: 2.0,
+ mn: 0.55,
+ zn: 0.33,
+ b: 0.28,
+ cu: 0.05,
+ mo: 0.05,
+ nnh4: 0,
+ # CEAC recipes are NO3-N; keep NH4 minimal
+ na: 20,
+ cl: 25,
+ si: 20
+}
+
+HOT_PEPPER = {
+ # Mature greenhouse pepper (HortAmericas summary of UA recipes)
+ nno3: 180,
+ p: 50,
+ k: 280,
+ ca: 200,
+ mg: 45,
+ s: 20,
+ fe: 1.0,
+ mn: 0.55,
+ zn: 0.33,
+ b: 0.30,
+ cu: 0.05,
+ mo: 0.05,
+ nnh4: 15,
+ na: 20,
+ cl: 10,
+ si: 20
+}
+
+STRAWBERRY = {
+ # UA strawberry (Yamazaki) emphasizes lower EC; use conservative macros
+ nno3: 120,
+ p: 30,
+ k: 200,
+ ca: 120,
+ mg: 35,
+ s: 50,
+ fe: 1.5,
+ mn: 0.50,
+ zn: 0.20,
+ b: 0.30,
+ cu: 0.05,
+ mo: 0.05,
+ nnh4: 5,
+ na: 10,
+ cl: 5,
+ si: 20
+}
+
+RASPBERRY = {
+ # Sparse data; align with strawberry but a touch higher vigor
+ nno3: 140,
+ p: 35,
+ k: 230,
+ ca: 150,
+ mg: 40,
+ s: 50,
+ fe: 1.5,
+ mn: 0.50,
+ zn: 0.20,
+ b: 0.30,
+ cu: 0.05,
+ mo: 0.05,
+ nnh4: 5,
+ na: 15,
+ cl: 5,
+ si: 20
+}
+
+[
+ [ "lettuce", 0, LEAFY ],
+ [ "kale", 0, LEAFY ],
+ [ "chinese cabbage", 0, LEAFY ],
+ [ "tomatoes", 1, TOMATO ],
+ [ "raspberries", 1, RASPBERRY ],
+ [ "strawberries", 1, STRAWBERRY ],
+ [ "hot peppers", 1, HOT_PEPPER ],
+ [ "parsley", 2, HERB ],
+ [ "chives", 2, HERB ],
+ [ "italian basil", 2, HERB ],
+ [ "dill", 2, HERB ]
+].each do |name, type, nutrient_requirements|
+ Crop.find_or_create_by!(name: name) do |c|
+ c.crop_type = type
+ c.attributes = nutrient_requirements
+ end
+end
+
+puts "Crops: #{Crop.count}"
diff --git a/db/seeds/4_beds_and_rafts.rb b/db/seeds/4_beds_and_rafts.rb
new file mode 100644
index 0000000..0105260
--- /dev/null
+++ b/db/seeds/4_beds_and_rafts.rb
@@ -0,0 +1,24 @@
+BEDS = 14
+RAFTS = 10
+
+1.upto(BEDS) do |b|
+ bed = Bed.find_or_create_by!(location: b)
+
+ crop_name = case b
+ when 1..2 then "tomatoes"
+ when 3 then "hot peppers"
+ when 4 then "chives"
+ when 5 then "italian basil"
+ when 6..7 then "chinese cabbage"
+ else "lettuce"
+ end
+
+ 1.upto(RAFTS) do |r|
+ raft = bed.rafts.find_or_create_by!(location: r) do |raft|
+ raft.crop = Crop.find_by!(name: crop_name)
+ end
+ end
+end
+
+puts "Beds: #{Bed.count}"
+puts "Rafts: #{Raft.count}"
diff --git a/db/seeds/5_fertilizer_components.rb.bkp b/db/seeds/5_fertilizer_components.rb.bkp
new file mode 100644
index 0000000..8a1fc54
--- /dev/null
+++ b/db/seeds/5_fertilizer_components.rb.bkp
@@ -0,0 +1,38 @@
+FERTILIZER_COMPONENTS = [
+ # Macros / bases
+ { name: "Potassium Nitrate", formula: "KNO3", nno3: 13.50, k: 38.60 },
+ { name: "Calcium Nitrate", formula: "Ca(NO3)2·xH2O", nno3: 15.50, ca: 18.94 },
+ { name: "Ammonium Nitrate", formula: "NH4NO3", nno3: 13.50, nnh4: 13.50 }, # total N ≈ 27
+ { name: "Diammonium Phosphate", formula: "(NH4)2HPO4", p: 21.00 }, # NH4 can be added later if desired
+
+ # Acids / buffers
+ { name: "Nitric Acid 53%", formula: "HNO3", nno3: 11.70 },
+ { name: "Potassium Bicarbonate", formula: "KHCO3", k: 39.05 },
+ { name: "Calcium Carbonate", formula: "CaCO3", ca: 38.00 },
+
+ # K–Mg–S complex (Patentkali-type blend)
+ { name: "Potassium Sulfate blend (K–Mg–S + NaCl)", formula: "K2SO4+MgSO4+NaCl",
+ p: 0.44, k: 22.66, mg: 6.16, s: 17.77, na: 2.16, cl: 3.34 },
+
+ # Sulfates (micros / secondary)
+ { name: "Magnesium Sulfate", formula: "MgSO4·7H2O", mg: 9.648, s: 13.016 },
+ { name: "Manganese Sulfate", formula: "MnSO4", s: 7.17, mn: 12.00 },
+ { name: "Zinc Sulfate (Fiza Zinc)", formula: "ZnSO4", zn: 12.00 },
+
+ # Chelates / traces
+ { name: "Iron DTPA 11.8%", formula: "Fe-DTPA", fe: 11.80 },
+ { name: "HelioCopper (Cu chelate)", formula: "Cu-chelate", cu: 40.00 },
+
+ # Boron & Mo sources
+ { name: "Boron–Molybdenum (Boronia LS)", formula: "B+Mo", b: 13.50, mo: 0.028 },
+ { name: "Boronia MO12 (10L)", formula: "B+Mn+Cu", b: 8.90, mn: 0.089, cu: 0.89 },
+ { name: "Sodium Molybdate", formula: "Na2MoO4", mo: 39.50 }
+]
+
+FERTILIZER_COMPONENTS.each do |attrs|
+ FertilizerComponent.find_or_create_by!(name: attrs[:name]) do |c|
+ c.attributes = attrs
+ end
+end
+
+puts "Fertilizer components: #{FertilizerComponent.count}"
diff --git a/db/seeds/6_fertilizer_products.rb b/db/seeds/6_fertilizer_products.rb
new file mode 100644
index 0000000..6769bde
--- /dev/null
+++ b/db/seeds/6_fertilizer_products.rb
@@ -0,0 +1,143 @@
+FERTILIZER_RECIPES = [
+ {
+ name: "Multi K Reci",
+ purity: 99.0,
+ composition: [
+ { component: {
+ name: "Potassium nitrate",
+ formula: "KNO3",
+ nno3: 13.0,
+ k: 46.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Fixa Mn",
+ purity: 98.0,
+ composition: [
+ { component: {
+ name: "Manganese sulfate",
+ formula: "MnSO4·H2O",
+ mn: 32.0,
+ s: 18.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Multi-Cal Haïfa",
+ purity: 99.0,
+ composition: [
+ { component: {
+ name: "Calcium nitrate",
+ formula: "Ca(NO3)2·4H2O",
+ nno3: 15.5,
+ ca: 19.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "DAP 18/46/00",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Diammonium phosphate",
+ formula: "(NH4)2HPO4",
+ nnh4: 18.0,
+ p: 20.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Patenkali",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Potassium sulfate",
+ formula: "K2SO4",
+ k: 50.0,
+ s: 18.0
+ }, percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Eso Top",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Magnesium sulfate",
+ formula: "MgSO4·7H2O",
+ mg: 9.8,
+ s: 13.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Ammonitrate 27",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Ammonium nitrate",
+ formula: "NH4NO3",
+ nno3: 13.5,
+ nnh4: 13.5 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Fer chélaté",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Iron chelate (EDDHA)",
+ formula: "Fe-EDDHA",
+ fe: 6.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Carbonate de calcium",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Calcium carbonate",
+ formula: "CaCO3",
+ ca: 40.0 },
+ percent_w: 100.0 }
+ ]
+ },
+ {
+ name: "Héliocuivre",
+ purity: 100.0,
+ composition: [
+ { component: {
+ name: "Copper chelate (EDTA)",
+ formula: "Cu-EDTA",
+ cu: 14.0 },
+ percent_w: 100.0 }
+ ]
+ }
+]
+
+FERTILIZER_RECIPES.each do |recipe|
+ product = FertilizerProduct.find_or_create_by!(name: recipe[:name]) do |fp|
+ fp.purity = recipe[:purity]
+ end
+
+ recipe[:composition].each do |c|
+ comp_attrs = c[:component]
+ component = FertilizerComponent.find_or_create_by!(name: comp_attrs[:name]) do |fc|
+ fc.formula = comp_attrs[:formula]
+ end
+ # update nutrient fields if missing
+ component.update!(comp_attrs.except(:name, :formula))
+
+ FertilizerComposition.find_or_create_by!(
+ fertilizer_product: product,
+ fertilizer_component: component
+ ) do |fc|
+ fc.percent_w = c[:percent_w]
+ end
+ end
+end
+
+puts "FertilizerProducts: #{FertilizerProduct.count}"
Copyright 2019--2025 Marius PETER