Skip to content

Commit

Permalink
Rename Region to Subregion
Browse files Browse the repository at this point in the history
  • Loading branch information
swrobel committed Sep 7, 2017
1 parent 8c172a7 commit ff1405a
Show file tree
Hide file tree
Showing 27 changed files with 56 additions and 276 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Note: If you get a security warning in Chrome, Click "Advanced" and then "Procee

Contributing new spots is easy! Make sure you're signed into your [Github account](https://github.com/join) and edit the [seeds file](https://github.com/swrobel/meta-surf-forecast/edit/master/db/seeds.rb):

1. Create a new region if necessary. For example, the LA region is created like so:
1. Create a new Region if necessary. For example, Los Angeles is created like so:
```ruby
LA = Region.find_or_create_by(name: 'Los Angeles')
LA = Subregion.find_or_create_by(name: 'Los Angeles')
```
1. Get the Spitcast spot id, slug (unique text id) & lat/lon data using [their spot list API](http://api.spitcast.com/api/spot/nearby?longitude=-122.005261&latitude=37.02188) (you'll need to replace the lat/lon in the URL with yours, which you can get from the [Google Geocoder](https://google-developers.appspot.com/maps/documentation/utils/geocoder/)). The slug is `spot_id_char` in their API.
1. Go to the MagicSeaweed page for the spot you want to add. Their spot id is the number at the end of the url, and the slug is the text after the slash and before `-Surf-Report`, ex: for `http://magicseaweed.com/Pipeline-Backdoor-Surf-Report/616/` the slug is `Pipeline-Backdoor` and the id is `616`.
Expand All @@ -49,7 +49,7 @@ Use the following as a template. Delete the lines for `surfline_id`, `msw_id`, e
msw_slug: 'County-Line-Yerba-Buena-Beach',
spitcast_id: 207,
spitcast_slug: 'county-line-malibu-ca',
region: LA,
subregion: LA,
},
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class RegionsController < ApplicationController
before_action :set_region
class SubregionsController < ApplicationController
before_action :set_subregion

def show
@forecasts = Spot.connection.select_all <<-SQL
Expand Down Expand Up @@ -57,7 +57,7 @@ def show
JOIN spots s ON sub.spot_id = s.id
WHERE sub.timestamp > now() at time zone 'utc'
AND sub.timestamp <= (SELECT max(timestamp) FROM spitcasts)
AND s.region_id = #{@region.id}
AND s.subregion_id = #{@subregion.id}
GROUP BY id
,name
,lat
Expand Down Expand Up @@ -98,7 +98,7 @@ def show

private

def set_region
@region = Region.find(params[:id])
def set_subregion
@subregion = Subregion.find(params[:id])
end
end
2 changes: 1 addition & 1 deletion app/models/spot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Spot < ApplicationRecord
has_many :surfline_lolas
has_many :msws
has_many :spitcasts
belongs_to :region
belongs_to :subregion

default_scope -> { order(:name) }
scope :optimized, -> { includes(:msws, :surfline_nearshores, :surfline_lolas, :spitcasts) }
Expand Down
2 changes: 1 addition & 1 deletion app/models/region.rb → app/models/subregion.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class Region < ApplicationRecord
class Subregion < ApplicationRecord
extend FriendlyId
friendly_id :name, use: %i[slugged finders]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ nav.navbar.navbar-light.sticky-top
.row.font-weight-light
span.margin-left Region:
select.margin-left onchange='window.location = this.value'
- Region.all.each do |region|
option value=region_path(region) selected=('selected' if region == @region) =region.name
- Subregion.all.each do |subregion|
option value=subregion_path(subregion) selected=('selected' if subregion == @subregion) =subregion.name
div
- @forecasts.each do |data, forecast|
h2.font-weight-light.margin-left.spot-header
Expand Down
3 changes: 1 addition & 2 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = ENV['RAILS_SERVE_STATIC_FILES'].blank?
config.assets.debug = true

# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
Expand All @@ -61,7 +61,6 @@

# Suppress static asset requests from server logs
config.assets.quiet = true
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

