From 52b044d6a4278c229992404ad5801769c2d13363 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 24 Aug 2025 20:29:54 +0200 Subject: First commit. Vive le Castel Peter ! --- .dockerignore | 51 +++ .gitattributes | 9 + .gitignore | 34 ++ .kamal/secrets | 17 + .rubocop.yml | 8 + .ruby-version | 1 + Dockerfile | 72 ++++ Gemfile | 65 ++++ Gemfile.lock | 397 +++++++++++++++++++++ README.md | 24 ++ Rakefile | 6 + app/assets/images/.keep | 0 app/assets/stylesheets/application.css | 10 + app/controllers/application_controller.rb | 4 + app/controllers/concerns/.keep | 0 app/controllers/crops_controller.rb | 70 ++++ app/controllers/dashboard_controller.rb | 45 +++ app/controllers/fertilizer_products_controller.rb | 70 ++++ app/controllers/fertilizers_controller.rb | 70 ++++ app/controllers/nutrient_measurement_controller.rb | 4 + app/controllers/rafts_controller.rb | 54 +++ app/controllers/recipes_controller.rb | 8 + app/helpers/application_helper.rb | 2 + app/helpers/dashboard_helper.rb | 8 + app/helpers/nutrients_helper.rb | 21 ++ app/helpers/recipes_helper.rb | 16 + app/javascript/application.js | 1 + app/jobs/application_job.rb | 7 + app/mailers/application_mailer.rb | 4 + app/models/application_record.rb | 3 + app/models/bed.rb | 4 + app/models/concerns/.keep | 0 app/models/crop.rb | 4 + app/models/fertilizer_component.rb | 3 + app/models/fertilizer_composition.rb | 6 + app/models/fertilizer_product.rb | 7 + app/models/nutrient.rb | 7 + app/models/nutrient_measurement.rb | 4 + app/models/raft.rb | 5 + app/services/fertilizer_recipe_calculator.rb | 136 +++++++ app/services/target_nutrient_calculator.rb | 33 ++ app/views/application/_copyright_footer.html.erb | 10 + app/views/application/_navbar.html.erb | 33 ++ app/views/crops/_crop.html.erb | 92 +++++ app/views/crops/_form.html.erb | 107 ++++++ app/views/crops/edit.html.erb | 12 + app/views/crops/index.html.erb | 16 + app/views/crops/new.html.erb | 11 + app/views/crops/show.html.erb | 10 + app/views/dashboard/_raft_allocation.html.erb | 9 + app/views/dashboard/_recent_measurements.html.erb | 22 ++ app/views/dashboard/_target_table.html.erb | 40 +++ app/views/dashboard/index.html.erb | 7 + .../_fertilizer_product.html.erb | 12 + app/views/fertilizer_products/_form.html.erb | 27 ++ app/views/fertilizer_products/edit.html.erb | 12 + app/views/fertilizer_products/index.html.erb | 16 + app/views/fertilizer_products/new.html.erb | 11 + app/views/fertilizer_products/show.html.erb | 10 + app/views/layouts/application.html.erb | 46 +++ app/views/layouts/mailer.html.erb | 13 + app/views/layouts/mailer.text.erb | 1 + app/views/nutrient_measurement/index.html.erb | 27 ++ app/views/pwa/manifest.json.erb | 22 ++ app/views/pwa/service-worker.js | 26 ++ app/views/rafts/editor.html.erb | 108 ++++++ app/views/recipes/_table.html.erb | 32 ++ app/views/recipes/show.html.erb | 108 ++++++ bin/brakeman | 7 + bin/dev | 2 + bin/docker-entrypoint | 14 + bin/importmap | 4 + bin/rails | 4 + bin/rake | 4 + bin/rubocop | 8 + bin/setup | 34 ++ bin/thrust | 5 + config.ru | 6 + config/application.rb | 27 ++ config/boot.rb | 4 + config/cable.yml | 10 + config/credentials.yml.enc | 1 + config/database.yml | 41 +++ config/deploy.yml | 116 ++++++ config/environment.rb | 5 + config/environments/development.rb | 72 ++++ config/environments/production.rb | 89 +++++ config/environments/test.rb | 53 +++ config/importmap.rb | 3 + config/initializers/assets.rb | 7 + config/initializers/content_security_policy.rb | 25 ++ config/initializers/filter_parameter_logging.rb | 8 + config/initializers/inflections.rb | 16 + config/locales/en.yml | 31 ++ config/puma.rb | 41 +++ config/routes.rb | 32 ++ config/storage.yml | 34 ++ db/data/dolibarr_measurements.csv | 44 +++ db/data/nutrient_requirements.csv | 9 + db/migrate/20250820175727_create_nutrients.rb | 10 + .../20250820175742_create_nutrient_measurements.rb | 27 ++ db/migrate/20250823140019_create_crops.rb | 26 ++ db/migrate/20250823142743_create_beds.rb | 11 + db/migrate/20250823142858_create_rafts.rb | 13 + .../20250824121914_create_fertilizer_components.rb | 26 ++ .../20250824163242_create_fertilizer_products.rb | 11 + ...0250824163257_create_fertilizer_compositions.rb | 11 + db/schema.rb | 130 +++++++ db/seeds.rb | 13 + db/seeds/1_nutrients.rb | 24 ++ db/seeds/2_nutrient_measurements.rb | 27 ++ db/seeds/3_crops.rb | 125 +++++++ db/seeds/4_beds_and_rafts.rb | 24 ++ db/seeds/5_fertilizer_components.rb.bkp | 38 ++ db/seeds/6_fertilizer_products.rb | 143 ++++++++ lib/tasks/.keep | 0 log/.keep | 0 public/400.html | 114 ++++++ public/404.html | 114 ++++++ public/406-unsupported-browser.html | 114 ++++++ public/422.html | 114 ++++++ public/500.html | 114 ++++++ public/icon.png | Bin 0 -> 4166 bytes public/icon.svg | 3 + public/robots.txt | 1 + script/.keep | 0 storage/.keep | 0 test/application_system_test_case.rb | 5 + test/controllers/crops_controller_test.rb | 48 +++ test/controllers/dashboard_controller_test.rb | 8 + .../fertilizer_products_controller_test.rb | 48 +++ .../nutrient_measurement_controller_test.rb | 8 + test/controllers/rafts_controller_test.rb | 7 + test/controllers/recipes_controller_test.rb | 7 + test/fixtures/beds.yml | 7 + test/fixtures/crops.yml | 41 +++ test/fixtures/fertilizer_products.yml | 9 + test/fixtures/files/.keep | 0 test/fixtures/nutrient_measurements.yml | 39 ++ test/fixtures/nutrients.yml | 9 + test/fixtures/rafts.yml | 9 + test/helpers/.keep | 0 test/integration/.keep | 0 test/mailers/.keep | 0 test/models/.keep | 0 test/models/bed_test.rb | 7 + test/models/crop_test.rb | 7 + test/models/fertilizer_composition_test.rb | 7 + test/models/fertilizer_product_test.rb | 7 + test/models/fertilizer_test.rb | 7 + test/models/nutrient_measurement_test.rb | 7 + test/models/nutrient_test.rb | 7 + test/models/raft_test.rb | 7 + test/system/.keep | 0 test/system/crops_test.rb | 75 ++++ test/system/fertilizer_products_test.rb | 43 +++ test/test_helper.rb | 15 + tmp/.keep | 0 tmp/pids/.keep | 0 tmp/storage/.keep | 0 vendor/.gitignore | 3 + vendor/bundle/.keep | 0 vendor/javascript/.keep | 0 163 files changed, 4556 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .kamal/secrets create mode 100644 .rubocop.yml create mode 100644 .ruby-version create mode 100644 Dockerfile create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 Rakefile create mode 100644 app/assets/images/.keep create mode 100644 app/assets/stylesheets/application.css create mode 100644 app/controllers/application_controller.rb create mode 100644 app/controllers/concerns/.keep create mode 100644 app/controllers/crops_controller.rb create mode 100644 app/controllers/dashboard_controller.rb create mode 100644 app/controllers/fertilizer_products_controller.rb create mode 100644 app/controllers/fertilizers_controller.rb create mode 100644 app/controllers/nutrient_measurement_controller.rb create mode 100644 app/controllers/rafts_controller.rb create mode 100644 app/controllers/recipes_controller.rb create mode 100644 app/helpers/application_helper.rb create mode 100644 app/helpers/dashboard_helper.rb create mode 100644 app/helpers/nutrients_helper.rb create mode 100644 app/helpers/recipes_helper.rb create mode 100644 app/javascript/application.js create mode 100644 app/jobs/application_job.rb create mode 100644 app/mailers/application_mailer.rb create mode 100644 app/models/application_record.rb create mode 100644 app/models/bed.rb create mode 100644 app/models/concerns/.keep create mode 100644 app/models/crop.rb create mode 100644 app/models/fertilizer_component.rb create mode 100644 app/models/fertilizer_composition.rb create mode 100644 app/models/fertilizer_product.rb create mode 100644 app/models/nutrient.rb create mode 100644 app/models/nutrient_measurement.rb create mode 100644 app/models/raft.rb create mode 100644 app/services/fertilizer_recipe_calculator.rb create mode 100644 app/services/target_nutrient_calculator.rb create mode 100644 app/views/application/_copyright_footer.html.erb create mode 100644 app/views/application/_navbar.html.erb create mode 100644 app/views/crops/_crop.html.erb create mode 100644 app/views/crops/_form.html.erb create mode 100644 app/views/crops/edit.html.erb create mode 100644 app/views/crops/index.html.erb create mode 100644 app/views/crops/new.html.erb create mode 100644 app/views/crops/show.html.erb create mode 100644 app/views/dashboard/_raft_allocation.html.erb create mode 100644 app/views/dashboard/_recent_measurements.html.erb create mode 100644 app/views/dashboard/_target_table.html.erb create mode 100644 app/views/dashboard/index.html.erb create mode 100644 app/views/fertilizer_products/_fertilizer_product.html.erb create mode 100644 app/views/fertilizer_products/_form.html.erb create mode 100644 app/views/fertilizer_products/edit.html.erb create mode 100644 app/views/fertilizer_products/index.html.erb create mode 100644 app/views/fertilizer_products/new.html.erb create mode 100644 app/views/fertilizer_products/show.html.erb create mode 100644 app/views/layouts/application.html.erb create mode 100644 app/views/layouts/mailer.html.erb create mode 100644 app/views/layouts/mailer.text.erb create mode 100644 app/views/nutrient_measurement/index.html.erb create mode 100644 app/views/pwa/manifest.json.erb create mode 100644 app/views/pwa/service-worker.js create mode 100644 app/views/rafts/editor.html.erb create mode 100644 app/views/recipes/_table.html.erb create mode 100644 app/views/recipes/show.html.erb create mode 100755 bin/brakeman create mode 100755 bin/dev create mode 100755 bin/docker-entrypoint create mode 100755 bin/importmap create mode 100755 bin/rails create mode 100755 bin/rake create mode 100755 bin/rubocop create mode 100755 bin/setup create mode 100755 bin/thrust create mode 100644 config.ru create mode 100644 config/application.rb create mode 100644 config/boot.rb create mode 100644 config/cable.yml create mode 100644 config/credentials.yml.enc create mode 100644 config/database.yml create mode 100644 config/deploy.yml create mode 100644 config/environment.rb create mode 100644 config/environments/development.rb create mode 100644 config/environments/production.rb create mode 100644 config/environments/test.rb create mode 100644 config/importmap.rb create mode 100644 config/initializers/assets.rb create mode 100644 config/initializers/content_security_policy.rb create mode 100644 config/initializers/filter_parameter_logging.rb create mode 100644 config/initializers/inflections.rb create mode 100644 config/locales/en.yml create mode 100644 config/puma.rb create mode 100644 config/routes.rb create mode 100644 config/storage.yml create mode 100644 db/data/dolibarr_measurements.csv create mode 100644 db/data/nutrient_requirements.csv create mode 100644 db/migrate/20250820175727_create_nutrients.rb create mode 100644 db/migrate/20250820175742_create_nutrient_measurements.rb create mode 100644 db/migrate/20250823140019_create_crops.rb create mode 100644 db/migrate/20250823142743_create_beds.rb create mode 100644 db/migrate/20250823142858_create_rafts.rb create mode 100644 db/migrate/20250824121914_create_fertilizer_components.rb create mode 100644 db/migrate/20250824163242_create_fertilizer_products.rb create mode 100644 db/migrate/20250824163257_create_fertilizer_compositions.rb create mode 100644 db/schema.rb create mode 100644 db/seeds.rb create mode 100644 db/seeds/1_nutrients.rb create mode 100644 db/seeds/2_nutrient_measurements.rb create mode 100644 db/seeds/3_crops.rb create mode 100644 db/seeds/4_beds_and_rafts.rb create mode 100644 db/seeds/5_fertilizer_components.rb.bkp create mode 100644 db/seeds/6_fertilizer_products.rb create mode 100644 lib/tasks/.keep create mode 100644 log/.keep create mode 100644 public/400.html create mode 100644 public/404.html create mode 100644 public/406-unsupported-browser.html create mode 100644 public/422.html create mode 100644 public/500.html create mode 100644 public/icon.png create mode 100644 public/icon.svg create mode 100644 public/robots.txt create mode 100644 script/.keep create mode 100644 storage/.keep create mode 100644 test/application_system_test_case.rb create mode 100644 test/controllers/crops_controller_test.rb create mode 100644 test/controllers/dashboard_controller_test.rb create mode 100644 test/controllers/fertilizer_products_controller_test.rb create mode 100644 test/controllers/nutrient_measurement_controller_test.rb create mode 100644 test/controllers/rafts_controller_test.rb create mode 100644 test/controllers/recipes_controller_test.rb create mode 100644 test/fixtures/beds.yml create mode 100644 test/fixtures/crops.yml create mode 100644 test/fixtures/fertilizer_products.yml create mode 100644 test/fixtures/files/.keep create mode 100644 test/fixtures/nutrient_measurements.yml create mode 100644 test/fixtures/nutrients.yml create mode 100644 test/fixtures/rafts.yml create mode 100644 test/helpers/.keep create mode 100644 test/integration/.keep create mode 100644 test/mailers/.keep create mode 100644 test/models/.keep create mode 100644 test/models/bed_test.rb create mode 100644 test/models/crop_test.rb create mode 100644 test/models/fertilizer_composition_test.rb create mode 100644 test/models/fertilizer_product_test.rb create mode 100644 test/models/fertilizer_test.rb create mode 100644 test/models/nutrient_measurement_test.rb create mode 100644 test/models/nutrient_test.rb create mode 100644 test/models/raft_test.rb create mode 100644 test/system/.keep create mode 100644 test/system/crops_test.rb create mode 100644 test/system/fertilizer_products_test.rb create mode 100644 test/test_helper.rb create mode 100644 tmp/.keep create mode 100644 tmp/pids/.keep create mode 100644 tmp/storage/.keep create mode 100644 vendor/.gitignore create mode 100644 vendor/bundle/.keep create mode 100644 vendor/javascript/.keep diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..325bfc0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,51 @@ +# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files. + +# Ignore git directory. +/.git/ +/.gitignore + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all default key files. +/config/master.key +/config/credentials/*.key + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/.keep + +# Ignore assets. +/node_modules/ +/app/assets/builds/* +!/app/assets/builds/.keep +/public/assets + +# Ignore CI service files. +/.github + +# Ignore Kamal files. +/config/deploy*.yml +/.kamal + +# Ignore development files +/.devcontainer + +# Ignore Docker-related files +/.dockerignore +/Dockerfile* diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8dc4323 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +# See https://git-scm.com/docs/gitattributes for more about git attribute files. + +# Mark the database schema as having been generated. +db/schema.rb linguist-generated + +# Mark any vendored files as having been vendored. +vendor/* linguist-vendored +config/credentials/*.yml.enc diff=rails_credentials +config/credentials.yml.enc diff=rails_credentials diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f92525c --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +# See https://help.github.com/articles/ignoring-files for more about ignoring files. +# +# Temporary files generated by your text editor or operating system +# belong in git's global ignore instead: +# `$XDG_CONFIG_HOME/git/ignore` or `~/.config/git/ignore` + +# Ignore bundler config. +/.bundle + +# Ignore all environment files. +/.env* + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep + +# Ignore storage (uploaded files in development and any SQLite databases). +/storage/* +!/storage/.keep +/tmp/storage/* +!/tmp/storage/ +!/tmp/storage/.keep + +/public/assets + +# Ignore master key for decrypting credentials and more. +/config/master.key diff --git a/.kamal/secrets b/.kamal/secrets new file mode 100644 index 0000000..9a771a3 --- /dev/null +++ b/.kamal/secrets @@ -0,0 +1,17 @@ +# Secrets defined here are available for reference under registry/password, env/secret, builder/secrets, +# and accessories/*/env/secret in config/deploy.yml. All secrets should be pulled from either +# password manager, ENV, or a file. DO NOT ENTER RAW CREDENTIALS HERE! This file needs to be safe for git. + +# Example of extracting secrets from 1password (or another compatible pw manager) +# SECRETS=$(kamal secrets fetch --adapter 1password --account your-account --from Vault/Item KAMAL_REGISTRY_PASSWORD RAILS_MASTER_KEY) +# KAMAL_REGISTRY_PASSWORD=$(kamal secrets extract KAMAL_REGISTRY_PASSWORD ${SECRETS}) +# RAILS_MASTER_KEY=$(kamal secrets extract RAILS_MASTER_KEY ${SECRETS}) + +# Use a GITHUB_TOKEN if private repositories are needed for the image +# GITHUB_TOKEN=$(gh config get -h github.com oauth_token) + +# Grab the registry password from ENV +KAMAL_REGISTRY_PASSWORD=$KAMAL_REGISTRY_PASSWORD + +# Improve security by using a password manager. Never check config/master.key into git! +RAILS_MASTER_KEY=$(cat config/master.key) diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f9d86d4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,8 @@ +# Omakase Ruby styling for Rails +inherit_gem: { rubocop-rails-omakase: rubocop.yml } + +# Overwrite or add rules to create your own house style +# +# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]` +# Layout/SpaceInsideArrayLiteralBrackets: +# Enabled: false diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..61b1268 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-3.2.8 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..20b3bf3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +# syntax=docker/dockerfile:1 +# check=error=true + +# This Dockerfile is designed for production, not development. Use with Kamal or build'n'run by hand: +# docker build -t ferti . +# docker run -d -p 80:80 -e RAILS_MASTER_KEY= --name ferti ferti + +# For a containerized dev environment, see Dev Containers: https://guides.rubyonrails.org/getting_started_with_devcontainer.html + +# Make sure RUBY_VERSION matches the Ruby version in .ruby-version +ARG RUBY_VERSION=3.2.8 +FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base + +# Rails app lives here +WORKDIR /rails + +# Install base packages +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips sqlite3 && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Set production environment +ENV RAILS_ENV="production" \ + BUNDLE_DEPLOYMENT="1" \ + BUNDLE_PATH="/usr/local/bundle" \ + BUNDLE_WITHOUT="development" + +# Throw-away build stage to reduce size of final image +FROM base AS build + +# Install packages needed to build gems +RUN apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential git libyaml-dev pkg-config && \ + rm -rf /var/lib/apt/lists /var/cache/apt/archives + +# Install application gems +COPY Gemfile Gemfile.lock ./ +RUN bundle install && \ + rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ + bundle exec bootsnap precompile --gemfile + +# Copy application code +COPY . . + +# Precompile bootsnap code for faster boot times +RUN bundle exec bootsnap precompile app/ lib/ + +# Precompiling assets for production without requiring secret RAILS_MASTER_KEY +RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile + + + + +# Final stage for app image +FROM base + +# Copy built artifacts: gems, application +COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}" +COPY --from=build /rails /rails + +# Run and own only the runtime files as a non-root user for security +RUN groupadd --system --gid 1000 rails && \ + useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \ + chown -R rails:rails db log storage tmp +USER 1000:1000 + +# Entrypoint prepares the database. +ENTRYPOINT ["/rails/bin/docker-entrypoint"] + +# Start server via Thruster by default, this can be overwritten at runtime +EXPOSE 80 +CMD ["./bin/thrust", "./bin/rails", "server"] diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..2077d17 --- /dev/null +++ b/Gemfile @@ -0,0 +1,65 @@ +source "https://rubygems.org" + +# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main" +gem "rails", "~> 8.0.2", ">= 8.0.2.1" +# The modern asset pipeline for Rails [https://github.com/rails/propshaft] +gem "propshaft" +# Use sqlite3 as the database for Active Record +gem "sqlite3", ">= 2.1" +# Use the Puma web server [https://github.com/puma/puma] +gem "puma", ">= 5.0" +# Use JavaScript with ESM import maps [https://github.com/rails/importmap-rails] +gem "importmap-rails" +# Hotwire's SPA-like page accelerator [https://turbo.hotwired.dev] +gem "turbo-rails" +# Hotwire's modest JavaScript framework [https://stimulus.hotwired.dev] +gem "stimulus-rails" +# Build JSON APIs with ease [https://github.com/rails/jbuilder] +gem "jbuilder" + +# Use Active Model has_secure_password [https://guides.rubyonrails.org/active_model_basics.html#securepassword] +# gem "bcrypt", "~> 3.1.7" + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem "tzinfo-data", platforms: %i[ windows jruby ] + +# Use the database-backed adapters for Rails.cache, Active Job, and Action Cable +gem "solid_cache" +gem "solid_queue" +gem "solid_cable" + +# Reduces boot times through caching; required in config/boot.rb +gem "bootsnap", require: false + +# Deploy this application anywhere as a Docker container [https://kamal-deploy.org] +gem "kamal", require: false + +# Add HTTP asset caching/compression and X-Sendfile acceleration to Puma [https://github.com/basecamp/thruster/] +gem "thruster", require: false + +# Use Active Storage variants [https://guides.rubyonrails.org/active_storage_overview.html#transforming-images] +# gem "image_processing", "~> 1.2" + +group :development, :test do + # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem + gem "debug", platforms: %i[ mri windows ], require: "debug/prelude" + + # Static analysis for security vulnerabilities [https://brakemanscanner.org/] + gem "brakeman", require: false + + # Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/] + gem "rubocop-rails-omakase", require: false +end + +group :development do + # Use console on exceptions pages [https://github.com/rails/web-console] + gem "web-console" +end + +group :test do + # Use system testing [https://guides.rubyonrails.org/testing.html#system-testing] + gem "capybara" + gem "selenium-webdriver" +end + +gem "chartkick", "~> 5.2" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..1bc31ac --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,397 @@ +GEM + remote: https://rubygems.org/ + specs: + actioncable (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) + nio4r (~> 2.0) + websocket-driver (>= 0.6.1) + zeitwerk (~> 2.6) + actionmailbox (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + mail (>= 2.8.0) + actionmailer (8.0.2.1) + actionpack (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activesupport (= 8.0.2.1) + mail (>= 2.8.0) + rails-dom-testing (~> 2.2) + actionpack (8.0.2.1) + actionview (= 8.0.2.1) + activesupport (= 8.0.2.1) + nokogiri (>= 1.8.5) + rack (>= 2.2.4) + rack-session (>= 1.0.1) + rack-test (>= 0.6.3) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + useragent (~> 0.16) + actiontext (8.0.2.1) + actionpack (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + globalid (>= 0.6.0) + nokogiri (>= 1.8.5) + actionview (8.0.2.1) + activesupport (= 8.0.2.1) + builder (~> 3.1) + erubi (~> 1.11) + rails-dom-testing (~> 2.2) + rails-html-sanitizer (~> 1.6) + activejob (8.0.2.1) + activesupport (= 8.0.2.1) + globalid (>= 0.3.6) + activemodel (8.0.2.1) + activesupport (= 8.0.2.1) + activerecord (8.0.2.1) + activemodel (= 8.0.2.1) + activesupport (= 8.0.2.1) + timeout (>= 0.4.0) + activestorage (8.0.2.1) + actionpack (= 8.0.2.1) + activejob (= 8.0.2.1) + activerecord (= 8.0.2.1) + activesupport (= 8.0.2.1) + marcel (~> 1.0) + activesupport (8.0.2.1) + base64 + benchmark (>= 0.3) + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + uri (>= 0.13.1) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.3) + base64 (0.3.0) + bcrypt_pbkdf (1.1.1) + bcrypt_pbkdf (1.1.1-arm64-darwin) + bcrypt_pbkdf (1.1.1-x86_64-darwin) + benchmark (0.4.1) + bigdecimal (3.2.2) + bindex (0.8.1) + bootsnap (1.18.6) + msgpack (~> 1.2) + brakeman (7.1.0) + racc + builder (3.3.0) + capybara (3.40.0) + addressable + matrix + mini_mime (>= 0.1.3) + nokogiri (~> 1.11) + rack (>= 1.6.0) + rack-test (>= 0.6.3) + regexp_parser (>= 1.5, < 3.0) + xpath (~> 3.2) + chartkick (5.2.0) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) + crass (1.0.6) + date (3.4.1) + debug (1.11.0) + irb (~> 1.10) + reline (>= 0.3.8) + dotenv (3.1.8) + drb (2.2.3) + ed25519 (1.4.0) + erb (5.0.2) + erubi (1.13.1) + et-orbi (1.3.0) + tzinfo + fugit (1.11.1) + et-orbi (~> 1, >= 1.2.11) + raabro (~> 1.4) + globalid (1.2.1) + activesupport (>= 6.1) + i18n (1.14.7) + concurrent-ruby (~> 1.0) + importmap-rails (2.2.2) + actionpack (>= 6.0.0) + activesupport (>= 6.0.0) + railties (>= 6.0.0) + io-console (0.8.1) + irb (1.15.2) + pp (>= 0.6.0) + rdoc (>= 4.0.0) + reline (>= 0.4.2) + jbuilder (2.14.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + json (2.13.2) + kamal (2.7.0) + activesupport (>= 7.0) + base64 (~> 0.2) + bcrypt_pbkdf (~> 1.0) + concurrent-ruby (~> 1.2) + dotenv (~> 3.1) + ed25519 (~> 1.4) + net-ssh (~> 7.3) + sshkit (>= 1.23.0, < 2.0) + thor (~> 1.3) + zeitwerk (>= 2.6.18, < 3.0) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + loofah (2.24.1) + crass (~> 1.0.2) + nokogiri (>= 1.12.0) + mail (2.8.1) + mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp + marcel (1.0.4) + matrix (0.4.3) + mini_mime (1.1.5) + minitest (5.25.5) + msgpack (1.8.0) + net-imap (0.5.9) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.2) + timeout + net-scp (4.1.0) + net-ssh (>= 2.6.5, < 8.0.0) + net-sftp (4.0.0) + net-ssh (>= 5.0.0, < 8.0.0) + net-smtp (0.5.1) + net-protocol + net-ssh (7.3.0) + nio4r (2.7.4) + nokogiri (1.18.9-aarch64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-aarch64-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-arm-linux-musl) + racc (~> 1.4) + nokogiri (1.18.9-arm64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-darwin) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-gnu) + racc (~> 1.4) + nokogiri (1.18.9-x86_64-linux-musl) + racc (~> 1.4) + ostruct (0.6.3) + parallel (1.27.0) + parser (3.3.9.0) + ast (~> 2.4.1) + racc + pp (0.6.2) + prettyprint + prettyprint (0.2.0) + prism (1.4.0) + propshaft (1.2.1) + actionpack (>= 7.0.0) + activesupport (>= 7.0.0) + rack + psych (5.2.6) + date + stringio + public_suffix (6.0.2) + puma (6.6.1) + nio4r (~> 2.0) + raabro (1.4.0) + racc (1.8.1) + rack (3.2.0) + rack-session (2.1.1) + base64 (>= 0.1.0) + rack (>= 3.0.0) + rack-test (2.2.0) + rack (>= 1.3) + rackup (2.2.1) + rack (>= 3) + rails (8.0.2.1) + actioncable (= 8.0.2.1) + actionmailbox (= 8.0.2.1) + actionmailer (= 8.0.2.1) + actionpack (= 8.0.2.1) + actiontext (= 8.0.2.1) + actionview (= 8.0.2.1) + activejob (= 8.0.2.1) + activemodel (= 8.0.2.1) + activerecord (= 8.0.2.1) + activestorage (= 8.0.2.1) + activesupport (= 8.0.2.1) + bundler (>= 1.15.0) + railties (= 8.0.2.1) + rails-dom-testing (2.3.0) + activesupport (>= 5.0.0) + minitest + nokogiri (>= 1.6) + rails-html-sanitizer (1.6.2) + loofah (~> 2.21) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (8.0.2.1) + actionpack (= 8.0.2.1) + activesupport (= 8.0.2.1) + irb (~> 1.13) + rackup (>= 1.0.0) + rake (>= 12.2) + thor (~> 1.0, >= 1.2.2) + zeitwerk (~> 2.6) + rainbow (3.1.1) + rake (13.3.0) + rdoc (6.14.2) + erb + psych (>= 4.0.0) + regexp_parser (2.11.2) + reline (0.6.2) + io-console (~> 0.5) + rexml (3.4.1) + rubocop (1.79.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.25.0) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rails (2.33.3) + activesupport (>= 4.2.0) + lint_roller (~> 1.1) + rack (>= 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rails-omakase (1.1.0) + rubocop (>= 1.72) + rubocop-performance (>= 1.24) + rubocop-rails (>= 2.30) + ruby-progressbar (1.13.0) + rubyzip (3.0.1) + securerandom (0.4.1) + selenium-webdriver (4.35.0) + base64 (~> 0.2) + logger (~> 1.4) + rexml (~> 3.2, >= 3.2.5) + rubyzip (>= 1.2.2, < 4.0) + websocket (~> 1.0) + solid_cable (3.0.12) + actioncable (>= 7.2) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_cache (1.0.7) + activejob (>= 7.2) + activerecord (>= 7.2) + railties (>= 7.2) + solid_queue (1.2.1) + activejob (>= 7.1) + activerecord (>= 7.1) + concurrent-ruby (>= 1.3.1) + fugit (~> 1.11.0) + railties (>= 7.1) + thor (>= 1.3.1) + sqlite3 (2.7.3-aarch64-linux-gnu) + sqlite3 (2.7.3-aarch64-linux-musl) + sqlite3 (2.7.3-arm-linux-gnu) + sqlite3 (2.7.3-arm-linux-musl) + sqlite3 (2.7.3-arm64-darwin) + sqlite3 (2.7.3-x86_64-darwin) + sqlite3 (2.7.3-x86_64-linux-gnu) + sqlite3 (2.7.3-x86_64-linux-musl) + sshkit (1.24.0) + base64 + logger + net-scp (>= 1.1.2) + net-sftp (>= 2.1.2) + net-ssh (>= 2.8.0) + ostruct + stimulus-rails (1.3.4) + railties (>= 6.0.0) + stringio (3.1.7) + thor (1.4.0) + thruster (0.1.15) + thruster (0.1.15-aarch64-linux) + thruster (0.1.15-arm64-darwin) + thruster (0.1.15-x86_64-darwin) + thruster (0.1.15-x86_64-linux) + timeout (0.4.3) + turbo-rails (2.0.16) + actionpack (>= 7.1.0) + railties (>= 7.1.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (3.1.5) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.3) + useragent (0.16.11) + web-console (4.2.1) + actionview (>= 6.0.0) + activemodel (>= 6.0.0) + bindex (>= 0.4.0) + railties (>= 6.0.0) + websocket (1.2.11) + websocket-driver (0.8.0) + base64 + websocket-extensions (>= 0.1.0) + websocket-extensions (0.1.5) + xpath (3.2.0) + nokogiri (~> 1.8) + zeitwerk (2.7.3) + +PLATFORMS + aarch64-linux + aarch64-linux-gnu + aarch64-linux-musl + arm-linux-gnu + arm-linux-musl + arm64-darwin + x86_64-darwin + x86_64-linux-gnu + x86_64-linux-musl + +DEPENDENCIES + bootsnap + brakeman + capybara + chartkick (~> 5.2) + debug + importmap-rails + jbuilder + kamal + propshaft + puma (>= 5.0) + rails (~> 8.0.2, >= 8.0.2.1) + rubocop-rails-omakase + selenium-webdriver + solid_cable + solid_cache + solid_queue + sqlite3 (>= 2.1) + stimulus-rails + thruster + turbo-rails + tzinfo-data + web-console + +BUNDLED WITH + 2.6.9 diff --git a/README.md b/README.md new file mode 100644 index 0000000..7db80e4 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# README + +This README would normally document whatever steps are necessary to get the +application up and running. + +Things you may want to cover: + +* Ruby version + +* System dependencies + +* Configuration + +* Database creation + +* Database initialization + +* How to run the test suite + +* Services (job queues, cache servers, search engines, etc.) + +* Deployment instructions + +* ... diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..9a5ea73 --- /dev/null +++ b/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require_relative "config/application" + +Rails.application.load_tasks diff --git a/app/assets/images/.keep b/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 0000000..fe93333 --- /dev/null +++ b/app/assets/stylesheets/application.css @@ -0,0 +1,10 @@ +/* + * This is a manifest file that'll be compiled into application.css. + * + * With Propshaft, assets are served efficiently without preprocessing steps. You can still include + * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard + * cascading order, meaning styles declared later in the document or manifest will override earlier ones, + * depending on specificity. + * + * Consider organizing styles into separate files for maintainability. + */ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb new file mode 100644 index 0000000..0d95db2 --- /dev/null +++ b/app/controllers/application_controller.rb @@ -0,0 +1,4 @@ +class ApplicationController < ActionController::Base + # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. + allow_browser versions: :modern +end diff --git a/app/controllers/concerns/.keep b/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb new file mode 100644 index 0000000..9619852 --- /dev/null +++ b/app/controllers/crops_controller.rb @@ -0,0 +1,70 @@ +class CropsController < ApplicationController + before_action :set_crop, only: %i[ show edit update destroy ] + + # GET /crops or /crops.json + def index + @crops = Crop.all + end + + # GET /crops/1 or /crops/1.json + def show + end + + # GET /crops/new + def new + @crop = Crop.new + end + + # GET /crops/1/edit + def edit + end + + # POST /crops or /crops.json + def create + @crop = Crop.new(crop_params) + + respond_to do |format| + if @crop.save + format.html { redirect_to @crop, notice: "Crop was successfully created." } + format.json { render :show, status: :created, location: @crop } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @crop.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /crops/1 or /crops/1.json + def update + respond_to do |format| + if @crop.update(crop_params) + format.html { redirect_to @crop, notice: "Crop was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @crop } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @crop.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /crops/1 or /crops/1.json + def destroy + @crop.destroy! + + respond_to do |format| + format.html { redirect_to crops_path, notice: "Crop was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_crop + @crop = Crop.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def crop_params + params.expect(crop: [ :name, :crop_type, :nno3, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo, :nnh4 ]) + end +end diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb new file mode 100644 index 0000000..4e9d560 --- /dev/null +++ b/app/controllers/dashboard_controller.rb @@ -0,0 +1,45 @@ +class DashboardController < ApplicationController + def index + # Raft allocation by crop type + @raft_data = raft_data_series + + # Nutrient target table + @latest_measurement = NutrientMeasurement.order(measured_on: :desc, created_at: :desc).first + @target = TargetNutrientCalculator.call + + # Measurement history table + @measurements = NutrientMeasurement.order(measured_on: :desc).limit(10) + + @npk_measurement_data = measurement_data_series(:nno3, :p, :k) + @ammonium_measurement_data = measurement_data_series(:nnh4) + end + + private + + def raft_data_series + data_series = [] + + counts = Raft.left_outer_joins(:crop) + .group("crops.name", "crops.crop_type") + .count + + counts.each do |(crop_name, crop_type), count| + name = (crop_name || "unassigned").titleize + type = (crop_type || "unassigned").titleize + data = { type => count } + data_series << { name:, data: } + end + + unassigned, assigned = data_series.partition { |s| s[:name].casecmp("unassigned").zero? } + assigned + unassigned + end + + def measurement_data_series(*nutrients) + nutrients.map do |formula| + { name: Nutrient.find_by!(formula:).name, + data: NutrientMeasurement + .order(:measured_on) + .pluck(:measured_on, formula) } + end + end +end diff --git a/app/controllers/fertilizer_products_controller.rb b/app/controllers/fertilizer_products_controller.rb new file mode 100644 index 0000000..ff0d945 --- /dev/null +++ b/app/controllers/fertilizer_products_controller.rb @@ -0,0 +1,70 @@ +class FertilizerProductsController < ApplicationController + before_action :set_fertilizer_product, only: %i[ show edit update destroy ] + + # GET /fertilizer_products or /fertilizer_products.json + def index + @fertilizer_products = FertilizerProduct.all + end + + # GET /fertilizer_products/1 or /fertilizer_products/1.json + def show + end + + # GET /fertilizer_products/new + def new + @fertilizer_product = FertilizerProduct.new + end + + # GET /fertilizer_products/1/edit + def edit + end + + # POST /fertilizer_products or /fertilizer_products.json + def create + @fertilizer_product = FertilizerProduct.new(fertilizer_product_params) + + respond_to do |format| + if @fertilizer_product.save + format.html { redirect_to @fertilizer_product, notice: "Fertilizer product was successfully created." } + format.json { render :show, status: :created, location: @fertilizer_product } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @fertilizer_product.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /fertilizer_products/1 or /fertilizer_products/1.json + def update + respond_to do |format| + if @fertilizer_product.update(fertilizer_product_params) + format.html { redirect_to @fertilizer_product, notice: "Fertilizer product was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @fertilizer_product } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @fertilizer_product.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /fertilizer_products/1 or /fertilizer_products/1.json + def destroy + @fertilizer_product.destroy! + + respond_to do |format| + format.html { redirect_to fertilizer_products_path, notice: "Fertilizer product was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_fertilizer_product + @fertilizer_product = FertilizerProduct.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def fertilizer_product_params + params.expect(fertilizer_product: [ :name, :purity ]) + end +end diff --git a/app/controllers/fertilizers_controller.rb b/app/controllers/fertilizers_controller.rb new file mode 100644 index 0000000..040c462 --- /dev/null +++ b/app/controllers/fertilizers_controller.rb @@ -0,0 +1,70 @@ +class FertilizersController < ApplicationController + before_action :set_fertilizer, only: %i[ show edit update destroy ] + + # GET /fertilizers or /fertilizers.json + def index + @fertilizers = Fertilizer.all + end + + # GET /fertilizers/1 or /fertilizers/1.json + def show + end + + # GET /fertilizers/new + def new + @fertilizer = Fertilizer.new + end + + # GET /fertilizers/1/edit + def edit + end + + # POST /fertilizers or /fertilizers.json + def create + @fertilizer = Fertilizer.new(fertilizer_params) + + respond_to do |format| + if @fertilizer.save + format.html { redirect_to @fertilizer, notice: "Fertilizer was successfully created." } + format.json { render :show, status: :created, location: @fertilizer } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @fertilizer.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /fertilizers/1 or /fertilizers/1.json + def update + respond_to do |format| + if @fertilizer.update(fertilizer_params) + format.html { redirect_to @fertilizer, notice: "Fertilizer was successfully updated.", status: :see_other } + format.json { render :show, status: :ok, location: @fertilizer } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @fertilizer.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /fertilizers/1 or /fertilizers/1.json + def destroy + @fertilizer.destroy! + + respond_to do |format| + format.html { redirect_to fertilizers_path, notice: "Fertilizer was successfully destroyed.", status: :see_other } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_fertilizer + @fertilizer = Fertilizer.find(params.expect(:id)) + end + + # Only allow a list of trusted parameters through. + def fertilizer_params + params.expect(fertilizer: [ :name, :formula, :nno3, :nnh4, :p, :k, :ca, :mg, :s, :na, :cl, :si, :fe, :zn, :b, :mn, :cu, :mo ]) + end +end diff --git a/app/controllers/nutrient_measurement_controller.rb b/app/controllers/nutrient_measurement_controller.rb new file mode 100644 index 0000000..6d26bfa --- /dev/null +++ b/app/controllers/nutrient_measurement_controller.rb @@ -0,0 +1,4 @@ +class NutrientMeasurementController < ApplicationController + def index + end +end diff --git a/app/controllers/rafts_controller.rb b/app/controllers/rafts_controller.rb new file mode 100644 index 0000000..96d99fd --- /dev/null +++ b/app/controllers/rafts_controller.rb @@ -0,0 +1,54 @@ +class RaftsController < ApplicationController + before_action :set_collections, only: [ :editor ] + + def index + redirect_to editor_rafts_path + end + + def editor + # @beds, @crops set in before_action + end + + # 1) Assign ALL rafts + def assign_all + crop_id = normalized_crop_id(params[:crop_id]) + Raft.update_all(crop_id: crop_id) # nil ok + redirect_to editor_rafts_path, notice: "All rafts updated." + end + + # 2) Assign all rafts in ONE bed + def assign_bed + bed = Bed.find(params.require(:bed_id)) + crop_id = normalized_crop_id(params[:crop_id]) + bed.rafts.update_all(crop_id: crop_id) + redirect_to editor_rafts_path, notice: "Bed ##{bed.location} updated." + end + + # 3) Assign ONE raft + def assign_one + raft = Raft.find(params[:id]) + val = params[:crop_id].to_s + + if val.blank? || val.casecmp("null").zero? + # Skip validations; write NULL directly + raft.update_column(:crop_id, nil) + else + raft.update!(crop_id: val) + end + + redirect_to editor_rafts_path(anchor: "bed-#{raft.bed_id}"), notice: "Raft updated." + end + + private + + def set_collections + @beds = Bed.order(:location) + @crops = Crop.order(:name) + end + + # Accept "", "null" → nil to allow clearing + def normalized_crop_id(val) + return nil if val.blank? || val.to_s.downcase == "null" + val + end +end diff --git a/app/controllers/recipes_controller.rb b/app/controllers/recipes_controller.rb new file mode 100644 index 0000000..bcc29e7 --- /dev/null +++ b/app/controllers/recipes_controller.rb @@ -0,0 +1,8 @@ +class RecipesController < ApplicationController + def show + @latest = NutrientMeasurement.order(:measured_on).last || NutrientMeasurement.new + @target = TargetNutrientCalculator.call + volume = (params[:volume].presence || 100_000).to_i + @recipe = FertilizerRecipeCalculator.call(@latest, @target, water_volume_l: volume) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb new file mode 100644 index 0000000..5d64d17 --- /dev/null +++ b/app/helpers/dashboard_helper.rb @@ -0,0 +1,8 @@ +module DashboardHelper + def fmt2(v) = number_with_precision(v, precision: 2) + + # Total nitrogen (NO3-N + NH4-N) + def total_n(measurement) + (measurement.nno3.to_f) + (measurement.nnh4.to_f) + end +end diff --git a/app/helpers/nutrients_helper.rb b/app/helpers/nutrients_helper.rb new file mode 100644 index 0000000..de98dc3 --- /dev/null +++ b/app/helpers/nutrients_helper.rb @@ -0,0 +1,21 @@ +module NutrientsHelper + NUTRIENTS = %i[nno3 p k ca mg s na cl si fe zn b mn cu mo nnh4].freeze + + def percent_delta(measured, target) + return 0.0 if target.to_f.zero? + ((measured.to_f - target.to_f) / target.to_f) * 100.0 + end + + def fmt(v) + number_with_precision(v, precision: 2, strip_insignificant_zeros: true) + end + + def delta_badge_class(delta) + d = delta.abs + case d + when d < 0 then "bg-info" + when 0..5 then "bg-secondary" + else "bg-warning" + end + end +end diff --git a/app/helpers/recipes_helper.rb b/app/helpers/recipes_helper.rb new file mode 100644 index 0000000..02cb1a7 --- /dev/null +++ b/app/helpers/recipes_helper.rb @@ -0,0 +1,16 @@ +module RecipesHelper + def commercial_name_for(component) + # Try to find a FertilizerProduct via a join, but gracefully fallback. + if defined?(FertilizerProduct) && defined?(FertilizerComposition) + prod = FertilizerProduct.joins(:fertilizer_compositions) + .where(fertilizer_compositions: { fertilizer_component_id: component.id }) + .first + return prod.name if prod&.name.present? + end + component.name.presence || component.formula + end + + def fmt_kg(v) + number_with_precision(v.to_f, precision: 2, strip_insignificant_zeros: true) + end +end diff --git a/app/javascript/application.js b/app/javascript/application.js new file mode 100644 index 0000000..beff742 --- /dev/null +++ b/app/javascript/application.js @@ -0,0 +1 @@ +// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb new file mode 100644 index 0000000..d394c3d --- /dev/null +++ b/app/jobs/application_job.rb @@ -0,0 +1,7 @@ +class ApplicationJob < ActiveJob::Base + # Automatically retry jobs that encountered a deadlock + # retry_on ActiveRecord::Deadlocked + + # Most jobs are safe to ignore if the underlying records are no longer available + # discard_on ActiveJob::DeserializationError +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb new file mode 100644 index 0000000..3c34c81 --- /dev/null +++ b/app/mailers/application_mailer.rb @@ -0,0 +1,4 @@ +class ApplicationMailer < ActionMailer::Base + default from: "from@example.com" + layout "mailer" +end diff --git a/app/models/application_record.rb b/app/models/application_record.rb new file mode 100644 index 0000000..b63caeb --- /dev/null +++ b/app/models/application_record.rb @@ -0,0 +1,3 @@ +class ApplicationRecord < ActiveRecord::Base + primary_abstract_class +end diff --git a/app/models/bed.rb b/app/models/bed.rb new file mode 100644 index 0000000..33eafd2 --- /dev/null +++ b/app/models/bed.rb @@ -0,0 +1,4 @@ +class Bed < ApplicationRecord + has_many :rafts, -> { order(:location) }, dependent: :destroy + validates :location, presence: true, uniqueness: true +end diff --git a/app/models/concerns/.keep b/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/app/models/crop.rb b/app/models/crop.rb new file mode 100644 index 0000000..b0f168d --- /dev/null +++ b/app/models/crop.rb @@ -0,0 +1,4 @@ +class Crop < ApplicationRecord + has_many :rafts + enum :crop_type, { leafy: 0, fruit: 1, herb: 2 } +end diff --git a/app/models/fertilizer_component.rb b/app/models/fertilizer_component.rb new file mode 100644 index 0000000..701ae9b --- /dev/null +++ b/app/models/fertilizer_component.rb @@ -0,0 +1,3 @@ +class FertilizerComponent < ApplicationRecord + validates :name, presence: true +end diff --git a/app/models/fertilizer_composition.rb b/app/models/fertilizer_composition.rb new file mode 100644 index 0000000..cf2bb93 --- /dev/null +++ b/app/models/fertilizer_composition.rb @@ -0,0 +1,6 @@ +class FertilizerComposition < ApplicationRecord + belongs_to :fertilizer_product + belongs_to :fertilizer_component + + validates :percent_w, numericality: { greater_than: 0, less_than_or_equal_to: 100 } +end diff --git a/app/models/fertilizer_product.rb b/app/models/fertilizer_product.rb new file mode 100644 index 0000000..e41316b --- /dev/null +++ b/app/models/fertilizer_product.rb @@ -0,0 +1,7 @@ +class FertilizerProduct < ApplicationRecord + has_many :fertilizer_compositions, dependent: :destroy + has_many :fertilizer_components, through: :fertilizer_compositions + + validates :name, presence: true, uniqueness: true + validates :purity, numericality: { greater_than: 0, less_than_or_equal_to: 100 } +end diff --git a/app/models/nutrient.rb b/app/models/nutrient.rb new file mode 100644 index 0000000..c584668 --- /dev/null +++ b/app/models/nutrient.rb @@ -0,0 +1,7 @@ +class Nutrient < ApplicationRecord + validates :formula, presence: true, uniqueness: true + validates :name, presence: true + + before_update { raise ActiveRecord::ReadOnlyRecord } + before_destroy { raise ActiveRecord::ReadOnlyRecord } +end diff --git a/app/models/nutrient_measurement.rb b/app/models/nutrient_measurement.rb new file mode 100644 index 0000000..f1d6d5b --- /dev/null +++ b/app/models/nutrient_measurement.rb @@ -0,0 +1,4 @@ +class NutrientMeasurement < ApplicationRecord + validates :measured_on, presence: true + validates :measured_on, uniqueness: true +end diff --git a/app/models/raft.rb b/app/models/raft.rb new file mode 100644 index 0000000..af52700 --- /dev/null +++ b/app/models/raft.rb @@ -0,0 +1,5 @@ +class Raft < ApplicationRecord + belongs_to :bed + belongs_to :crop + validates :location, presence: true, uniqueness: { scope: :bed_id } +end diff --git a/app/services/fertilizer_recipe_calculator.rb b/app/services/fertilizer_recipe_calculator.rb new file mode 100644 index 0000000..28ba8aa --- /dev/null +++ b/app/services/fertilizer_recipe_calculator.rb @@ -0,0 +1,136 @@ +class FertilizerRecipeCalculator + NUTRIENTS = %i[nno3 p k ca mg s nnh4].freeze + + def self.call(latest, target, water_volume_l: 100_000) + new(latest, target, water_volume_l).call + end + + def initialize(latest, target, water_volume_l) + @latest = latest || NutrientMeasurement.new + @target = target || NutrientMeasurement.new + @vol_l = water_volume_l.to_f + end + + # Returns a Hash { FertilizerComponent => qty_kg } + def call + deltas_mg_per_l = NUTRIENTS.index_with do |k| + [ (value(@target, k) - value(@latest, k)), 0 ].max + end + + # mg/L * L = mg -> kg + needed_kg = deltas_mg_per_l.transform_values { |mg_l| mg_l * @vol_l / 1_000_000.0 } + + recipe = Hash.new(0.0) + + # 1) P via MAP or DAP (accounts NH4-N) + if (p_need = needed_kg[:p]) > 0 + map = fc_by_formula("MAP") || fc_by_name_like("monoammonium phosphate") + dap = fc_by_formula("DAP") || fc_by_name_like("diammonium phosphate") + carrier = [ map, dap ].compact.find { |c| positive?(c.p) } + if carrier + kg = kg_for(p_need, carrier.p) + recipe[carrier] += kg + needed_kg[:nnh4] = [ needed_kg[:nnh4] - kg * pct(carrier.nnh4), 0 ].max if positive?(carrier.nnh4) + needed_kg[:p] = 0 + end + end + + # 2) NO3-N via KNO3 then Ca(NO3)2 (accounts K/Ca) + if (n_need = needed_kg[:nno3]) > 0 + kno3 = fc_by_formula("KNO3") || fc_by_name_like("potassium nitrate") + can = fc_by_formula("Ca(NO3)2") || fc_by_name_like("calcium nitrate") + + if kno3&.nno3.to_f > 0 + kg = kg_for(n_need, kno3.nno3) + recipe[kno3] += kg + needed_kg[:k] = [ needed_kg[:k] - kg * pct(kno3.k), 0 ].max + n_need -= kg * pct(kno3.nno3) + end + + if n_need > 0 && can&.nno3.to_f > 0 + kg = kg_for(n_need, can.nno3) + recipe[can] += kg + needed_kg[:ca] = [ needed_kg[:ca] - kg * pct(can.ca), 0 ].max + n_need = 0 + end + + needed_kg[:nno3] = [ n_need, 0 ].max + end + + # 3) K via K2SO4 (accounts S) + if (k_need = needed_kg[:k]) > 0 + sop = fc_by_formula("K2SO4") || fc_by_name_like("potassium sulfate") + if sop&.k.to_f > 0 + kg = kg_for(k_need, sop.k) + recipe[sop] += kg + needed_kg[:s] = [ needed_kg[:s] - kg * pct(sop.s), 0 ].max + needed_kg[:k] = 0 + end + end + + # 4) Ca via Ca(NO3)2 (accounts NO3-N) + if (ca_need = needed_kg[:ca]) > 0 + can = recipe.keys.find { |c| norm_formula(c) == "ca(no3)2" } || + fc_by_formula("Ca(NO3)2") || fc_by_name_like("calcium nitrate") + if can&.ca.to_f > 0 + kg = kg_for(ca_need, can.ca) + recipe[can] += kg + needed_kg[:nno3] = [ needed_kg[:nno3] - kg * pct(can.nno3), 0 ].max + needed_kg[:ca] = 0 + end + end + + # 5) Mg via MgSO4 (accounts S) + if (mg_need = needed_kg[:mg]) > 0 + mgs = fc_by_formula("MgSO4") || fc_by_name_like("magnesium sulfate") + if mgs&.mg.to_f > 0 + kg = kg_for(mg_need, mgs.mg) + recipe[mgs] += kg + needed_kg[:s] = [ needed_kg[:s] - kg * pct(mgs.s), 0 ].max + needed_kg[:mg] = 0 + end + end + + # 6) S via K2SO4 or MgSO4 (whichever we already used or find) + if (s_need = needed_kg[:s]) > 0 + sop = recipe.keys.find { |c| norm_formula(c) == "k2so4" } || + fc_by_formula("K2SO4") || fc_by_name_like("potassium sulfate") + mgs = recipe.keys.find { |c| norm_formula(c) == "mgso4" } || + fc_by_formula("MgSO4") || fc_by_name_like("magnesium sulfate") + carrier = [ sop, mgs ].compact.find { |c| positive?(c.s) } + if carrier + kg = kg_for(s_need, carrier.s) + recipe[carrier] += kg + needed_kg[:k] = [ needed_kg[:k] - kg * pct(carrier.k), 0 ].max if positive?(carrier.k) + needed_kg[:mg] = [ needed_kg[:mg] - kg * pct(carrier.mg), 0 ].max if positive?(carrier.mg) + needed_kg[:s] = 0 + end + end + + recipe.delete_if { |_c, kg| kg < 0.01 } + recipe + end + + private + + def value(obj, key) = obj.public_send(key).to_f + + def fc_by_formula(formula) + FertilizerComponent.where("LOWER(formula) = ?", formula.to_s.downcase).first + end + + def fc_by_name_like(name) + FertilizerComponent.where("LOWER(name) LIKE ?", "%#{name.downcase}%").first + end + + def kg_for(need_kg_element, percent_in_product) + return 0.0 unless positive?(percent_in_product) + need_kg_element / pct(percent_in_product) + end + + def pct(v) = v.to_f / 100.0 + + def positive?(v) = v.to_f > 0.0 + + def norm_formula(c) = c.formula.to_s.downcase.gsub(/\s+/, "") +end diff --git a/app/services/target_nutrient_calculator.rb b/app/services/target_nutrient_calculator.rb new file mode 100644 index 0000000..e6cd378 --- /dev/null +++ b/app/services/target_nutrient_calculator.rb @@ -0,0 +1,33 @@ +class TargetNutrientCalculator + # Derive nutrient columns from the NutrientMeasurement table + NUTRIENT_COLUMNS = (NutrientMeasurement.column_names - %w[id measured_on created_at updated_at]) + .map!(&:to_sym) + .freeze + + # Returns an unsaved NutrientMeasurement with target concentrations (e.g., mg/L) + def self.call + rafts = Raft.includes(:crop).where.not(crop_id: nil) + total = rafts.count + return empty_measurement if total.zero? + + sums = Hash.new(0.0) + + rafts.each do |raft| + NUTRIENT_COLUMNS.each do |col| + v = raft.crop.public_send(col) + sums[col] += v.to_f if v + end + end + + targets = sums.transform_values { |s| s / total } + NutrientMeasurement.new({ measured_on: Date.current }.merge(targets)) + end + + private + + def empty_measurement + NutrientMeasurement.new( + { measured_on: Date.current }.merge(NUTRIENT_COLUMNS.index_with { 0.0 }) + ) + end +end diff --git a/app/views/application/_copyright_footer.html.erb b/app/views/application/_copyright_footer.html.erb new file mode 100644 index 0000000..4a6d240 --- /dev/null +++ b/app/views/application/_copyright_footer.html.erb @@ -0,0 +1,10 @@ + diff --git a/app/views/application/_navbar.html.erb b/app/views/application/_navbar.html.erb new file mode 100644 index 0000000..9fa250a --- /dev/null +++ b/app/views/application/_navbar.html.erb @@ -0,0 +1,33 @@ + diff --git a/app/views/crops/_crop.html.erb b/app/views/crops/_crop.html.erb new file mode 100644 index 0000000..e9b9b4d --- /dev/null +++ b/app/views/crops/_crop.html.erb @@ -0,0 +1,92 @@ +
+

+ Name: + <%= crop.name %> +

+ +

+ Crop type: + <%= crop.crop_type %> +

+ +

+ Nno3: + <%= crop.nno3 %> +

+ +

+ P: + <%= crop.p %> +

+ +

+ K: + <%= crop.k %> +

+ +

+ Ca: + <%= crop.ca %> +

+ +

+ Mg: + <%= crop.mg %> +

+ +

+ S: + <%= crop.s %> +

+ +

+ Na: + <%= crop.na %> +

+ +

+ Cl: + <%= crop.cl %> +

+ +

+ Si: + <%= crop.si %> +

+ +

+ Fe: + <%= crop.fe %> +

+ +

+ Zn: + <%= crop.zn %> +

+ +

+ B: + <%= crop.b %> +

+ +

+ Mn: + <%= crop.mn %> +

+ +

+ Cu: + <%= crop.cu %> +

+ +

+ Mo: + <%= crop.mo %> +

+ +

+ Nnh4: + <%= crop.nnh4 %> +

+ +
diff --git a/app/views/crops/_form.html.erb b/app/views/crops/_form.html.erb new file mode 100644 index 0000000..90226b6 --- /dev/null +++ b/app/views/crops/_form.html.erb @@ -0,0 +1,107 @@ +<%= form_with(model: crop) do |form| %> + <% if crop.errors.any? %> +
+

