Skip to content
Draft
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/garden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Garden < ApplicationRecord

has_many :plantings, dependent: :destroy
has_many :crops, through: :plantings
has_many :weather_observations

belongs_to :garden_type, optional: true

Expand Down
16 changes: 16 additions & 0 deletions app/models/weather_observation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A weather observation is intended to be a snapshot aligned to
# https://github.com/schemaorg/schemaorg/issues/362
class WeatherObservation < ApplicationRecord
belongs_to :garden

validates :source, presence: true
validates :observed_at, presence: true

# Lowest temp on earth: -89.2°C (-128.6°F)
# Highest: 56.7°C
validates :dew_point_temperature_centigrade, min: -90, max: 60
validates :air_temperature_centigrade, min: -90, max: 60
validates :relative_humidity, min: 0, max: 100
validates :wind_speed_kmh, min: 0, max: 450 # Highest 408 km/h
validates :wind_gust_speed_kmh, min: 0, max: 450 # Highest 408 km/h
end
24 changes: 24 additions & 0 deletions db/migrate/20230916061712_add_weather_observations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

class AddWeatherObservations < ActiveRecord::Migration[7.0]
def change
# See https://github.com/schemaorg/schemaorg/issues/362
create_table :weather_observations do |t|
t.string :source
t.datetime :observation_at
t.integer :solar_uv_index
t.decimal :wind_speed_kmh
t.decimal :wind_gust_speed_kmh
t.string :wind_direction
t.decimal :air_temperature_centigrade
t.decimal :relative_humidity
t.decimal :precipitation_probability
t.decimal :dew_point_temperature_centigrade
t.decimal :pressure
t.integer :visibility_distance_metres
t.string :weather_type
t.references :garden_id
t.timestamps
end
end
end