Skip to content

Commit

Permalink
CHANGED: orientation to landscape. lickr photos were originally portr…
Browse files Browse the repository at this point in the history
…ait, but the better photos are landscape.
  • Loading branch information
captproton committed Oct 12, 2017
1 parent 8265a61 commit 4d9be4a
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 19 deletions.
7 changes: 7 additions & 0 deletions app/models/cached_flickr_photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ class CachedFlickrPhoto < ActiveRecord::Base
scope :tall_skinny_medium_sizes, -> { includes(:cached_flickr_photo_sizes).
where(cached_flickr_photo_sizes: {height: '640'}).
where(cached_flickr_photo_sizes: {label: "Medium 640"}) }
scope :portrait_medium, -> { includes(:cached_flickr_photo_sizes).portrait.
where(cached_flickr_photo_sizes: {label: "Medium 640"}) }
scope :portrait, -> { includes(:cached_flickr_photo_sizes).where(cached_flickr_photo_sizes: {width_by_height: (0.001..0.99)}) }
scope :landscape, -> { includes(:cached_flickr_photo_sizes).where(cached_flickr_photo_sizes: {width_by_height: (1.01..10.0)}) }
scope :landscape_medium, -> { includes(:cached_flickr_photo_sizes).landscape.
where(cached_flickr_photo_sizes: {width_by_height: (1.3..1.4)}).
where(cached_flickr_photo_sizes: {label: "Medium 640"}) }

def self._collect_tall_medium_for_hotel(hotel_id)
all_tall_photos = self.tall_skinny_medium_sizes
Expand Down
21 changes: 21 additions & 0 deletions app/models/cached_flickr_photo_size.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,25 @@
class CachedFlickrPhotoSize < ActiveRecord::Base
belongs_to :cached_flickr_photo

scope :missing_ratio, -> { where(width_by_height: nil) }
scope :last_week, lambda { where("created_at < ?", Time.zone.now ) }
scope :portrait, lambda { where("width_by_height < ?", 1 ) }
scope :landscape, lambda { where("width_by_height > ?", 1 ) }
scope :medium, lambda { where(width_by_height: (1.3..1.4)) }

def self.add_width_height_ratio_to_sizes_missing_ratio
sizes = self.missing_ratio
sizes.each do |size|
self.add_width_height_ratio(size)
end
end

def self.add_width_height_ratio(size)
ratio = caculate_width_height_ratio(width: size.width, height: size.height)
size.update(width_by_height: ratio)
end

def self.caculate_width_height_ratio(width:,height:)
ratio = width.to_f / height.to_f
end
end
9 changes: 5 additions & 4 deletions app/models/flickr_photo.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
class FlickrPhoto
## formerly used attempted to create FlickrClient and FlickrConnection, but they failed

attr_reader :client, :lat, :lon, :radius
attr_reader :client, :lat, :lon, :radius, :per_page

def initialize(api_key: FLICKR_ID, shared_secret: FLICKR_SECRET, lat:"", lon:"", radius:"")
def initialize(api_key: FLICKR_ID, shared_secret: FLICKR_SECRET, lat:"", lon:"", radius:"", per_page: 500)
@client = FlickrClient.new.client
@lat = lat
@lon = lon
@radius = radius
@per_page = per_page
end

def title
"i am flickr"
end

def search(text: "")
def search(text: "", per_page: 500)
responses = []
search_results = self.client.photos.search(text: text)
search_results = self.client.photos.search(text: text, per_page: per_page)
search_results.each do |photo|
response = OpenStruct.new(photo.to_hash)
responses << response
Expand Down
4 changes: 4 additions & 0 deletions app/models/flickr_photo_collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ def _add_sizes_to_cached_photos
end
end
end

def caculate_width_height_ratio(width:,height:)
ratio = width.to_f / height.to_f
end
end
24 changes: 13 additions & 11 deletions app/views/application/_callout_large_secondary.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<div class="callout large secondary">
<div class="row">
<div class="large-4 columns">
<h5>Waiting Vivamus Hendrerit Arcu Sed Erat Molestie</h5>
<p>Curabitur vulputate, ligula lacinia scelerisque tempor, lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit.</p>
<h5>For Disney Fans by Disney Fans</h5>
<p>WDW Hub provides a feel for what you vacation could be like through the eye of the fans of the total vacation experience.</p>
</div>
<div class="large-3 large-offset-2 columns">
<h6>Official Walt Disney World Info</h6>
<ul class="menu vertical">
<li><a href="#">Uno</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
<li><a href="#">Four</a></li>
</ul>