<%= pluralize(crop.errors.count, "error") %> prohibited this crop from being saved:

+ +
    + <% crop.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :crop_type, style: "display: block" %> + <%= form.number_field :crop_type %> +
+ +
+ <%= form.label :nno3, style: "display: block" %> + <%= form.text_field :nno3 %> +
+ +
+ <%= form.label :p, style: "display: block" %> + <%= form.text_field :p %> +
+ +
+ <%= form.label :k, style: "display: block" %> + <%= form.text_field :k %> +
+ +
+ <%= form.label :ca, style: "display: block" %> + <%= form.text_field :ca %> +
+ +
+ <%= form.label :mg, style: "display: block" %> + <%= form.text_field :mg %> +
+ +
+ <%= form.label :s, style: "display: block" %> + <%= form.text_field :s %> +
+ +
+ <%= form.label :na, style: "display: block" %> + <%= form.text_field :na %> +
+ +
+ <%= form.label :cl, style: "display: block" %> + <%= form.text_field :cl %> +
+ +
+ <%= form.label :si, style: "display: block" %> + <%= form.text_field :si %> +
+ +
+ <%= form.label :fe, style: "display: block" %> + <%= form.text_field :fe %> +
+ +
+ <%= form.label :zn, style: "display: block" %> + <%= form.text_field :zn %> +
+ +
+ <%= form.label :b, style: "display: block" %> + <%= form.text_field :b %> +
+ +
+ <%= form.label :mn, style: "display: block" %> + <%= form.text_field :mn %> +
+ +
+ <%= form.label :cu, style: "display: block" %> + <%= form.text_field :cu %> +
+ +
+ <%= form.label :mo, style: "display: block" %> + <%= form.text_field :mo %> +
+ +
+ <%= form.label :nnh4, style: "display: block" %> + <%= form.text_field :nnh4 %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/crops/edit.html.erb b/app/views/crops/edit.html.erb new file mode 100644 index 0000000..54c616c --- /dev/null +++ b/app/views/crops/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing crop" %> + +

