Class: WeatherJudge::WeatherData

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_judge/weather_data.rb

Constant Summary collapse

SCORE_WEIGHT =
25

Instance Method Summary collapse

Constructor Details

#initialize(forecast_today) ⇒ WeatherData

Returns a new instance of WeatherData.



11
12
13
# File 'lib/weather_judge/weather_data.rb', line 11

def initialize(forecast_today)
  @forecast_today = forecast_today
end

Instance Method Details

#cloud_cover_scoreObject



26
27
28
# File 'lib/weather_judge/weather_data.rb', line 26

def cloud_cover_score
  score_from_decimal_data(WeatherJudge.max_cloud_cover, @forecast_today.cloudCover)
end

#percent_rain_scoreObject



30
31
32
# File 'lib/weather_judge/weather_data.rb', line 30

def percent_rain_score
  score_from_decimal_data(WeatherJudge.max_percent_rain, @forecast_today.precipProbability)
end

#raw_dataObject

Returns raw forecast data object



16
17
18
# File 'lib/weather_judge/weather_data.rb', line 16

def raw_data
  @forecast_today
end

#temperature_scoreObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/weather_judge/weather_data.rb', line 44

def temperature_score
  high_today = @forecast_today.temperatureMax
  min_ideal_temp = WeatherJudge.ideal_temp_range[:min]
  max_ideal_temp = WeatherJudge.ideal_temp_range[:max]
  delta = WeatherJudge.temp_range_delta

  if high_today > min_ideal_temp && high_today < max_ideal_temp
    SCORE_WEIGHT
  elsif high_today > min_ideal_temp - delta && high_today < min_ideal_temp ||
      high_today > max_ideal_temp && high_today < max_ideal_temp + delta
    SCORE_WEIGHT.to_f / 2
  else
    SCORE_WEIGHT.to_f / 4
  end
end

#total_location_scoreObject

Returns total location score based on forecast. It is the sum of cloud cover score, percent rain score, wind score, and temperature score.



22
23
24
# File 'lib/weather_judge/weather_data.rb', line 22

def total_location_score
  cloud_cover_score + percent_rain_score + wind_score + temperature_score
end

#wind_scoreObject



34
35
36
37
38
39
40
41
42
# File 'lib/weather_judge/weather_data.rb', line 34

def wind_score
  wind_speed = @forecast_today.windSpeed
  max_wind_speed = WeatherJudge.max_wind_speed.to_f
  if wind_speed < max_wind_speed
    ((max_wind_speed - wind_speed) / max_wind_speed) * SCORE_WEIGHT
  else
    0
  end
end