config.middleware.insert_before ActionDispatch::ShowExceptions, Rack::Toolbar,
snippet: '<script id="__bs_script__">
Expand Down
4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
end

resources :spots, only: :show
resources :regions, only: :show
resources :subregions, only: :show

root to: redirect('/regions/los-angeles')
root to: redirect('/subregions/los-angeles')
end
7 changes: 7 additions & 0 deletions db/migrate/20170906230307_rename_regions_to_subregions.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class RenameRegionsToSubregions < ActiveRecord::Migration[5.1]
def change
rename_table :regions, :subregions

rename_column :spots, :region_id, :subregion_id
end
end
24 changes: 12 additions & 12 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170618230016) do
ActiveRecord::Schema.define(version: 20170906230307) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -49,14 +49,6 @@
t.index ["spot_id", "timestamp"], name: "index_msws_on_spot_id_and_timestamp"
end

create_table "regions", force: :cascade do |t|
t.string "name"
t.string "slug"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["slug"], name: "index_regions_on_slug", unique: true
end

create_table "spitcasts", id: :serial, force: :cascade do |t|
t.integer "spot_id"
t.datetime "timestamp"
Expand All @@ -79,13 +71,21 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "slug"
t.bigint "region_id"
t.bigint "subregion_id"
t.string "msw_slug"
t.string "spitcast_slug"
t.string "surfline_slug"
t.index ["msw_id", "surfline_id", "spitcast_id"], name: "index_spots_on_msw_id_and_surfline_id_and_spitcast_id", unique: true
t.index ["region_id"], name: "index_spots_on_region_id"
t.index ["slug"], name: "index_spots_on_slug", unique: true
t.index ["subregion_id"], name: "index_spots_on_subregion_id"
end

create_table "subregions", force: :cascade do |t|
t.string "name"
t.string "slug"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["slug"], name: "index_subregions_on_slug", unique: true
end

create_table "surfline_lolas", id: :serial, force: :cascade do |t|
Expand Down Expand Up @@ -142,7 +142,7 @@
add_foreign_key "msws", "spots"
add_foreign_key "spitcasts", "api_requests"
add_foreign_key "spitcasts", "spots"
add_foreign_key "spots", "regions"
add_foreign_key "spots", "subregions"
add_foreign_key "surfline_lolas", "api_requests"
add_foreign_key "surfline_lolas", "spots"
add_foreign_key "surfline_nearshores", "api_requests"
Expand Down
44 changes: 22 additions & 22 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
dept.url = 'http://www.publichealth.lacounty.gov/phcommon/public/eh/water_quality/beach_grades.cfm'
end

LA = Region.find_or_create_by(name: 'Los Angeles')
SC = Region.find_or_create_by(name: 'Santa Cruz')
SF = Region.find_or_create_by(name: 'San Francisco')
LA = Subregion.find_or_create_by(name: 'Los Angeles')
SC = Subregion.find_or_create_by(name: 'Santa Cruz')
SF = Subregion.find_or_create_by(name: 'San Francisco')