Editing crop

+ +<%= render "form", crop: @crop %> + +
+ +
+ <%= link_to "Show this crop", @crop %> | + <%= link_to "Back to crops", crops_path %> +
diff --git a/app/views/crops/index.html.erb b/app/views/crops/index.html.erb new file mode 100644 index 0000000..bae09fa --- /dev/null +++ b/app/views/crops/index.html.erb @@ -0,0 +1,16 @@ +

<%= notice %>

+ +<% content_for :title, "Crops" %> + +

Crops

+ +
+ <% @crops.each do |crop| %> + <%= render crop %> +

+ <%= link_to "Show this crop", crop %> +

+ <% end %> +
+ +<%= link_to "New crop", new_crop_path %> diff --git a/app/views/crops/new.html.erb b/app/views/crops/new.html.erb new file mode 100644 index 0000000..4ef4da5 --- /dev/null +++ b/app/views/crops/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New crop" %> + +

New crop

+ +<%= render "form", crop: @crop %> + +
+ +
+ <%= link_to "Back to crops", crops_path %> +
diff --git a/app/views/crops/show.html.erb b/app/views/crops/show.html.erb new file mode 100644 index 0000000..971f097 --- /dev/null +++ b/app/views/crops/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @crop %> + +
+ <%= link_to "Edit this crop", edit_crop_path(@crop) %> | + <%= link_to "Back to crops", crops_path %> + + <%= button_to "Destroy this crop", @crop, method: :delete %> +
diff --git a/app/views/dashboard/_raft_allocation.html.erb b/app/views/dashboard/_raft_allocation.html.erb new file mode 100644 index 0000000..ef95cdd --- /dev/null +++ b/app/views/dashboard/_raft_allocation.html.erb @@ -0,0 +1,9 @@ +
+
+
Raft Allocation
+ <%= link_to "Edit raft allocation", editor_rafts_path, class: "btn btn-sm btn-primary" %> +
+ + <%= bar_chart @raft_data, stacked: true %> +
+ diff --git a/app/views/dashboard/_recent_measurements.html.erb b/app/views/dashboard/_recent_measurements.html.erb new file mode 100644 index 0000000..bc63a60 --- /dev/null +++ b/app/views/dashboard/_recent_measurements.html.erb @@ -0,0 +1,22 @@ +
+
+
Nutrient Measurements
+
+ <%#= link_to "Add new measurement", editor_rafts_path, class: "btn btn-sm btn-primary" %> + <%#= link_to "View all", editor_rafts_path, class: "btn btn-sm btn-secondary" %> +
+
+ +
+
+ <%= line_chart @npk_measurement_data, + title: "NPK", + ytitle: "Concentration (mg/L)" %> +
+
+ <%= line_chart @ammonium_measurement_data, + title: "Ammonium", + ytitle: "Concentration (mg/L)" %> +
+
+
diff --git a/app/views/dashboard/_target_table.html.erb b/app/views/dashboard/_target_table.html.erb new file mode 100644 index 0000000..b8f7e66 --- /dev/null +++ b/app/views/dashboard/_target_table.html.erb @@ -0,0 +1,40 @@ +
+
+
Target nutrient concentrations
+ <%= link_to "Get Ferti© recipe", ferti_recipe_path, class: "btn btn-sm btn-primary" %> +
+ +
+ + + + + + + + + + + <% NutrientsHelper::NUTRIENTS.each do |n| %> + <% latest = @latest_measurement[n] || 0 %> + <% target = @target[n] || 0 %> + <% delta = target - latest %> + + + + + + + <% end %> + +
Nutrient Latest (mg/L) + Target (mg/L)Δ %
<%= n.upcase %><%= fmt(latest) %><%= fmt(target) %> + + <%= fmt(delta) %>% + +
+
+ +
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb new file mode 100644 index 0000000..2902ada --- /dev/null +++ b/app/views/dashboard/index.html.erb @@ -0,0 +1,7 @@ +

Ferti

+ +<%= render "raft_allocation" %> + +<%= render "target_table" %> + +<%= render "recent_measurements" %> diff --git a/app/views/fertilizer_products/_fertilizer_product.html.erb b/app/views/fertilizer_products/_fertilizer_product.html.erb new file mode 100644 index 0000000..d84a03d --- /dev/null +++ b/app/views/fertilizer_products/_fertilizer_product.html.erb @@ -0,0 +1,12 @@ +
+

+ Name: + <%= fertilizer_product.name %> +

+ +

+ Purity: + <%= fertilizer_product.purity %> +

+ +
diff --git a/app/views/fertilizer_products/_form.html.erb b/app/views/fertilizer_products/_form.html.erb new file mode 100644 index 0000000..517fe09 --- /dev/null +++ b/app/views/fertilizer_products/_form.html.erb @@ -0,0 +1,27 @@ +<%= form_with(model: fertilizer_product) do |form| %> + <% if fertilizer_product.errors.any? %> +
+

<%= pluralize(fertilizer_product.errors.count, "error") %> prohibited this fertilizer_product from being saved:

+ +
    + <% fertilizer_product.errors.each do |error| %> +
  • <%= error.full_message %>
  • + <% end %> +
