Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add table for weather observation (Stacked PR) #3452

Draft
wants to merge 19 commits into
base: dev
Choose a base branch
from
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 @@

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

Check notice on line 12 in app/models/garden.rb

View check run for this annotation

codefactor.io / CodeFactor

app/models/garden.rb#L12

Specify a `:dependent` option. (Rails/HasManyOrHasOneDependent)

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

Check notice on line 1 in app/models/weather_observation.rb

View check run for this annotation

codefactor.io / CodeFactor

app/models/weather_observation.rb#L1

Missing frozen string literal comment. (Style/FrozenStringLiteralComment)
# https://github.com/schemaorg/schemaorg/issues/362
class WeatherObservation < ApplicationRecord
Fixed Show fixed Hide fixed
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

Check notice on line 16 in app/models/weather_observation.rb

View check run for this annotation

codefactor.io / CodeFactor

app/models/weather_observation.rb#L16

Final newline missing. (Layout/TrailingEmptyLines)
CloCkWeRX marked this conversation as resolved.
Show resolved Hide resolved
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
Loading