spots = [
{
Expand All @@ -19,7 +19,7 @@
msw_slug: 'County-Line-Yerba-Buena-Beach',
spitcast_id: 207,
spitcast_slug: 'county-line-malibu-ca',
region: LA,
subregion: LA,
},
{
name: 'Leo Carillo',
Expand All @@ -28,15 +28,15 @@
surfline_id: 4953,
msw_id: 2642,
msw_slug: 'Leo-Carrillo',
region: LA,
subregion: LA,
},
{
name: 'Zeros',
lat: 34.041956,
lon: -118.91593,
msw_id: 2643,
msw_slug: 'Zero-Nicholas-Canyon-County-Beach',
region: LA,
subregion: LA,
},
{
name: 'Zuma Beach',
Expand All @@ -47,7 +47,7 @@
msw_slug: 'Zuma-Beach-County-Park',
spitcast_id: 206,
spitcast_slug: 'zuma-beach-malibu-ca',
region: LA,
subregion: LA,
},
{
name: 'Point Dume',
Expand All @@ -56,7 +56,7 @@
surfline_id: 4947,
msw_id: 2610,
msw_slug: 'Point-Dume',
region: LA,
subregion: LA,
},
{
name: 'Malibu',
Expand All @@ -67,7 +67,7 @@
msw_slug: 'Malibu-First-Point',
spitcast_id: 205,
spitcast_slug: 'malibu-malibu-ca',
region: LA,
subregion: LA,
},
{
name: 'Topanga',
Expand All @@ -78,7 +78,7 @@
msw_slug: 'Topanga-State-Beach',
spitcast_id: 388,
spitcast_slug: 'topanga-malibu-ca',
region: LA,
subregion: LA,
},
{
name: 'Sunset Blvd',
Expand All @@ -89,7 +89,7 @@
msw_slug: 'Sunset-Blvd',
spitcast_id: 387,
spitcast_slug: 'sunset-pacific-palisades-ca',
region: LA,
subregion: LA,
},
{
name: 'Venice Breakwater',
Expand All @@ -100,7 +100,7 @@
msw_slug: 'Venice-Beach',
spitcast_id: 204,
spitcast_slug: 'venice-venice-ca',
region: LA,
subregion: LA,
},
{
name: 'El Porto',
Expand All @@ -111,7 +111,7 @@
msw_slug: 'El-Porto-Beach',
spitcast_id: 402,
spitcast_slug: 'el-porto-manhattan-beach-ca',
region: LA,
subregion: LA,
},
{
name: 'Manhattan Beach',
Expand All @@ -122,7 +122,7 @@
msw_slug: 'Manhattan-Beach',
spitcast_id: 203,
spitcast_slug: 'manhattan-beach-manhattan-beach-ca',
region: LA,
subregion: LA,
},
{
name: 'Hermosa Beach',
Expand All @@ -133,7 +133,7 @@
msw_slug: 'Hermosa-Beach',
spitcast_id: 202,
spitcast_slug: 'hermosa-hermosa-beach-ca',
region: LA,
subregion: LA,
},
{
name: 'Redondo Breakwall',
Expand All @@ -142,7 +142,7 @@
surfline_id: 4912,
msw_id: 4208,
msw_slug: 'Redondo-Beach-Breakwater',
region: LA,
subregion: LA,
},
{
name: 'Torrance Beach/Haggertys',
Expand All @@ -153,7 +153,7 @@
msw_slug: 'Torrance-Beach-Haggertys',
spitcast_id: 200,
spitcast_slug: 'torrance-beach-redondo-beach-ca',
region: LA,
subregion: LA,
},
{
name: 'Palos Verdes Cove',
Expand All @@ -162,7 +162,7 @@
surfline_id: 4936,
msw_id: 4207,
msw_slug: 'Palos-Verdes-Cove',
region: LA,
subregion: LA,
},
{
name: 'Lunada Bay',
Expand All @@ -171,7 +171,7 @@
surfline_id: 4935,
msw_id: 283,
msw_slug: 'Lunada-Bay',
region: LA,
subregion: LA,
},
{
name: 'Ocean Beach',
Expand All @@ -182,7 +182,7 @@
msw_slug: 'Ocean-Beach',
spitcast_id: 117,
spitcast_slug: 'south-ocean-beach-san-francisco-ca',
region: SF,
subregion: SF,
},
{
name: 'Pleasure Point',
Expand All @@ -193,7 +193,7 @@
msw_slug: 'Pleasure-Point',
spitcast_id: 1,
spitcast_slug: 'pleasure-point-santa-cruz-ca',
region: SC,
subregion: SC,
},
]

Expand All @@ -202,7 +202,7 @@
spot.name = spot_data[:name]
spot.lat = spot_data[:lat]
spot.lon = spot_data[:lon]
spot.region = spot_data[:region]
spot.subregion = spot_data[:subregion]
spot.msw_slug = spot_data[:msw_slug]
spot.spitcast_slug = spot_data[:spitcast_slug]
spot.save!
Expand Down
Loading

0 comments on commit ff1405a

Please sign in to comment.