+
+ <% end %> + +
+ <%= form.label :name, style: "display: block" %> + <%= form.text_field :name %> +
+ +
+ <%= form.label :purity, style: "display: block" %> + <%= form.text_field :purity %> +
+ +
+ <%= form.submit %> +
+<% end %> diff --git a/app/views/fertilizer_products/edit.html.erb b/app/views/fertilizer_products/edit.html.erb new file mode 100644 index 0000000..aa88dad --- /dev/null +++ b/app/views/fertilizer_products/edit.html.erb @@ -0,0 +1,12 @@ +<% content_for :title, "Editing fertilizer product" %> + +

Editing fertilizer product

+ +<%= render "form", fertilizer_product: @fertilizer_product %> + +
+ +
+ <%= link_to "Show this fertilizer product", @fertilizer_product %> | + <%= link_to "Back to fertilizer products", fertilizer_products_path %> +
diff --git a/app/views/fertilizer_products/index.html.erb b/app/views/fertilizer_products/index.html.erb new file mode 100644 index 0000000..f624ffc --- /dev/null +++ b/app/views/fertilizer_products/index.html.erb @@ -0,0 +1,16 @@ +

<%= notice %>

+ +<% content_for :title, "Fertilizer products" %> + +

Fertilizer products

+ +
+ <% @fertilizer_products.each do |fertilizer_product| %> + <%= render fertilizer_product %> +

+ <%= link_to "Show this fertilizer product", fertilizer_product %> +

+ <% end %> +
+ +<%= link_to "New fertilizer product", new_fertilizer_product_path %> diff --git a/app/views/fertilizer_products/new.html.erb b/app/views/fertilizer_products/new.html.erb new file mode 100644 index 0000000..81aad79 --- /dev/null +++ b/app/views/fertilizer_products/new.html.erb @@ -0,0 +1,11 @@ +<% content_for :title, "New fertilizer product" %> + +

New fertilizer product

+ +<%= render "form", fertilizer_product: @fertilizer_product %> + +
+ +
+ <%= link_to "Back to fertilizer products", fertilizer_products_path %> +
diff --git a/app/views/fertilizer_products/show.html.erb b/app/views/fertilizer_products/show.html.erb new file mode 100644 index 0000000..ea97041 --- /dev/null +++ b/app/views/fertilizer_products/show.html.erb @@ -0,0 +1,10 @@ +

<%= notice %>

+ +<%= render @fertilizer_product %> + +
+ <%= link_to "Edit this fertilizer product", edit_fertilizer_product_path(@fertilizer_product) %> | + <%= link_to "Back to fertilizer products", fertilizer_products_path %> + + <%= button_to "Destroy this fertilizer product", @fertilizer_product, method: :delete %> +
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb new file mode 100644 index 0000000..bf61c9d --- /dev/null +++ b/app/views/layouts/application.html.erb @@ -0,0 +1,46 @@ + + + + <%= content_for(:title) || "Ferti" %> + + + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + + <%= yield :head %> + + <%# Enable PWA manifest for installable apps (make sure to enable in config/routes.rb too!) %> + <%#= tag.link rel: "manifest", href: pwa_manifest_path(format: :json) %> + + + + + + <%# Includes all stylesheet files in app/assets/stylesheets %> + <%= stylesheet_link_tag :app, "data-turbo-track": "reload" %> + + + + + + + + + + <%= javascript_importmap_tags %> + + + + <%= render "application/navbar" %> + +
+ <%= yield %> +
+ + <%= render "application/copyright_footer" %> + + + + + diff --git a/app/views/layouts/mailer.html.erb b/app/views/layouts/mailer.html.erb new file mode 100644 index 0000000..3aac900 --- /dev/null +++ b/app/views/layouts/mailer.html.erb @@ -0,0 +1,13 @@ + + + + + + + + + <%= yield %> + + diff --git a/app/views/layouts/mailer.text.erb b/app/views/layouts/mailer.text.erb new file mode 100644 index 0000000..37f0bdd --- /dev/null +++ b/app/views/layouts/mailer.text.erb @@ -0,0 +1 @@ +<%= yield %> diff --git a/app/views/nutrient_measurement/index.html.erb b/app/views/nutrient_measurement/index.html.erb new file mode 100644 index 0000000..d9f522e --- /dev/null +++ b/app/views/nutrient_measurement/index.html.erb @@ -0,0 +1,27 @@ +

NutrientMeasurement#index

+

Find me in app/views/nutrient_measurement/index.html.erb

