air_monitor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/air_monitor.gemspec +27 -0
- data/lib/air_monitor.rb +137 -0
- data/lib/air_monitor/version.rb +3 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 893c457b68288d79fa2fc916ad8bdfc1f8ad9933
|
4
|
+
data.tar.gz: 41dc9c1758c4c0b61f53af11033b33cfd3064312
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 498dcdabb0a43706398ce120cf8854edd25b1a0cc54cb04d9e04a3f39cc89acb535d1f924a52c69357fe55e40ef193614de3947b1f61a9b2941acfed8f188d69
|
7
|
+
data.tar.gz: 5072b3e09ed3859f51e80a81b97a6040084079e62333b951da5e7cff7fa137036c3ad2f52ef06d8d1da7991ddf5eee9c821925b42c0c91ff4487e2de3d542105
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Glen Egbert
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# AirMonitor
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'air_monitor'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install air_monitor
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/air_monitor/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/air_monitor.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'air_monitor/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "air_monitor"
|
8
|
+
spec.version = AirMonitor::VERSION
|
9
|
+
spec.authors = ["Glen Egbert"]
|
10
|
+
spec.email = ["glenegbert1@gmail.com"]
|
11
|
+
spec.summary = %q{Gem for use with Monitor My Air App}
|
12
|
+
spec.description = %q{This gem is for use with teh Monitor My Air app.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec-rails"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "launchy"
|
26
|
+
spec.add_runtime_dependency 'faraday', '>= 0', '~> 0.9.0'
|
27
|
+
end
|
data/lib/air_monitor.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require "air_monitor/version"
|
2
|
+
|
3
|
+
module AirMonitor
|
4
|
+
def initialize(zip_code=nil, params={})
|
5
|
+
@zip_code = zip_code
|
6
|
+
@checked_concerns = params.map {|concern, value| concern if value == "1"}.compact
|
7
|
+
end
|
8
|
+
|
9
|
+
def forecast
|
10
|
+
tomorrow = Date.today + 1
|
11
|
+
Faraday.get("http://www.airnowapi.org/aq/forecast/zipCode/?format=application/json&zipCode=#{@zip_code}&date=#{tomorrow.strftime('%Y-%m-%d')}&distance=100&API_KEY=6262A4E6-45AF-4316-8485-CB1A259D7231")
|
12
|
+
end
|
13
|
+
|
14
|
+
def observed
|
15
|
+
Faraday.get("http://www.airnowapi.org/aq/observation/zipCode/current/?format=application/json&zipCode=#{@zip_code}&distance=25&API_KEY=6262A4E6-45AF-4316-8485-CB1A259D7231")
|
16
|
+
end
|
17
|
+
|
18
|
+
def parsed_forecast
|
19
|
+
JSON.parse(forecast.body)
|
20
|
+
end
|
21
|
+
|
22
|
+
def parsed_observed
|
23
|
+
JSON.parse(observed.body)
|
24
|
+
end
|
25
|
+
|
26
|
+
def forecasted_levels
|
27
|
+
parsed_forecast.map {|data| data["Category"]["Name"]}
|
28
|
+
end
|
29
|
+
|
30
|
+
def forecasted_contaminates
|
31
|
+
parsed_forecast.map {|data| data["ParameterName"]}
|
32
|
+
end
|
33
|
+
|
34
|
+
def forecasted_contaminates_and_levels
|
35
|
+
Hash[forecasted_contaminates.zip forecasted_levels]
|
36
|
+
end
|
37
|
+
|
38
|
+
def observed_levels
|
39
|
+
parsed_observed.map {|data| data["Category"]["Name"]}
|
40
|
+
end
|
41
|
+
|
42
|
+
def observed_contaminates
|
43
|
+
parsed_observed.map {|data| data["ParameterName"]}
|
44
|
+
end
|
45
|
+
|
46
|
+
def observed_contaminates_and_levels
|
47
|
+
Hash[observed_contaminates.zip observed_levels]
|
48
|
+
end
|
49
|
+
|
50
|
+
def observed_aqi_values
|
51
|
+
parsed_observed.map {|data| data["AQI"]}
|
52
|
+
end
|
53
|
+
|
54
|
+
def forecasted_aqi_values
|
55
|
+
parsed_forecast.map {|data| data["AQI"]}
|
56
|
+
end
|
57
|
+
|
58
|
+
def forecasted_contaminates_and_aqi_values
|
59
|
+
Hash[forecasted_contaminates.zip forecasted_aqi_values]
|
60
|
+
end
|
61
|
+
|
62
|
+
def observed_contaminates_and_aqi_values
|
63
|
+
Hash[observed_contaminates.zip observed_aqi_values]
|
64
|
+
end
|
65
|
+
|
66
|
+
def reporting_area
|
67
|
+
parsed_observed[0]["ReportingArea"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def clean_checked_concerns
|
71
|
+
concerns = checked_concerns.map {|concern| concern.gsub("_", " ")}
|
72
|
+
concerns.map! do |concern|
|
73
|
+
if concern == concerns.last && concerns.count > 1
|
74
|
+
"and #{concern}."
|
75
|
+
elsif concerns.count > 1
|
76
|
+
concern + ","
|
77
|
+
else
|
78
|
+
concern + "."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
concerns.join(" ")
|
82
|
+
end
|
83
|
+
|
84
|
+
def lung_disease?(day)
|
85
|
+
condition_indicators = ["O3","PM2.5","PM10"]
|
86
|
+
alert?(condition_indicators, day)
|
87
|
+
end
|
88
|
+
|
89
|
+
def heart_disease?(day)
|
90
|
+
condition_indicators = ["PM2.5","PM10"]
|
91
|
+
alert?(condition_indicators, day)
|
92
|
+
end
|
93
|
+
|
94
|
+
def children?(day)
|
95
|
+
condition_indicators = ["O3","PM2.5","PM10"]
|
96
|
+
alert?(condition_indicators, day)
|
97
|
+
end
|
98
|
+
|
99
|
+
def older_adult?(day)
|
100
|
+
condition_indicators = ["O3","PM2.5","PM10"]
|
101
|
+
alert?(condition_indicators, day)
|
102
|
+
end
|
103
|
+
|
104
|
+
def active_outdoors?(day)
|
105
|
+
condition_indicators = ["O3"]
|
106
|
+
alert?(condition_indicators, day)
|
107
|
+
end
|
108
|
+
|
109
|
+
def general_population?(day)
|
110
|
+
red_zone?(day)
|
111
|
+
end
|
112
|
+
|
113
|
+
def alert?(condition_indicators, day)
|
114
|
+
if day == "today"
|
115
|
+
contaminates_aqis = observed_contaminates_and_aqi_values
|
116
|
+
else
|
117
|
+
contaminates_aqis = forecasted_contaminates_and_aqi_values
|
118
|
+
end
|
119
|
+
present_condition_indicators = contaminates_aqis.keys & condition_indicators
|
120
|
+
present_condition_indicators.any?{|indicator| contaminates_aqis[indicator] > 100} ||
|
121
|
+
red_zone?(day)
|
122
|
+
end
|
123
|
+
|
124
|
+
def red_zone?(day)
|
125
|
+
if day == "today"
|
126
|
+
observed_contaminates_and_aqi_values.values.any? {|value| value > 150}
|
127
|
+
else
|
128
|
+
forecasted_contaminates_and_aqi_values.values.any? {|value| value > 150}
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def health_effects?(day)
|
133
|
+
check_alerts_methods = checked_concerns.map {|concern| concern + "?"}
|
134
|
+
alerts = check_alerts_methods.map {|method| send(method, day)}
|
135
|
+
alerts.include?(true)
|
136
|
+
end
|
137
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: air_monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Glen Egbert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-03 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: launchy
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: faraday
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
- - "~>"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.9.0
|
93
|
+
type: :runtime
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 0.9.0
|
103
|
+
description: This gem is for use with teh Monitor My Air app.
|
104
|
+
email:
|
105
|
+
- glenegbert1@gmail.com
|
106
|
+
executables: []
|
107
|
+
extensions: []
|
108
|
+
extra_rdoc_files: []
|
109
|
+
files:
|
110
|
+
- ".gitignore"
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE.txt
|
113
|
+
- README.md
|
114
|
+
- Rakefile
|
115
|
+
- air_monitor.gemspec
|
116
|
+
- lib/air_monitor.rb
|
117
|
+
- lib/air_monitor/version.rb
|
118
|
+
homepage: ''
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.2.2
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Gem for use with Monitor My Air App
|
142
|
+
test_files: []
|
143
|
+
has_rdoc:
|