Created
May 28, 2021 16:23
-
-
Save caioertai/df203866d81ce7486bc20c679c5e34ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Result | |
class Day | |
def initialize(params) | |
@date = params[:date] || Date.today | |
@preference = params[:preference] | |
@spot = params[:spot] | |
end | |
def time_periods | |
conditions.map do |condition| | |
Result::TimePeriod.new(condition: condition, preference: @preference) | |
end | |
end | |
def any_go? | |
time_periods.any?(&:go?) | |
end | |
private | |
def conditions | |
# Use spot to query with AR for the conditions | |
# Condition.where(spot: @spot).where("BETWEEN STUFF") | |
condition_1 = OpenStruct.new( | |
id: 1294, | |
spot_id: 27, | |
created_at: "2021-05-27 20:24:33", | |
updated_at: "2021-05-27 21:24:35", | |
timestamp: 1622606400, | |
wind_strength: 7.56601, | |
wind_direction: 216.84284, | |
wind_gust: 7.2085, | |
wind_optimal_score: 2.0, | |
waves_surf_min: 1.54268, | |
waves_surf_max: 1.75844, | |
waves_optimal_score: 2.0, | |
waves_swell_height: 0.82772, | |
waves_swell_period: 18.0, | |
waves_swell_direction: 193.67999, | |
waves_swell_direction_min: 190.164325, | |
waves_swell_optimal_score: 1.0, | |
tide_type: "HIGH", | |
tide_height: 0.29, | |
time_at: "2021-06-02 04:00:00" | |
) | |
condition_2 = OpenStruct.new( | |
id: 1294, | |
spot_id: 27, | |
created_at: "2021-05-27 20:24:33", | |
updated_at: "2021-05-27 21:24:35", | |
timestamp: 1622606400 + (3600 * 3), | |
wind_strength: 7.56601, | |
wind_direction: 216.84284, | |
wind_gust: 7.2085, | |
wind_optimal_score: 2.0, | |
waves_surf_min: 1.54268, | |
waves_surf_max: 1.75844, | |
waves_optimal_score: 2.0, | |
waves_swell_height: 0.82772, | |
waves_swell_period: 18.0, | |
waves_swell_direction: 193.67999, | |
waves_swell_direction_min: 190.164325, | |
waves_swell_optimal_score: 1.0, | |
tide_type: "mid", | |
tide_height: 0.29, | |
time_at: "2021-06-02 04:00:00" | |
) | |
[condition_1, condition_2] | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Result | |
def initialize(params) | |
@preference = params[:preference] | |
@spot = params[:spot] | |
@start_date = params[:start_date] || Date.today | |
@days_count = params[:days_count] || 5 | |
@end_date = @start_date + @days_count | |
end | |
def days | |
(@start_date..@end_date).map do |date| | |
Day.new(preference: @preference, spot: @spot, date: date) | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Result | |
class TimePeriod | |
def initialize(params = {}) | |
@condition = params[:condition] | |
@preference = params[:preference] | |
end | |
def go? | |
tides_good? && winds_good? && waves_good? | |
end | |
private | |
def tides_good? | |
@condition.tide_type.downcase == @preference.pref_tide_position.downcase | |
end | |
def winds_good? | |
preference_winds_range.include?(@condition.wind_direction) | |
end | |
def waves_good? | |
preference_waves_range.include?(@condition.waves_swell_height) | |
end | |
# Abstract this later to preference | |
def preference_winds_range | |
@[email protected]_dir_max | |
end | |
def preference_waves_range | |
@[email protected]_hgt_max | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment