weather_judge 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9a7cc48f83c00173d4ac5eb1d72ccb336b8ea206
4
+ data.tar.gz: 25131c80b1435c676367b06be003f62bbb5c950b
5
+ SHA512:
6
+ metadata.gz: 131fdfde7a5ad13aa8478df225e564f1a661147d224d215b6d71010033287d38dac31fc1cc9216405fd9f90d8a2a1c4de8041d01b63a745f37cdba92532a3aca
7
+ data.tar.gz: de6e5d2dd793f317d9b645867c1b669d9051e28ea564d240ed85769818be15663c2d3924ddbaa28f71bb16bb240f50cc663a7819221669028b057fafebda8c89
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /.idea
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.3.1
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in weather_judge.gemspec
4
+ gemspec
5
+
6
+ gem 'forecast_io'
7
+
8
+ ruby '2.3.1'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Makoto Scott-Hinkle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # WeatherJudge
2
+
3
+ This gem retrieves weather forecasting data from Forecast.IO via [forecast-ruby](https://github.com/darkskyapp/forecast-ruby)
4
+ using longitude and latitude and returns an overall score. The following criteria are used to judge
5
+ the quality of weather. The total score is up to 100.
6
+
7
+ - Temperature
8
+ - Sky Cover
9
+ - Wind speed
10
+ - Change of Rain
11
+
12
+ Currently it only evaluates today's data but I plan on adding an ability to take a specified date. This is
13
+ more of a proof of concept at this point. Since there are four criteria at the moment, each of them holds
14
+ up to 25 points. Optimal weather is considered as a day with comfortable temperature, less than 15 mph wind,
15
+ low chance of rain, and low sky cover.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'weather_judge'
23
+ ```
24
+
25
+ And then execute:
26
+
27
+ $ bundle
28
+
29
+ Or install it yourself as:
30
+
31
+ $ gem install weather_judge
32
+
33
+ ## Usage
34
+ `WeatherJudge` returns overall weather score, and scores of weather aspect.
35
+
36
+ Please see [Forecast IO's documentation](https://developer.forecast.io/) for creating an api key.
37
+
38
+ ```ruby
39
+ WeatherJudge.forecast_io_api_key = '(your api key here)'
40
+ data = WeatherJudge.run(44, -122)
41
+ # => Returns `WeatherData` object
42
+
43
+ data.total_location_score
44
+ # => returns a score of 0 - 100
45
+ ```
46
+
47
+ Available methods for `WeatherData`
48
+ - `raw_data`
49
+ - `total_location_score`
50
+ - `cloud_cover_score`
51
+ - `wind_score`
52
+ - `temperature_score`
53
+ - `percent_rain_score`
54
+
55
+
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for
60
+ an interactive prompt that will allow you to experiment.
61
+
62
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version,
63
+ update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a
64
+ git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Future Plans/Disclaimer
67
+ The current state of this gem is more of a proof of concept. This gem was originally developed to be
68
+ used in my personal project for ranking overall weather of different locations, but feel free to use
69
+ it for any purpose. This gem will be evolving in the near future. A couple of obvious future plans are:
70
+ - Add ability to change preferred weather aspects for scoring
71
+ - Add ability to specify a date for retrieving scored data
72
+
73
+ ## Contributing
74
+
75
+ Bugs and pull requests are welcome, but if you want to make significant changes, please fork this project
76
+ and make changes there until you are satisfied, and then create a pull request. Please remember to add
77
+ tests. :)
78
+
79
+ ## License
80
+
81
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
82
+
83
+ ## Copyright
84
+ Copyright (c) 2016 Makoto Scott-Hinkle. Please see LICENSE.txt for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weather_judge"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ module WeatherJudge
2
+ module Configuration
3
+ attr_writer :forecast_io_api_key
4
+
5
+ def forecast_io_api_key
6
+ @forecast_io_api_key
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module WeatherJudge
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,55 @@
1
+ # Calculates score for 4 different weather aspects: sky cover,
2
+ # chance of rain, wind, and temperature
3
+
4
+ module WeatherJudge
5
+ class WeatherData
6
+ SCORE_WEIGHT = 25
7
+
8
+ def initialize(forecast_today)
9
+ @forecast_today = forecast_today
10
+ end
11
+
12
+ # Returns raw forecast data object
13
+ def raw_data
14
+ @forecast_today
15
+ end
16
+
17
+ # Returns total location score based on forecast. It is the sum of
18
+ # cloud cover score, percent rain score, wind score, and temperature score.
19
+ def total_location_score
20
+ cloud_cover_score + percent_rain_score + wind_score + temperature_score
21
+ end
22
+
23
+ def cloud_cover_score
24
+ @forecast_today.cloudCover * SCORE_WEIGHT
25
+ end
26
+
27
+ def percent_rain_score
28
+ @forecast_today.precipProbability * SCORE_WEIGHT
29
+ end
30
+
31
+ def wind_score
32
+ wind_speed = @forecast_today.windSpeed
33
+ max_wind_speed = 15.to_f
34
+ if wind_speed == 0
35
+ SCORE_WEIGHT
36
+ elsif wind_speed < max_wind_speed
37
+ ((max_wind_speed - wind_speed) / max_wind_speed) * SCORE_WEIGHT
38
+ else
39
+ 0
40
+ end
41
+ end
42
+
43
+ def temperature_score
44
+ max_temperature = @forecast_today.temperatureMax
45
+
46
+ if max_temperature > 67 && max_temperature < 77
47
+ SCORE_WEIGHT
48
+ elsif max_temperature > 55 && max_temperature < 67 || max_temperature > 77 && max_temperature < 85
49
+ SCORE_WEIGHT.to_f / 2
50
+ else
51
+ SCORE_WEIGHT.to_f / 4
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ require "weather_judge/version"
2
+ require 'forecast_io'
3
+ require 'weather_judge/weather_data'
4
+ require 'weather_judge/configuration'
5
+
6
+ module WeatherJudge
7
+ extend Configuration
8
+
9
+ class << self
10
+
11
+ # Retrieves WeatherData object for today's forecast given latitude and longitude.
12
+ def run(latitude, longitude)
13
+ ForecastIO.api_key = WeatherJudge.forecast_io_api_key
14
+ forecast = ForecastIO.forecast(latitude, longitude, params: { exclude: 'hourly,minutely,alerts,flags'})
15
+ @forecast_today = forecast.daily.data.first
16
+
17
+ WeatherData.new(@forecast_today)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'weather_judge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "weather_judge"
8
+ spec.version = WeatherJudge::VERSION
9
+ spec.authors = ["Makoto Scott-Hinkle"]
10
+ spec.email = ["makoto.scotthinkle@gmail.com"]
11
+ spec.homepage = "https://github.com/makotogitdev/weather-judge"
12
+
13
+ spec.summary = %q{Scores weather forecast on given coordinates.}
14
+ spec.description = %q{This gem gives a score to given coordinate's weather forecast. It uses Forecast.IO as data source.}
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.4"
25
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_judge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Makoto Scott-Hinkle
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
55
+ description: This gem gives a score to given coordinate's weather forecast. It uses
56
+ Forecast.IO as data source.
57
+ email:
58
+ - makoto.scotthinkle@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".ruby-version"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/weather_judge.rb
72
+ - lib/weather_judge/configuration.rb
73
+ - lib/weather_judge/version.rb
74
+ - lib/weather_judge/weather_data.rb
75
+ - weather_judge.gemspec
76
+ homepage: https://github.com/makotogitdev/weather-judge
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Scores weather forecast on given coordinates.
100
+ test_files: []