<li class="linksGroupItem"><h6 class="linksGroupTitle" role="heading" aria-level="3">Help</h6></li>
<li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_ContactUs" href="https://disneyworld.disney.go.com/help/phone/">Contact Us</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_HelpCenter" href="https://disneyworld.disney.go.com/help/">Help Center</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_FAQs" href="https://disneyworld.disney.go.com/faq/">Frequently Asked Questions</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_GuestsWithDisabilities" href="https://disneyworld.disney.go.com/guest-services/guests-with-disabilities/">Guests with Disabilities</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_GuestServices" href="https://disneyworld.disney.go.com/guest-services/">Guest Services</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_MomsPanel" href="https://disneyparksmomspanel.disney.go.com/destinations/walt-disney-world/">Disney Parks Mom's Panel</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_GuestSafety" href="https://disneywildaboutsafety.com/">Guest Safety</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_ParkSecurity" href="https://disneyworld.disney.go.com/guest-services/park-security/">Park Security</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_PrivacyLegal" href="https://disneyworld.disney.go.com/help/privacy-legal/">Privacy &amp; Legal</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_TravelPartners" href="https://disneytravelagents.com/">Travel Partners</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_HelpSupport_WebsiteHelp" href="https://disneyworld.disney.go.com/faq/technical-help/">Website Help</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_ParkRules" href="https://disneyworld.disney.go.com/park-rules/">Park Rules</a></li></ul>

</li> </ul>
</div>
<div class="large-3 columns">
<h6>&nbsp;</h6>
<ul class="menu vertical">
<li><a href="#">One</a></li>
<li><a href="#">Two</a></li>
<li><a href="#">Three</a></li>
<li><a href="#">Four</a></li>
<li class="linksGroupItem"><h6 class="linksGroupTitle" role="heading" aria-level="3">Learn About</h6></li>
<li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_MyMagicPlus" href="https://disneyworld.disney.go.com/plan/my-disney-experience/my-magic-plus/">MyMagic+</a></li>
<li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_MyDisneyExperience" href="https://disneyworld.disney.go.com/plan/my-disney-experience/">My Disney Experience</a></li>
<li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_FamilyFriends" href="https://disneyworld.disney.go.com/plan/my-disney-experience/family-friends/">My Family &amp; Friends</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_FastPassPlus" href="https://disneyworld.disney.go.com/plan/my-disney-experience/fastpass-plus">FastPass+</a></li><li class="linksGroupItem link"><a href="https://disneyworld.disney.go.com/plan/my-disney-experience/memory-maker/">Memory Maker</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_MagicBandsCards" href="https://disneyworld.disney.go.com/plan/my-disney-experience/bands-cards/">MagicBands and Cards</a></li><li class="linksGroupItem link"><a name="&amp;lid=WDW_Footer_Learn_MobileApp" href="https://disneyworld.disney.go.com/plan/my-disney-experience/mobile-apps/">Mobile App</a></li><li class="linksGroupItem link"><a name="&amp;lid=Footer_Learn_ShopDisneyParksApp" href="https://disneyworld.disney.go.com/guest-services/shop-disney-parks-mobile-app/?CMP=ILC-WDW_SDPFooter0001">Shop Disney Parks App</a></li></ul>
</ul>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/application/_featured_photo_gallery.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="row small-up-2 large-up-4">
<% featured_collection = CachedFlickrPhoto._collect_tall_medium_for_hotel(@hotel.id).shuffle.first(4) %>
<div class="row small-up-1 large-up-2">
<% featured_collection = @hotel.cached_flickr_photos.landscape_medium.shuffle.first(4) %>
<%= render :partial => "/hotels/2017/featured_photo",
:collection => featured_collection if featured_collection.length == 4 %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/hotels/2017/_featured_photo.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="column">
<%= image_tag("#{featured_photo.cached_flickr_photo_sizes.first.source}",
class: "thumbnail",
size: "300x400") %>
size: "640x480") %>
<!-- <img src="https://farm3.staticflickr.com/2847/13590772955_d97853612b_s.jpg" alt="myphoto"> -->
<%#= image_tag("https://www.flickr.com/photos/94674772@N03/17899628468/sizes/m/") %>
<!-- https://www.flickr.com/photos/stewart/567229075/sizes/m/ -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRaitioToCachedFlickrPhotoSize < ActiveRecord::Migration
def change
add_column :cached_flickr_photo_sizes, :width_by_height, :float
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171009223716) do
ActiveRecord::Schema.define(version: 20171011011341) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -26,6 +26,7 @@
t.integer "cached_flickr_photo_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "width_by_height"
end

add_index "cached_flickr_photo_sizes", ["cached_flickr_photo_id"], name: "index_cached_flickr_photo_sizes_on_cached_flickr_photo_id", using: :btree
Expand Down

0 comments on commit 4d9be4a

Please sign in to comment.