+ +
+ + + + + + + + + + + + <% @measurements.each do |m| %> + + + + + + + + <% end %> + +
DateN (total)PKNH₄‑N
<%= l(m.measured_on) %><%= fmt2(total_n(m)) %><%= fmt2(m.p) %><%= fmt2(m.k) %><%= fmt2(m.nnh4) %>
+
diff --git a/app/views/pwa/manifest.json.erb b/app/views/pwa/manifest.json.erb new file mode 100644 index 0000000..f8908f0 --- /dev/null +++ b/app/views/pwa/manifest.json.erb @@ -0,0 +1,22 @@ +{ + "name": "Ferti", + "icons": [ + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512" + }, + { + "src": "/icon.png", + "type": "image/png", + "sizes": "512x512", + "purpose": "maskable" + } + ], + "start_url": "/", + "display": "standalone", + "scope": "/", + "description": "Ferti.", + "theme_color": "red", + "background_color": "red" +} diff --git a/app/views/pwa/service-worker.js b/app/views/pwa/service-worker.js new file mode 100644 index 0000000..b3a13fb --- /dev/null +++ b/app/views/pwa/service-worker.js @@ -0,0 +1,26 @@ +// Add a service worker for processing Web Push notifications: +// +// self.addEventListener("push", async (event) => { +// const { title, options } = await event.data.json() +// event.waitUntil(self.registration.showNotification(title, options)) +// }) +// +// self.addEventListener("notificationclick", function(event) { +// event.notification.close() +// event.waitUntil( +// clients.matchAll({ type: "window" }).then((clientList) => { +// for (let i = 0; i < clientList.length; i++) { +// let client = clientList[i] +// let clientPath = (new URL(client.url)).pathname +// +// if (clientPath == event.notification.data.path && "focus" in client) { +// return client.focus() +// } +// } +// +// if (clients.openWindow) { +// return clients.openWindow(event.notification.data.path) +// } +// }) +// ) +// }) diff --git a/app/views/rafts/editor.html.erb b/app/views/rafts/editor.html.erb new file mode 100644 index 0000000..cde56d8 --- /dev/null +++ b/app/views/rafts/editor.html.erb @@ -0,0 +1,108 @@ +
+

Rafts editor

+ <%= link_to "Back to dashboard", root_path, class: "btn btn-outline-secondary" %> +
+ + +
+
Assign ALL rafts
+
+ <%= form_with url: assign_all_rafts_path, method: :patch, class: "row g-2", data: { turbo: false } do %> +
+ +
+
+ +
+ <% end %> +
+
+ +
+ + + + + <% max_cols = @beds.map { |b| b.rafts.count }.max %> + <% (1..max_cols).each do |i| %> + + <% end %> + + + + <% @beds.each do |bed| %> + + + <% bed.rafts.order(:location).each do |raft| %> + + <% end %> + + <% end %> + +
BedR<%= i %>
<%= bed.location %> + <% if raft.crop %> + <%= raft.crop.name %> + <% else %> + — + <% end %> +
+
+ + +<% @beds.each do |bed| %> +
+
+ Bed #<%= bed.location %> + <%= form_with url: assign_bed_rafts_path, method: :patch, class: "d-flex gap-2 align-items-center", data: { turbo: false } do %> + + + + <% end %> +
+
+
+ + + + + + + + + + <% bed.rafts.order(:location).each do |raft| %> + + + + + + <% end %> + +
RaftCropActions
<%= raft.location %> + <%= form_with url: assign_one_raft_path(raft), method: :patch, class: "d-flex gap-2", data: { turbo: false } do %> + + + <% end %> + + <%= button_to "Clear", assign_one_raft_path(raft, crop_id: ""), method: :patch, + form: { data: { turbo: false } }, class: "btn btn-outline-secondary btn-sm" %> +
+
+
+
+<% end %> diff --git a/app/views/recipes/_table.html.erb b/app/views/recipes/_table.html.erb new file mode 100644 index 0000000..a42a0b9 --- /dev/null +++ b/app/views/recipes/_table.html.erb @@ -0,0 +1,32 @@ +
+ + + + + + + + + + + <% pcount = [[portions.to_i, 2].max, 10].min %> + <% recipe&.each do |component, kg| %> + <% prod_name = commercial_name_for(component) %> + + + + + + + <% end %> + <% if recipe.blank? %> + + <% end %> + +
Fertilizer productComponentQty (kg)Per portion (kg)
<%= prod_name %><%= component.name %><%= fmt_kg(kg) %><%= fmt_kg(kg / pcount.to_f) %>
No supplementation required.
+
+ + diff --git a/app/views/recipes/show.html.erb b/app/views/recipes/show.html.erb new file mode 100644 index 0000000..180fdae --- /dev/null +++ b/app/views/recipes/show.html.erb @@ -0,0 +1,108 @@ + +<%# Controls header %> +
+
+
Ferti© Recipe
+ +
+ <%= form_with url: ferti_recipe_path, method: :get, local: true, class: "d-flex flex-wrap gap-2 align-items-center", id: "recipe-form" do %> +
+ + +
+ +
+ +
+ + +
+ <% end %> + + <%= link_to "Back", root_path, class: "btn btn-sm btn-secondary" %> +
+
+ +
+ + + + + + + + + + + <% @recipe.each do |component, kg| %> + <% prod_name = commercial_name_for(component) %> + + + + + + + <% end %> + <% if @recipe.blank? %> + + <% end %> + +
ProductFertilizerQty (kg)Per portion (kg)
<%= prod_name %><%= component.name %><%= fmt_kg(kg) %><%= fmt_kg(kg / (params[:portions].presence || 2).to_f) %>
No supplementation required.
+
+ + +
+ +<%# Tiny vanilla JS: auto-submit on volume change; live per-portion update %> + diff --git a/bin/brakeman b/bin/brakeman new file mode 100755 index 0000000..ace1c9b --- /dev/null +++ b/bin/brakeman @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +ARGV.unshift("--ensure-latest") + +load Gem.bin_path("brakeman", "brakeman") diff --git a/bin/dev b/bin/dev new file mode 100755 index 0000000..5f91c20 --- /dev/null +++ b/bin/dev @@ -0,0 +1,2 @@ +#!/usr/bin/env ruby +exec "./bin/rails", "server", *ARGV diff --git a/bin/docker-entrypoint b/bin/docker-entrypoint new file mode 100755 index 0000000..57567d6 --- /dev/null +++ b/bin/docker-entrypoint @@ -0,0 +1,14 @@ +#!/bin/bash -e + +# Enable jemalloc for reduced memory usage and latency. +if [ -z "${LD_PRELOAD+x}" ]; then + LD_PRELOAD=$(find /usr/lib -name libjemalloc.so.2 -print -quit) + export LD_PRELOAD +fi + +# If running the rails server then create or migrate existing database +if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ]; then + ./bin/rails db:prepare +fi + +exec "${@}" diff --git a/bin/importmap b/bin/importmap new file mode 100755 index 0000000..36502ab --- /dev/null +++ b/bin/importmap @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby + +require_relative "../config/application" +require "importmap/commands" diff --git a/bin/rails b/bin/rails new file mode 100755 index 0000000..efc0377 --- /dev/null +++ b/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path("../config/application", __dir__) +require_relative "../config/boot" +require "rails/commands" diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4fbf10b --- /dev/null +++ b/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative "../config/boot" +require "rake" +Rake.application.run diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..40330c0 --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,8 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +# explicit rubocop config increases performance slightly while avoiding config confusion. +ARGV.unshift("--config", File.expand_path("../.rubocop.yml", __dir__)) + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..be3db3c --- /dev/null +++ b/bin/setup @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby +require "fileutils" + +APP_ROOT = File.expand_path("..", __dir__) + +def system!(*args) + system(*args, exception: true) +end + +FileUtils.chdir APP_ROOT do + # This script is a way to set up or update your development environment automatically. + # This script is idempotent, so that you can run it at any time and get an expectable outcome. + # Add necessary setup steps to this file. + + puts "== Installing dependencies ==" + system("bundle check") || system!("bundle install") + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # FileUtils.cp "config/database.yml.sample", "config/database.yml" + # end + + puts "\n== Preparing database ==" + system! "bin/rails db:prepare" + + puts "\n== Removing old logs and tempfiles ==" + system! "bin/rails log:clear tmp:clear" + + unless ARGV.include?("--skip-server") + puts "\n== Starting development server ==" + STDOUT.flush # flush the output before exec(2) so that it displays + exec "bin/dev" + end +end diff --git a/bin/thrust b/bin/thrust new file mode 100755 index 0000000..36bde2d --- /dev/null +++ b/bin/thrust @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("thruster", "thrust") diff --git a/config.ru b/config.ru new file mode 100644 index 0000000..4a3c09a --- /dev/null +++ b/config.ru @@ -0,0 +1,6 @@ +# This file is used by Rack-based servers to start the application. + +require_relative "config/environment" + +run Rails.application +Rails.application.load_server diff --git a/config/application.rb b/config/application.rb new file mode 100644 index 0000000..316a750 --- /dev/null +++ b/config/application.rb @@ -0,0 +1,27 @@ +require_relative "boot" + +require "rails/all" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module Ferti + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 8.0 + + # Please, add to the `ignore` list any other `lib` subdirectories that do + # not contain `.rb` files, or that should not be reloaded or eager loaded. + # Common ones are `templates`, `generators`, or `middleware`, for example. + config.autoload_lib(ignore: %w[assets tasks]) + + # Configuration for the application, engines, and railties goes here. + # + # These settings can be overridden in specific environments using the files + # in config/environments, which are processed later. + # + # config.time_zone = "Central Time (US & Canada)" + # config.eager_load_paths << Rails.root.join("extras") + end +end diff --git a/config/boot.rb b/config/boot.rb new file mode 100644 index 0000000..988a5dd --- /dev/null +++ b/config/boot.rb @@ -0,0 +1,4 @@ +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +require "bundler/setup" # Set up gems listed in the Gemfile. +require "bootsnap/setup" # Speed up boot time by caching expensive operations. diff --git a/config/cable.yml b/config/cable.yml new file mode 100644 index 0000000..bfd4202 --- /dev/null +++ b/config/cable.yml @@ -0,0 +1,10 @@ +development: + adapter: async + +test: + adapter: test + +production: + adapter: redis + url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> + channel_prefix: ferti_production diff --git a/config/credentials.yml.enc b/config/credentials.yml.enc new file mode 100644 index 0000000..9179429 --- /dev/null +++ b/config/credentials.yml.enc @@ -0,0 +1 @@ +7jDV9/PMc5rXUDg80zXpTzhb856WzvtUFwrQT6hX6avsV6gfG2kbQZ6bw9dNhAuJG7biRAcqMMccziRtHW7xteFWXmlEdLEZVxyLJF1j692rThKblbhqwrl8A18Mtfo0urxfhwlvwpPlaML9RapsOtK4R4FrfOpRkxNRuJnvAzB+7ZTmB1fha+BhuDMJr4tz8EPC9F6S/rpR8k+jA4FSZDJnWjW1YzFK8A0YajIeGTWoQ09kTy2LmlZiR/7FpwfKEKaKaX+Mk1SmMRMQZhMpp6OM2CKRzy+dD9Rbv9HKa7LurLIqNOBSoh8CDqeMpquh299VaT6Gq3G4HXuUs6YH1hfWhOOFs0RZ91IJe83g9wYBUNVSjp/tkHo9E5IEorjvMcGRZUHuYqeFBgM1sS1uKXRKoBeI1UA+Nk72H5DRCP1VZuS0SvS4MGKtjzGJQVhyNGVXKAXt9xKQsSdoj0v1eJioHGKw0degKl/s/TbRXjE7QgPScBiBDkLe--ETBoZlP3MDy2hVMJ--xRfKKvHV54MospFJKlydjg== \ No newline at end of file diff --git a/config/database.yml b/config/database.yml new file mode 100644 index 0000000..2640cb5 --- /dev/null +++ b/config/database.yml @@ -0,0 +1,41 @@ +# SQLite. Versions 3.8.0 and up are supported. +# gem install sqlite3 +# +# Ensure the SQLite 3 gem is defined in your Gemfile +# gem "sqlite3" +# +default: &default + adapter: sqlite3 + pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> + timeout: 5000 + +development: + <<: *default + database: storage/development.sqlite3 + +# Warning: The database defined as "test" will be erased and +# re-generated from your development database when you run "rake". +# Do not set this db to the same as development or production. +test: + <<: *default + database: storage/test.sqlite3 + + +# Store production database in the storage/ directory, which by default +# is mounted as a persistent Docker volume in config/deploy.yml. +production: + primary: + <<: *default + database: storage/production.sqlite3 + cache: + <<: *default + database: storage/production_cache.sqlite3 + migrations_paths: db/cache_migrate + queue: + <<: *default + database: storage/production_queue.sqlite3 + migrations_paths: db/queue_migrate + cable: + <<: *default + database: storage/production_cable.sqlite3 + migrations_paths: db/cable_migrate diff --git a/config/deploy.yml b/config/deploy.yml new file mode 100644 index 0000000..600b1ae --- /dev/null +++ b/config/deploy.yml @@ -0,0 +1,116 @@ +# Name of your application. Used to uniquely configure containers. +service: ferti + +# Name of the container image. +image: your-user/ferti + +# Deploy to these servers. +servers: + web: + - 192.168.0.1 + # job: + # hosts: + # - 192.168.0.1 + # cmd: bin/jobs + +# Enable SSL auto certification via Let's Encrypt and allow for multiple apps on a single web server. +# Remove this section when using multiple web servers and ensure you terminate SSL at your load balancer. +# +# Note: If using Cloudflare, set encryption mode in SSL/TLS setting to "Full" to enable CF-to-app encryption. +proxy: + ssl: true + host: app.example.com + +# Credentials for your image host. +registry: + # Specify the registry server, if you're not using Docker Hub + # server: registry.digitalocean.com / ghcr.io / ... + username: your-user + + # Always use an access token rather than real password when possible. + password: + - KAMAL_REGISTRY_PASSWORD + +# Inject ENV variables into containers (secrets come from .kamal/secrets). +env: + secret: + - RAILS_MASTER_KEY + clear: + # Run the Solid Queue Supervisor inside the web server's Puma process to do jobs. + # When you start using multiple servers, you should split out job processing to a dedicated machine. + SOLID_QUEUE_IN_PUMA: true + + # Set number of processes dedicated to Solid Queue (default: 1) + # JOB_CONCURRENCY: 3 + + # Set number of cores available to the application on each server (default: 1). + # WEB_CONCURRENCY: 2 + + # Match this to any external database server to configure Active Record correctly + # Use ferti-db for a db accessory server on same machine via local kamal docker network. + # DB_HOST: 192.168.0.2 + + # Log everything from Rails + # RAILS_LOG_LEVEL: debug + +# Aliases are triggered with "bin/kamal ". You can overwrite arguments on invocation: +# "bin/kamal logs -r job" will tail logs from the first server in the job section. +aliases: + console: app exec --interactive --reuse "bin/rails console" + shell: app exec --interactive --reuse "bash" + logs: app logs -f + dbc: app exec --interactive --reuse "bin/rails dbconsole" + + +# Use a persistent storage volume for sqlite database files and local Active Storage files. +# Recommended to change this to a mounted volume path that is backed up off server. +volumes: + - "ferti_storage:/rails/storage" + + +# Bridge fingerprinted assets, like JS and CSS, between versions to avoid +# hitting 404 on in-flight requests. Combines all files from new and old +# version inside the asset_path. +asset_path: /rails/public/assets + +# Configure the image builder. +builder: + arch: amd64 + + # # Build image via remote server (useful for faster amd64 builds on arm64 computers) + # remote: ssh://docker@docker-builder-server + # + # # Pass arguments and secrets to the Docker build process + # args: + # RUBY_VERSION: ruby-3.2.8 + # secrets: + # - GITHUB_TOKEN + # - RAILS_MASTER_KEY + +# Use a different ssh user than root +# ssh: +# user: app + +# Use accessory services (secrets come from .kamal/secrets). +# accessories: +# db: +# image: mysql:8.0 +# host: 192.168.0.2 +# # Change to 3306 to expose port to the world instead of just local network. +# port: "127.0.0.1:3306:3306" +# env: +# clear: +# MYSQL_ROOT_HOST: '%' +# secret: +# - MYSQL_ROOT_PASSWORD +# files: +# - config/mysql/production.cnf:/etc/mysql/my.cnf +# - db/production.sql:/docker-entrypoint-initdb.d/setup.sql +# directories: +# - data:/var/lib/mysql +# redis: +# image: redis:7.0 +# host: 192.168.0.2 +# port: 6379 +# directories: +# - data:/data diff --git a/config/environment.rb b/config/environment.rb new file mode 100644 index 0000000..cac5315 --- /dev/null +++ b/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative "application" + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 0000000..4cc21c4 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,72 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Make code changes take effect immediately without server restart. + config.enable_reloading = true + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable server timing. + config.server_timing = true + + # Enable/disable Action Controller caching. By default Action Controller caching is disabled. + # Run rails dev:cache to toggle Action Controller caching. + if Rails.root.join("tmp/caching-dev.txt").exist? + config.action_controller.perform_caching = true + config.action_controller.enable_fragment_cache_logging = true + config.public_file_server.headers = { "cache-control" => "public, max-age=#{2.days.to_i}" } + else + config.action_controller.perform_caching = false + end + + # Change to :null_store to avoid any caching. + config.cache_store = :memory_store + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Make template changes take effect immediately. + config.action_mailer.perform_caching = false + + # Set localhost to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "localhost", port: 3000 } + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Append comments with runtime information tags to SQL queries in logs. + config.active_record.query_log_tags_enabled = true + + # Highlight code that enqueued background job in logs. + config.active_job.verbose_enqueue_logs = true + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + config.action_view.annotate_rendered_view_with_filenames = true + + # Uncomment if you wish to allow Action Cable access from any origin. + # config.action_cable.disable_request_forgery_protection = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true + + # Apply autocorrection by RuboCop to files generated by `bin/rails generate`. + # config.generators.apply_rubocop_autocorrect_after_generate! +end diff --git a/config/environments/production.rb b/config/environments/production.rb new file mode 100644 index 0000000..1749607 --- /dev/null +++ b/config/environments/production.rb @@ -0,0 +1,89 @@ +require "active_support/core_ext/integer/time" + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.enable_reloading = false + + # Eager load code on boot for better performance and memory savings (ignored by Rake tasks). + config.eager_load = true + + # Full error reports are disabled. + config.consider_all_requests_local = false + + # Turn on fragment caching in view templates. + config.action_controller.perform_caching = true + + # Cache assets for far-future expiry since they are all digest stamped. + config.public_file_server.headers = { "cache-control" => "public, max-age=#{1.year.to_i}" } + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.asset_host = "http://assets.example.com" + + # Store uploaded files on the local file system (see config/storage.yml for options). + config.active_storage.service = :local + + # Assume all access to the app is happening through a SSL-terminating reverse proxy. + config.assume_ssl = true + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + config.force_ssl = true + + # Skip http-to-https redirect for the default health check endpoint. + # config.ssl_options = { redirect: { exclude: ->(request) { request.path == "/up" } } } + + # Log to STDOUT with the current request id as a default log tag. + config.log_tags = [ :request_id ] + config.logger = ActiveSupport::TaggedLogging.logger(STDOUT) + + # Change to "debug" to log everything (including potentially personally-identifiable information!) + config.log_level = ENV.fetch("RAILS_LOG_LEVEL", "info") + + # Prevent health checks from clogging up the logs. + config.silence_healthcheck_path = "/up" + + # Don't log any deprecations. + config.active_support.report_deprecations = false + + # Replace the default in-process memory cache store with a durable alternative. + # config.cache_store = :mem_cache_store + + # Replace the default in-process and non-durable queuing backend for Active Job. + # config.active_job.queue_adapter = :resque + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "example.com" } + + # Specify outgoing SMTP server. Remember to add smtp/* credentials via rails credentials:edit. + # config.action_mailer.smtp_settings = { + # user_name: Rails.application.credentials.dig(:smtp, :user_name), + # password: Rails.application.credentials.dig(:smtp, :password), + # address: "smtp.example.com", + # port: 587, + # authentication: :plain + # } + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false + + # Only use :id for inspections in production. + config.active_record.attributes_for_inspect = [ :id ] + + # Enable DNS rebinding protection and other `Host` header attacks. + # config.hosts = [ + # "example.com", # Allow requests from example.com + # /.*\.example\.com/ # Allow requests from subdomains like `www.example.com` + # ] + # + # Skip DNS rebinding protection for the default health check endpoint. + # config.host_authorization = { exclude: ->(request) { request.path == "/up" } } +end diff --git a/config/environments/test.rb b/config/environments/test.rb new file mode 100644 index 0000000..c2095b1 --- /dev/null +++ b/config/environments/test.rb @@ -0,0 +1,53 @@ +# The test environment is used exclusively to run your application's +# test suite. You never need to work with it otherwise. Remember that +# your test database is "scratch space" for the test suite and is wiped +# and recreated between test runs. Don't rely on the data there! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # While tests run files are not watched, reloading is not necessary. + config.enable_reloading = false + + # Eager loading loads your entire application. When running a single test locally, + # this is usually not necessary, and can slow down your test suite. However, it's + # recommended that you enable it in continuous integration systems to ensure eager + # loading is working properly before deploying your code. + config.eager_load = ENV["CI"].present? + + # Configure public file server for tests with cache-control for performance. + config.public_file_server.headers = { "cache-control" => "public, max-age=3600" } + + # Show full error reports. + config.consider_all_requests_local = true + config.cache_store = :null_store + + # Render exception templates for rescuable exceptions and raise for other exceptions. + config.action_dispatch.show_exceptions = :rescuable + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Store uploaded files on the local file system in a temporary directory. + config.active_storage.service = :test + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Set host to be used by links generated in mailer templates. + config.action_mailer.default_url_options = { host: "example.com" } + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations. + # config.i18n.raise_on_missing_translations = true + + # Annotate rendered view with file names. + # config.action_view.annotate_rendered_view_with_filenames = true + + # Raise error when a before_action's only/except options reference missing actions. + config.action_controller.raise_on_missing_callback_actions = true +end diff --git a/config/importmap.rb b/config/importmap.rb new file mode 100644 index 0000000..0086a32 --- /dev/null +++ b/config/importmap.rb @@ -0,0 +1,3 @@ +# Pin npm packages by running ./bin/importmap + +pin "application" diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb new file mode 100644 index 0000000..4873244 --- /dev/null +++ b/config/initializers/assets.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +Rails.application.config.assets.version = "1.0" + +# Add additional assets to the asset load path. +# Rails.application.config.assets.paths << Emoji.images_path diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 0000000..b3076b3 --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,25 @@ +# Be sure to restart your server when you modify this file. + +# Define an application-wide content security policy. +# See the Securing Rails Applications Guide for more information: +# https://guides.rubyonrails.org/security.html#content-security-policy-header + +# Rails.application.configure do +# config.content_security_policy do |policy| +# policy.default_src :self, :https +# policy.font_src :self, :https, :data +# policy.img_src :self, :https, :data +# policy.object_src :none +# policy.script_src :self, :https +# policy.style_src :self, :https +# # Specify URI for violation reports +# # policy.report_uri "/csp-violation-report-endpoint" +# end +# +# # Generate session nonces for permitted importmap, inline scripts, and inline styles. +# config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s } +# config.content_security_policy_nonce_directives = %w(script-src style-src) +# +# # Report violations without enforcing the policy. +# # config.content_security_policy_report_only = true +# end diff --git a/config/initializers/filter_parameter_logging.rb b/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..c0b717f --- /dev/null +++ b/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file. +# Use this to limit dissemination of sensitive information. +# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors. +Rails.application.config.filter_parameters += [ + :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn, :cvv, :cvc +] diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb new file mode 100644 index 0000000..3860f65 --- /dev/null +++ b/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, "\\1en" +# inflect.singular /^(ox)en/i, "\\1" +# inflect.irregular "person", "people" +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym "RESTful" +# end diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 0000000..6c349ae --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,31 @@ +# Files in the config/locales directory are used for internationalization and +# are automatically loaded by Rails. If you want to use locales other than +# English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t "hello" +# +# In views, this is aliased to just `t`: +# +# <%= t("hello") %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more about the API, please read the Rails Internationalization guide +# at https://guides.rubyonrails.org/i18n.html. +# +# Be aware that YAML interprets the following case-insensitive strings as +# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings +# must be quoted to be interpreted as strings. For example: +# +# en: +# "yes": yup +# enabled: "ON" + +en: + hello: "Hello world" diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..a248513 --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,41 @@ +# This configuration file will be evaluated by Puma. The top-level methods that +# are invoked here are part of Puma's configuration DSL. For more information +# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html. +# +# Puma starts a configurable number of processes (workers) and each process +# serves each request in a thread from an internal thread pool. +# +# You can control the number of workers using ENV["WEB_CONCURRENCY"]. You +# should only set this value when you want to run 2 or more workers. The +# default is already 1. +# +# The ideal number of threads per worker depends both on how much time the +# application spends waiting for IO operations and on how much you wish to +# prioritize throughput over latency. +# +# As a rule of thumb, increasing the number of threads will increase how much +# traffic a given process can handle (throughput), but due to CRuby's +# Global VM Lock (GVL) it has diminishing returns and will degrade the +# response time (latency) of the application. +# +# The default is set to 3 threads as it's deemed a decent compromise between +# throughput and latency for the average Rails application. +# +# Any libraries that use a connection pool or another resource pool should +# be configured to provide at least as many connections as the number of +# threads. This includes Active Record's `pool` parameter in `database.yml`. +threads_count = ENV.fetch("RAILS_MAX_THREADS", 3) +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +port ENV.fetch("PORT", 3000) + +# Allow puma to be restarted by `bin/rails restart` command. +plugin :tmp_restart + +# Run the Solid Queue supervisor inside of Puma for single-server deployments +plugin :solid_queue if ENV["SOLID_QUEUE_IN_PUMA"] + +# Specify the PID file. Defaults to tmp/pids/server.pid in development. +# In other environments, only set the PID file if requested. +pidfile ENV["PIDFILE"] if ENV["PIDFILE"] diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..1b24155 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,32 @@ +Rails.application.routes.draw do + root "dashboard#index" + + get "ferti_recipe", to: "recipes#show" + resources :fertilizer_products + resources :raft_crops, only: [ :update ] + resources :rafts, only: [ :index ] do + collection do + get :editor # rafts/editor + patch :assign_all # bulk assign all rafts + patch :assign_bed # bulk assign per bed + end + member do + patch :assign_one # per raft + end + end + resources :crops + resources :nutrient_measurements + + # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html + + # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500. + # Can be used by load balancers and uptime monitors to verify that the app is live. + get "up" => "rails/health#show", as: :rails_health_check + + # Render dynamic PWA files from app/views/pwa/* (remember to link manifest in application.html.erb) + # get "manifest" => "rails/pwa#manifest", as: :pwa_manifest + # get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker + + # Defines the root path route ("/") + # root "posts#index" +end diff --git a/config/storage.yml b/config/storage.yml new file mode 100644 index 0000000..4942ab6 --- /dev/null +++ b/config/storage.yml @@ -0,0 +1,34 @@ +test: + service: Disk + root: <%= Rails.root.join("tmp/storage") %> + +local: + service: Disk + root: <%= Rails.root.join("storage") %> + +# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key) +# amazon: +# service: S3 +# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %> +# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %> +# region: us-east-1 +# bucket: your_own_bucket-<%= Rails.env %> + +# Remember not to checkin your GCS keyfile to a repository +# google: +# service: GCS +# project: your_project +# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %> +# bucket: your_own_bucket-<%= Rails.env %> + +# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key) +# microsoft: +# service: AzureStorage +# storage_account_name: your_account_name +# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %> +# container: your_container_name-<%= Rails.env %> + +# mirror: +# service: Mirror +# primary: local +# mirrors: [ amazon, google, microsoft ] diff --git a/db/data/dolibarr_measurements.csv b/db/data/dolibarr_measurements.csv new file mode 100644 index 0000000..38be569 --- /dev/null +++ b/db/data/dolibarr_measurements.csv @@ -0,0 +1,44 @@ +date,nno3,p,k,ca,mg,s,na,cl,si,fe,zn,b,mn,cu,mo,nnh4 +08/05/2021,1.87,0.0031936,0.91,100.79,8.37,1.08666558,6.73,12.28,5.42,0.01,0.01,0.01,0.01,0.01,0.01,0.02 +02/07/2021,66.3,0.0095808,110.91,93.09,17.95,32.84663382,10.27,18.53,5.02,4.37,0.03,0.18,0.15,0,0,0.63 +12/07/2021,61.66,2.011968,122.53,73.5,17.44,47.64328569,0.45,0.82,0.36,1.76,0.05,0.13,0.32,0,0,0 +12/08/2021,67.27,0.351296,94.45,89.48,16.25,9.11665755,10.76,16.51,4.95,3.2,0.03,0.14,0.07,0,0,0.06 +06/09/2021,77.8,7.1153408,96.29,86.31,14.21,23.90664276,9.32,14.92,4.61,2.45,0.08,0.12,0.05,0.03,0,0.02 +21/09/2021,87.88,11.33728,117.24,90.64,17.25,29.90663676,9.92,15.96,4.68,2.4,0.08,0.27,0.12,0.04,0.01,0.02 +19/10/2021,77.84,13.4195072,121.91,94.71,18.3,33.19663347,12.36,15.28,4.47,2.72,0.11,0.74,0.04,0.04,0.02,0.03 +01/12/2021,57.09,6.6842048,81.46,61.45,10.52,17.72331561,17.36,23.05,2.11,1.27,0.17,0.32,0.01,0.03,0.02,0.07 +04/02/2022,43.56,6.5979776,63.1,63.72,9.92,17.3999826,17.08,21.15,1.44,1.6,0.22,0.34,0.01,0.04,0.01,0.03 +12/04/2022,38.36,6.5021696,83.48,49.75,6.42,14.14331919,29.8,38.85,0.23,0.3,0.2,0,0.02,0.01,0.4,0.07 +16/05/2022,24.63,0.542912,30.22,39.79,6.75,0.0666666,25.98,25.89,0.14,1.13,0.3,0.23,0.01,0.02,0.005,0.12 +15/06/2022,2.45,0.0606784,0.69,24.58,4.14,1.24999875,19.59,11.33,0.32,0.79,0.25,0.13,0.01,0.02,0.01,0.1 +04/07/2022,24.3,3.081824,42.34,39.79,8.09,0.41333292,19.79,11.32,1.24,0.7,0.18,0.07,0.02,0.01,0.005,0.68 +01/08/2022,4.88,0.2299392,27.77,22.48,6.71,18.68331465,23,5,0.64,0.97,0.17,0.04,0.005,0.005,0.005,0.07 +07/09/2022,29.28,2.07584,79.65,36.05,13.82,31.17663549,33.41,12.32,0.83,0.84,0.13,0.07,0.01,0.005,0.005,0.8 +24/10/2022,41.61,1.2646656,68.38,47.44,11.54,21.55664511,28.22,18.73,0.81,0.41,0.1,0.05,0.005,0.005,0.005,0.09 +21/11/2022,40.34,3.1105664,53.6,51.09,9.69,17.97331536,25.5,18.85,0.97,0.58,0.11,0.07,0.005,0.005,0.005,0.04 +09/01/2023,48.71,6.6171392,63.08,71.45,11.58,6.55666011,23.81,21.32,1.46,1.04,0.13,0.13,0.01,0.01,0.01,0.03 +21/02/2023,56.03,7.5273152,53.3,81.75,12.11,19.31998068,23.16,27.27,1.86,0.95,0.18,0.19,0.01,0.005,0.02,0.13 +20/04/2023,50.67,7.0546624,76.45,76.63,10.57,15.54331779,22.25,26.97,0.95,0.96,0.19,0.12,0.005,0.005,0.005,0.21 +07/06/2023,48.82,7.3005696,90.04,64.58,9.96,16.92664974,22.39,25.93,0.78,0.42,0.2,0.11,0.005,0.005,0.005,0.16 +13/07/2023,21.79,1.5712512,77.61,40.41,9.74,20.82331251,26.23,22.49,0.6,1.16,0.22,0.31,0,0,0.02,0.14 +17/07/2023,21.79,4.9213376,77.61,40.41,9.74,20.82331251,26.23,22.49,0.6,1.16,0.22,0.31,0.01,0.01,0.02,0.14 +23/08/2023,23.88,2.778432,97.75,49.74,26.25,31.24996875,31.11,16.43,1.33,0.8,0.18,0.14,0,0,0.01,1.01 +02/09/2023,23.88,2.778432,97.75,49.74,16.15,31.24996875,31.11,16.43,1.33,0.8,0.18,0.14,0,0,0.01,1.01 +13/10/2023,71.9,5.0905984,106.35,91.03,18.11,34.90663176,32.36,14.59,1.43,0.97,0.17,0.05,0,0,0,0.24 +28/12/2023,70.58,9.1368896,141.05,68.18,11.96,24.18664248,27.95,21.57,1.31,0.88,0.16,0.15,0,0,0.02,0.06 +16/01/2024,77.26,11.433088,149.17,68.71,12.14,23.24331009,29.88,27.04,1.15,1.14,0.26,0.14,0,0,0,0.09 +04/03/2024,84.65,13.4418624,185.21,66.05,15.61,30.69330264,40.12,36.82,0.66,0.93,0.39,0.35,0,0,0.03,0.16 +23/04/2024,69.17,11.2350848,116.41,52.96,14.07,28.95330438,80.73,37.54,0.57,0.79,0.42,0.38,0.01,0,0.03,0.16 +30/05/2024,46.74,7.520928,81.84,38.61,10.48,26.52997347,79.96,40.47,0.34,0.87,0.45,0.37,0,0.03,0.03,0.12 +05/07/2024,27.51,3.960064,75.58,27.78,8.29,25.99330734,92.2,44.74,0.32,0.59,0.45,0.37,0,0.03,0.03,0.15 +23/07/2024,16.55,2.4143616,83.62,16.52,4.9,20.45997954,79.04,40.51,0.32,0.77,0.43,0.26,0,0.03,0.02,0.43 +06/08/2024,0,0.3001984,74.41,6.82,2.56,17.28664938,78.79,35.04,0.42,0.9,0.37,0.29,0,0.03,0.02,0.13 +09/09/2024,18.3,2.87424,85.3,8.7,1.7,10.5666561,53.7,22.7,2.5,0.7,0.2,0.1,0,0,0,0 +01/10/2024,22.94,4.1740352,112.46,9.44,2,13.51998648,58.57,28.76,0.27,0.6,0.26,0.17,0,0.02,0,0.2 +22/11/2024,66,2.87424,127,33,9,7.333326,63,40,2.8,0.73,0.37,0.16,0.01,0.01,0.01,0 +20/01/2025,94.26,15.664608,146.27,76.06,14.24,32.05663461,64.29,46.99,0.45,0.37,0.48,0.16,0.08,0.03,0.01,0.11 +06/03/2025,95.82,20.007904,171.83,92.24,15.75,35.2332981,82.27,54.5,0.45,0.17,0.49,0.16,0.03,0.02,0,0.06 +04/04/2025,85.49,17.2646016,109.91,88.54,13.47,31.08663558,65.02,53.96,0.28,0.65,0.51,0.13,0.01,0.01,0,0 +22/05/2025,49.8,9.9927744,92.41,61.42,8.47,22.42331091,52.95,38.25,0.32,0.86,0.48,0.23,0.03,0,0.02,0.13 +11/06/2025,30.28,5.700576,50.2,48.96,5.73,22.10664456,51.34,33.41,0,0.96,0.51,0.26,0,0,0,0 +01/08/2025,1.34,0.4854272,77.64,16.45,5.52,22.93997706,58.45,25.83,0.5,0.48,0.44,0.17,0,0,0,0 diff --git a/db/data/nutrient_requirements.csv b/db/data/nutrient_requirements.csv new file mode 100644 index 0000000..61406b8 --- /dev/null +++ b/db/data/nutrient_requirements.csv @@ -0,0 +1,9 @@ +Nom,NNO3,P,K,Ca,Mg,S,Na,Cl,Si,Fe,Zn,B,Mn,Cu,Mo,NNH4 +Générique croissance,160,30,230,100,30,60,0,0,0,5,"0,15","0,3","0,5","0,15","0,05",0 +Générique floraison,130,60,300,100,30,60,0,0,0,2,"0,1","0,5","0,5","0,05","0,05",0 +Laitue,190,50,210,200,50,66,0,0,0,5,"0,15","0,3","0,5","0,15","0,05",0 +Tomate (cycle entier),140,50,352,180,50,168,0,0,0,5,"0,1","0,3","0,8","0,07","0,03",0 +Tomate 10-14 jours,100,40,200,100,20,53,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Tomate 1ere grappe,130,55,300,150,33,109,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Tomate à maturité,180,65,400,400,45,144,0,0,0,3,"0,1","0,3","0,8","0,07","0,03",0 +Framboise - tous stades,70,12,88,90,24,48,0,0,50,0.56,"0,325",11,"0,11","0,032","0,01",0 diff --git a/db/migrate/20250820175727_create_nutrients.rb b/db/migrate/20250820175727_create_nutrients.rb new file mode 100644 index 0000000..d054375 --- /dev/null +++ b/db/migrate/20250820175727_create_nutrients.rb @@ -0,0 +1,10 @@ +class CreateNutrients < ActiveRecord::Migration[8.0] + def change + create_table :nutrients do |t| + t.string :formula + t.string :name + + t.timestamps + end + end +end diff --git a/db/migrate/20250820175742_create_nutrient_measurements.rb b/db/migrate/20250820175742_create_nutrient_measurements.rb new file mode 100644 index 0000000..b4bae51 --- /dev/null +++ b/db/migrate/20250820175742_create_nutrient_measurements.rb @@ -0,0 +1,27 @@ +class CreateNutrientMeasurements < ActiveRecord::Migration[8.0] + def change + create_table :nutrient_measurements do |t| + t.date :measured_on + t.float :nno3 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + t.float :nnh4 + + t.timestamps + end + + add_index :nutrient_measurements, :measured_on, unique: true + end +end diff --git a/db/migrate/20250823140019_create_crops.rb b/db/migrate/20250823140019_create_crops.rb new file mode 100644 index 0000000..e88abd3 --- /dev/null +++ b/db/migrate/20250823140019_create_crops.rb @@ -0,0 +1,26 @@ +class CreateCrops < ActiveRecord::Migration[8.0] + def change + create_table :crops do |t| + t.string :name + t.integer :crop_type, null: false, default: 1 + t.float :nno3 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + t.float :nnh4 + + t.timestamps + end + end +end diff --git a/db/migrate/20250823142743_create_beds.rb b/db/migrate/20250823142743_create_beds.rb new file mode 100644 index 0000000..3c23ad7 --- /dev/null +++ b/db/migrate/20250823142743_create_beds.rb @@ -0,0 +1,11 @@ +class CreateBeds < ActiveRecord::Migration[8.0] + def change + create_table :beds do |t| + t.integer :location, null: false + + t.timestamps + end + + add_index :beds, :location, unique: true + end +end diff --git a/db/migrate/20250823142858_create_rafts.rb b/db/migrate/20250823142858_create_rafts.rb new file mode 100644 index 0000000..6b7f006 --- /dev/null +++ b/db/migrate/20250823142858_create_rafts.rb @@ -0,0 +1,13 @@ +class CreateRafts < ActiveRecord::Migration[8.0] + def change + create_table :rafts do |t| + t.references :bed, null: false, foreign_key: true + t.integer :location, null: false + t.references :crop, null: true, foreign_key: true + + t.timestamps + end + + add_index :rafts, [ :bed_id, :location ], unique: true + end +end diff --git a/db/migrate/20250824121914_create_fertilizer_components.rb b/db/migrate/20250824121914_create_fertilizer_components.rb new file mode 100644 index 0000000..2e08fff --- /dev/null +++ b/db/migrate/20250824121914_create_fertilizer_components.rb @@ -0,0 +1,26 @@ +class CreateFertilizerComponents < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_components do |t| + t.string :name + t.string :formula + t.float :nno3 + t.float :nnh4 + t.float :p + t.float :k + t.float :ca + t.float :mg + t.float :s + t.float :na + t.float :cl + t.float :si + t.float :fe + t.float :zn + t.float :b + t.float :mn + t.float :cu + t.float :mo + + t.timestamps + end + end +end diff --git a/db/migrate/20250824163242_create_fertilizer_products.rb b/db/migrate/20250824163242_create_fertilizer_products.rb new file mode 100644 index 0000000..024f82c --- /dev/null +++ b/db/migrate/20250824163242_create_fertilizer_products.rb @@ -0,0 +1,11 @@ +class CreateFertilizerProducts < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_products do |t| + t.string :name, null: false + t.decimal :purity, precision: 5, scale: 2, null: false, default: 100.00 + + t.timestamps + end + add_index :fertilizer_products, :name, unique: true + end +end diff --git a/db/migrate/20250824163257_create_fertilizer_compositions.rb b/db/migrate/20250824163257_create_fertilizer_compositions.rb new file mode 100644 index 0000000..b48954a --- /dev/null +++ b/db/migrate/20250824163257_create_fertilizer_compositions.rb @@ -0,0 +1,11 @@ +class CreateFertilizerCompositions < ActiveRecord::Migration[8.0] + def change + create_table :fertilizer_compositions do |t| + t.references :fertilizer_product, null: false, foreign_key: true + t.references :fertilizer_component, null: false, foreign_key: true + t.decimal :percent_w, precision: 6, scale: 3, null: false # e.g. 13.500 (% w/w) + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..b5f2e03 --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,130 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# This file is the source Rails uses to define your schema when running `bin/rails +# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to +# be faster and is potentially less error prone than running all of your +# migrations from scratch. Old migrations may fail to apply correctly if those +# migrations use external dependencies or application code. +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema[8.0].define(version: 2025_08_24_163257) do + create_table "beds", force: :cascade do |t| + t.integer "location", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["location"], name: "index_beds_on_location", unique: true + end + + create_table "crops", force: :cascade do |t| + t.string "name" + t.integer "crop_type", default: 1, null: false + t.float "nno3" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.float "nnh4" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "fertilizer_components", force: :cascade do |t| + t.string "name" + t.string "formula" + t.float "nno3" + t.float "nnh4" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "fertilizer_compositions", force: :cascade do |t| + t.integer "fertilizer_product_id", null: false + t.integer "fertilizer_component_id", null: false + t.decimal "percent_w", precision: 6, scale: 3, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["fertilizer_component_id"], name: "index_fertilizer_compositions_on_fertilizer_component_id" + t.index ["fertilizer_product_id"], name: "index_fertilizer_compositions_on_fertilizer_product_id" + end + + create_table "fertilizer_products", force: :cascade do |t| + t.string "name", null: false + t.decimal "purity", precision: 5, scale: 2, default: "100.0", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["name"], name: "index_fertilizer_products_on_name", unique: true + end + + create_table "nutrient_measurements", force: :cascade do |t| + t.date "measured_on" + t.float "nno3" + t.float "p" + t.float "k" + t.float "ca" + t.float "mg" + t.float "s" + t.float "na" + t.float "cl" + t.float "si" + t.float "fe" + t.float "zn" + t.float "b" + t.float "mn" + t.float "cu" + t.float "mo" + t.float "nnh4" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["measured_on"], name: "index_nutrient_measurements_on_measured_on", unique: true + end + + create_table "nutrients", force: :cascade do |t| + t.string "formula" + t.string "name" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + + create_table "rafts", force: :cascade do |t| + t.integer "bed_id", null: false + t.integer "location", null: false + t.integer "crop_id" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["bed_id", "location"], name: "index_rafts_on_bed_id_and_location", unique: true + t.index ["bed_id"], name: "index_rafts_on_bed_id" + t.index ["crop_id"], name: "index_rafts_on_crop_id" + end + + add_foreign_key "fertilizer_compositions", "fertilizer_components" + add_foreign_key "fertilizer_compositions", "fertilizer_products" + add_foreign_key "rafts", "beds" + add_foreign_key "rafts", "crops" +end diff --git a/db/seeds.rb b/db/seeds.rb new file mode 100644 index 0000000..848db0d --- /dev/null +++ b/db/seeds.rb @@ -0,0 +1,13 @@ +# This file should ensure the existence of records required to run the application in every environment (production, +# development, test). The code here should be idempotent so that it can be executed at any point in every environment. +# The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). +# +# Example: +# +# ["Action", "Comedy", "Drama", "Horror"].each do |genre_name| +# MovieGenre.find_or_create_by!(name: genre_name) +# end + +Dir[Rails.root.join("db/seeds/*.rb")].sort.each do |seed| + load seed +end 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}" diff --git a/lib/tasks/.keep b/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/log/.keep b/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/public/400.html b/public/400.html new file mode 100644 index 0000000..282dbc8 --- /dev/null +++ b/public/400.html @@ -0,0 +1,114 @@ + + + + + + + The server cannot process the request due to a client error (400 Bad Request) + + + + + + + + + + + + + +
+
+ +
+
+

The server cannot process the request due to a client error. Please check the request and try again. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/404.html b/public/404.html new file mode 100644 index 0000000..c0670bc --- /dev/null +++ b/public/404.html @@ -0,0 +1,114 @@ + + + + + + + The page you were looking for doesn’t exist (404 Not found) + + + + + + + + + + + + + +
+
+ +
+
+

The page you were looking for doesn’t exist. You may have mistyped the address or the page may have moved. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/406-unsupported-browser.html b/public/406-unsupported-browser.html new file mode 100644 index 0000000..9532a9c --- /dev/null +++ b/public/406-unsupported-browser.html @@ -0,0 +1,114 @@ + + + + + + + Your browser is not supported (406 Not Acceptable) + + + + + + + + + + + + + +
+
+ +
+
+

Your browser is not supported.
Please upgrade your browser to continue.

+
+
+ + + + diff --git a/public/422.html b/public/422.html new file mode 100644 index 0000000..8bcf060 --- /dev/null +++ b/public/422.html @@ -0,0 +1,114 @@ + + + + + + + The change you wanted was rejected (422 Unprocessable Entity) + + + + + + + + + + + + + +
+
+ +
+
+

The change you wanted was rejected. Maybe you tried to change something you didn’t have access to. If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/500.html b/public/500.html new file mode 100644 index 0000000..d77718c --- /dev/null +++ b/public/500.html @@ -0,0 +1,114 @@ + + + + + + + We’re sorry, but something went wrong (500 Internal Server Error) + + + + + + + + + + + + + +
+
+ +
+
+

We’re sorry, but something went wrong.
If you’re the application owner check the logs for more information.

+
+
+ + + + diff --git a/public/icon.png b/public/icon.png new file mode 100644 index 0000000..c4c9dbf Binary files /dev/null and b/public/icon.png differ diff --git a/public/icon.svg b/public/icon.svg new file mode 100644 index 0000000..04b34bf --- /dev/null +++ b/public/icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/public/robots.txt b/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/script/.keep b/script/.keep new file mode 100644 index 0000000..e69de29 diff --git a/storage/.keep b/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 0000000..cee29fd --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :headless_chrome, screen_size: [ 1400, 1400 ] +end diff --git a/test/controllers/crops_controller_test.rb b/test/controllers/crops_controller_test.rb new file mode 100644 index 0000000..71821b1 --- /dev/null +++ b/test/controllers/crops_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class CropsControllerTest < ActionDispatch::IntegrationTest + setup do + @crop = crops(:one) + end + + test "should get index" do + get crops_url + assert_response :success + end + + test "should get new" do + get new_crop_url + assert_response :success + end + + test "should create crop" do + assert_difference("Crop.count") do + post crops_url, params: { crop: { b: @crop.b, ca: @crop.ca, cl: @crop.cl, crop_type: @crop.crop_type, cu: @crop.cu, fe: @crop.fe, k: @crop.k, mg: @crop.mg, mn: @crop.mn, mo: @crop.mo, na: @crop.na, name: @crop.name, nnh4: @crop.nnh4, nno3: @crop.nno3, p: @crop.p, s: @crop.s, si: @crop.si, zn: @crop.zn } } + end + + assert_redirected_to crop_url(Crop.last) + end + + test "should show crop" do + get crop_url(@crop) + assert_response :success + end + + test "should get edit" do + get edit_crop_url(@crop) + assert_response :success + end + + test "should update crop" do + patch crop_url(@crop), params: { crop: { b: @crop.b, ca: @crop.ca, cl: @crop.cl, crop_type: @crop.crop_type, cu: @crop.cu, fe: @crop.fe, k: @crop.k, mg: @crop.mg, mn: @crop.mn, mo: @crop.mo, na: @crop.na, name: @crop.name, nnh4: @crop.nnh4, nno3: @crop.nno3, p: @crop.p, s: @crop.s, si: @crop.si, zn: @crop.zn } } + assert_redirected_to crop_url(@crop) + end + + test "should destroy crop" do + assert_difference("Crop.count", -1) do + delete crop_url(@crop) + end + + assert_redirected_to crops_url + end +end diff --git a/test/controllers/dashboard_controller_test.rb b/test/controllers/dashboard_controller_test.rb new file mode 100644 index 0000000..447c045 --- /dev/null +++ b/test/controllers/dashboard_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class DashboardControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get dashboard_index_url + assert_response :success + end +end diff --git a/test/controllers/fertilizer_products_controller_test.rb b/test/controllers/fertilizer_products_controller_test.rb new file mode 100644 index 0000000..dbdd44f --- /dev/null +++ b/test/controllers/fertilizer_products_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class FertilizerProductsControllerTest < ActionDispatch::IntegrationTest + setup do + @fertilizer_product = fertilizer_products(:one) + end + + test "should get index" do + get fertilizer_products_url + assert_response :success + end + + test "should get new" do + get new_fertilizer_product_url + assert_response :success + end + + test "should create fertilizer_product" do + assert_difference("FertilizerProduct.count") do + post fertilizer_products_url, params: { fertilizer_product: { name: @fertilizer_product.name, purity: @fertilizer_product.purity } } + end + + assert_redirected_to fertilizer_product_url(FertilizerProduct.last) + end + + test "should show fertilizer_product" do + get fertilizer_product_url(@fertilizer_product) + assert_response :success + end + + test "should get edit" do + get edit_fertilizer_product_url(@fertilizer_product) + assert_response :success + end + + test "should update fertilizer_product" do + patch fertilizer_product_url(@fertilizer_product), params: { fertilizer_product: { name: @fertilizer_product.name, purity: @fertilizer_product.purity } } + assert_redirected_to fertilizer_product_url(@fertilizer_product) + end + + test "should destroy fertilizer_product" do + assert_difference("FertilizerProduct.count", -1) do + delete fertilizer_product_url(@fertilizer_product) + end + + assert_redirected_to fertilizer_products_url + end +end diff --git a/test/controllers/nutrient_measurement_controller_test.rb b/test/controllers/nutrient_measurement_controller_test.rb new file mode 100644 index 0000000..02523e0 --- /dev/null +++ b/test/controllers/nutrient_measurement_controller_test.rb @@ -0,0 +1,8 @@ +require "test_helper" + +class NutrientMeasurementControllerTest < ActionDispatch::IntegrationTest + test "should get index" do + get nutrient_measurement_index_url + assert_response :success + end +end diff --git a/test/controllers/rafts_controller_test.rb b/test/controllers/rafts_controller_test.rb new file mode 100644 index 0000000..0d608d3 --- /dev/null +++ b/test/controllers/rafts_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RaftsControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/controllers/recipes_controller_test.rb b/test/controllers/recipes_controller_test.rb new file mode 100644 index 0000000..2280833 --- /dev/null +++ b/test/controllers/recipes_controller_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RecipesControllerTest < ActionDispatch::IntegrationTest + # test "the truth" do + # assert true + # end +end diff --git a/test/fixtures/beds.yml b/test/fixtures/beds.yml new file mode 100644 index 0000000..330db85 --- /dev/null +++ b/test/fixtures/beds.yml @@ -0,0 +1,7 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + number: 1 + +two: + number: 1 diff --git a/test/fixtures/crops.yml b/test/fixtures/crops.yml new file mode 100644 index 0000000..32cd3d5 --- /dev/null +++ b/test/fixtures/crops.yml @@ -0,0 +1,41 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + crop_type: 1 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 + +two: + name: MyString + crop_type: 1 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 diff --git a/test/fixtures/fertilizer_products.yml b/test/fixtures/fertilizer_products.yml new file mode 100644 index 0000000..5784aac --- /dev/null +++ b/test/fixtures/fertilizer_products.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + name: MyString + purity: 9.99 + +two: + name: MyString + purity: 9.99 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/fixtures/nutrient_measurements.yml b/test/fixtures/nutrient_measurements.yml new file mode 100644 index 0000000..8408647 --- /dev/null +++ b/test/fixtures/nutrient_measurements.yml @@ -0,0 +1,39 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + measured_on: 2025-08-20 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 + +two: + measured_on: 2025-08-20 + nno3: 1.5 + p: 1.5 + k: 1.5 + ca: 1.5 + mg: 1.5 + s: 1.5 + na: 1.5 + cl: 1.5 + si: 1.5 + fe: 1.5 + zn: 1.5 + b: 1.5 + mn: 1.5 + cu: 1.5 + mo: 1.5 + nnh4: 1.5 diff --git a/test/fixtures/nutrients.yml b/test/fixtures/nutrients.yml new file mode 100644 index 0000000..f3c6fc9 --- /dev/null +++ b/test/fixtures/nutrients.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + formula: MyString + name: MyString + +two: + formula: MyString + name: MyString diff --git a/test/fixtures/rafts.yml b/test/fixtures/rafts.yml new file mode 100644 index 0000000..1869e29 --- /dev/null +++ b/test/fixtures/rafts.yml @@ -0,0 +1,9 @@ +# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html + +one: + bed: one + location: 1 + +two: + bed: two + location: 1 diff --git a/test/helpers/.keep b/test/helpers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/integration/.keep b/test/integration/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/mailers/.keep b/test/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/.keep b/test/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/models/bed_test.rb b/test/models/bed_test.rb new file mode 100644 index 0000000..67b50da --- /dev/null +++ b/test/models/bed_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class BedTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/crop_test.rb b/test/models/crop_test.rb new file mode 100644 index 0000000..52e4feb --- /dev/null +++ b/test/models/crop_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class CropTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_composition_test.rb b/test/models/fertilizer_composition_test.rb new file mode 100644 index 0000000..5823d3e --- /dev/null +++ b/test/models/fertilizer_composition_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerCompositionTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_product_test.rb b/test/models/fertilizer_product_test.rb new file mode 100644 index 0000000..2da4ee7 --- /dev/null +++ b/test/models/fertilizer_product_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerProductTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/fertilizer_test.rb b/test/models/fertilizer_test.rb new file mode 100644 index 0000000..71c9769 --- /dev/null +++ b/test/models/fertilizer_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class FertilizerTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/nutrient_measurement_test.rb b/test/models/nutrient_measurement_test.rb new file mode 100644 index 0000000..866c8f6 --- /dev/null +++ b/test/models/nutrient_measurement_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class NutrientMeasurementTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/nutrient_test.rb b/test/models/nutrient_test.rb new file mode 100644 index 0000000..61649ad --- /dev/null +++ b/test/models/nutrient_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class NutrientTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/models/raft_test.rb b/test/models/raft_test.rb new file mode 100644 index 0000000..adb1ef0 --- /dev/null +++ b/test/models/raft_test.rb @@ -0,0 +1,7 @@ +require "test_helper" + +class RaftTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/system/.keep b/test/system/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/system/crops_test.rb b/test/system/crops_test.rb new file mode 100644 index 0000000..bbf3e28 --- /dev/null +++ b/test/system/crops_test.rb @@ -0,0 +1,75 @@ +require "application_system_test_case" + +class CropsTest < ApplicationSystemTestCase + setup do + @crop = crops(:one) + end + + test "visiting the index" do + visit crops_url + assert_selector "h1", text: "Crops" + end + + test "should create crop" do + visit crops_url + click_on "New crop" + + fill_in "B", with: @crop.b + fill_in "Ca", with: @crop.ca + fill_in "Cl", with: @crop.cl + fill_in "Crop type", with: @crop.crop_type + fill_in "Cu", with: @crop.cu + fill_in "Fe", with: @crop.fe + fill_in "K", with: @crop.k + fill_in "Mg", with: @crop.mg + fill_in "Mn", with: @crop.mn + fill_in "Mo", with: @crop.mo + fill_in "Na", with: @crop.na + fill_in "Name", with: @crop.name + fill_in "Nnh4", with: @crop.nnh4 + fill_in "Nno3", with: @crop.nno3 + fill_in "P", with: @crop.p + fill_in "S", with: @crop.s + fill_in "Si", with: @crop.si + fill_in "Zn", with: @crop.zn + click_on "Create Crop" + + assert_text "Crop was successfully created" + click_on "Back" + end + + test "should update Crop" do + visit crop_url(@crop) + click_on "Edit this crop", match: :first + + fill_in "B", with: @crop.b + fill_in "Ca", with: @crop.ca + fill_in "Cl", with: @crop.cl + fill_in "Crop type", with: @crop.crop_type + fill_in "Cu", with: @crop.cu + fill_in "Fe", with: @crop.fe + fill_in "K", with: @crop.k + fill_in "Mg", with: @crop.mg + fill_in "Mn", with: @crop.mn + fill_in "Mo", with: @crop.mo + fill_in "Na", with: @crop.na + fill_in "Name", with: @crop.name + fill_in "Nnh4", with: @crop.nnh4 + fill_in "Nno3", with: @crop.nno3 + fill_in "P", with: @crop.p + fill_in "S", with: @crop.s + fill_in "Si", with: @crop.si + fill_in "Zn", with: @crop.zn + click_on "Update Crop" + + assert_text "Crop was successfully updated" + click_on "Back" + end + + test "should destroy Crop" do + visit crop_url(@crop) + click_on "Destroy this crop", match: :first + + assert_text "Crop was successfully destroyed" + end +end diff --git a/test/system/fertilizer_products_test.rb b/test/system/fertilizer_products_test.rb new file mode 100644 index 0000000..be82ed5 --- /dev/null +++ b/test/system/fertilizer_products_test.rb @@ -0,0 +1,43 @@ +require "application_system_test_case" + +class FertilizerProductsTest < ApplicationSystemTestCase + setup do + @fertilizer_product = fertilizer_products(:one) + end + + test "visiting the index" do + visit fertilizer_products_url + assert_selector "h1", text: "Fertilizer products" + end + + test "should create fertilizer product" do + visit fertilizer_products_url + click_on "New fertilizer product" + + fill_in "Name", with: @fertilizer_product.name + fill_in "Purity", with: @fertilizer_product.purity + click_on "Create Fertilizer product" + + assert_text "Fertilizer product was successfully created" + click_on "Back" + end + + test "should update Fertilizer product" do + visit fertilizer_product_url(@fertilizer_product) + click_on "Edit this fertilizer product", match: :first + + fill_in "Name", with: @fertilizer_product.name + fill_in "Purity", with: @fertilizer_product.purity + click_on "Update Fertilizer product" + + assert_text "Fertilizer product was successfully updated" + click_on "Back" + end + + test "should destroy Fertilizer product" do + visit fertilizer_product_url(@fertilizer_product) + click_on "Destroy this fertilizer product", match: :first + + assert_text "Fertilizer product was successfully destroyed" + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..0c22470 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,15 @@ +ENV["RAILS_ENV"] ||= "test" +require_relative "../config/environment" +require "rails/test_help" + +module ActiveSupport + class TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) + + # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order. + fixtures :all + + # Add more helper methods to be used by all tests here... + end +end diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/pids/.keep b/tmp/pids/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tmp/storage/.keep b/tmp/storage/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/.gitignore b/vendor/.gitignore new file mode 100644 index 0000000..1bc4299 --- /dev/null +++ b/vendor/.gitignore @@ -0,0 +1,3 @@ +/bundle/* +!/bundle/ +!/bundle/.keep \ No newline at end of file diff --git a/vendor/bundle/.keep b/vendor/bundle/.keep new file mode 100644 index 0000000..e69de29 diff --git a/vendor/javascript/.keep b/vendor/javascript/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3