south_african_air_quality_index 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 +56 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +110 -0
- data/LICENSE +21 -0
- data/README.md +91 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +8 -0
- data/lib/south_african_air_quality_index/client.rb +177 -0
- data/lib/south_african_air_quality_index/constants.rb +27 -0
- data/lib/south_african_air_quality_index/version.rb +3 -0
- data/lib/south_african_air_quality_index.rb +10 -0
- data/notes.txt +176 -0
- data/south_african_air_quality_index.gemspec +38 -0
- metadata +213 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d697dae6b8a2a2239caa16f7107edfca19a6fe4ca3b13dbdf35ed2cd1220a55
|
4
|
+
data.tar.gz: cbb4c1a357e70556c6a1e778a24e740ac853de86f0a7780469fb240ab87a9f3f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7b94a2be9950e13b4f8b363e297a236271144801b436cb02e0b9ef55b011eea2714c85427bdd8df476f71e1839297b46689a4687492fc762200ffb1bc4959cbb
|
7
|
+
data.tar.gz: 15583299e9d8660eb9391642cc64f8d0495e1287368225e35c651c9b6d703cb681e6ab67ef46b0a6b6f79409c9d20641a23a76f838dcd24a842612f7724aa535
|
data/.gitignore
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# Used by dotenv library to load environment variables.
|
14
|
+
# .env
|
15
|
+
|
16
|
+
# Ignore Byebug command history file.
|
17
|
+
.byebug_history
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Specific to RubyMotion (use of CocoaPods):
|
28
|
+
#
|
29
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
30
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
31
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
32
|
+
#
|
33
|
+
# vendor/Pods/
|
34
|
+
|
35
|
+
## Documentation cache and generated files:
|
36
|
+
/.yardoc/
|
37
|
+
/_yardoc/
|
38
|
+
/doc/
|
39
|
+
/rdoc/
|
40
|
+
|
41
|
+
## Environment normalization:
|
42
|
+
/.bundle/
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
|
55
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
56
|
+
# .rubocop-https?--*
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behaviour that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behaviour by participants include:
|
24
|
+
|
25
|
+
* The use of sexualised language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behaviour and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behaviour.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviours that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behaviour may be
|
58
|
+
reported by contacting the project team at contact@jasonchalom.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
south_african_air_quality_index (0.0.1)
|
5
|
+
active_attr (~> 0.15)
|
6
|
+
httparty (~> 0.20)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (7.0.3)
|
12
|
+
actionview (= 7.0.3)
|
13
|
+
activesupport (= 7.0.3)
|
14
|
+
rack (~> 2.0, >= 2.2.0)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
+
actionview (7.0.3)
|
19
|
+
activesupport (= 7.0.3)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
+
active_attr (0.15.4)
|
25
|
+
actionpack (>= 3.0.2, < 7.1)
|
26
|
+
activemodel (>= 3.0.2, < 7.1)
|
27
|
+
activesupport (>= 3.0.2, < 7.1)
|
28
|
+
activemodel (7.0.3)
|
29
|
+
activesupport (= 7.0.3)
|
30
|
+
activesupport (7.0.3)
|
31
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
32
|
+
i18n (>= 1.6, < 2)
|
33
|
+
minitest (>= 5.1)
|
34
|
+
tzinfo (~> 2.0)
|
35
|
+
addressable (2.8.0)
|
36
|
+
public_suffix (>= 2.0.2, < 5.0)
|
37
|
+
ansi (1.5.0)
|
38
|
+
builder (3.2.4)
|
39
|
+
coderay (1.1.3)
|
40
|
+
concurrent-ruby (1.1.10)
|
41
|
+
crack (0.4.5)
|
42
|
+
rexml
|
43
|
+
crass (1.0.6)
|
44
|
+
erubi (1.10.0)
|
45
|
+
hashdiff (1.0.1)
|
46
|
+
httparty (0.20.0)
|
47
|
+
mime-types (~> 3.0)
|
48
|
+
multi_xml (>= 0.5.2)
|
49
|
+
i18n (1.10.0)
|
50
|
+
concurrent-ruby (~> 1.0)
|
51
|
+
loofah (2.18.0)
|
52
|
+
crass (~> 1.0.2)
|
53
|
+
nokogiri (>= 1.5.9)
|
54
|
+
method_source (1.0.0)
|
55
|
+
mime-types (3.4.1)
|
56
|
+
mime-types-data (~> 3.2015)
|
57
|
+
mime-types-data (3.2022.0105)
|
58
|
+
minitest (5.15.0)
|
59
|
+
minitest-focus (1.1.2)
|
60
|
+
minitest (>= 4, < 6)
|
61
|
+
minitest-reporters (1.4.3)
|
62
|
+
ansi
|
63
|
+
builder
|
64
|
+
minitest (>= 5.0)
|
65
|
+
ruby-progressbar
|
66
|
+
mocha (1.11.2)
|
67
|
+
multi_xml (0.6.0)
|
68
|
+
nokogiri (1.13.6-arm64-darwin)
|
69
|
+
racc (~> 1.4)
|
70
|
+
pry (0.14.1)
|
71
|
+
coderay (~> 1.1)
|
72
|
+
method_source (~> 1.0)
|
73
|
+
public_suffix (4.0.7)
|
74
|
+
racc (1.6.0)
|
75
|
+
rack (2.2.3.1)
|
76
|
+
rack-test (1.1.0)
|
77
|
+
rack (>= 1.0, < 3)
|
78
|
+
rails-dom-testing (2.0.3)
|
79
|
+
activesupport (>= 4.2.0)
|
80
|
+
nokogiri (>= 1.6)
|
81
|
+
rails-html-sanitizer (1.4.2)
|
82
|
+
loofah (~> 2.3)
|
83
|
+
rake (13.0.6)
|
84
|
+
rexml (3.2.5)
|
85
|
+
ruby-progressbar (1.11.0)
|
86
|
+
timecop (0.9.5)
|
87
|
+
tzinfo (2.0.4)
|
88
|
+
concurrent-ruby (~> 1.0)
|
89
|
+
webmock (3.8.3)
|
90
|
+
addressable (>= 2.3.6)
|
91
|
+
crack (>= 0.3.2)
|
92
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
93
|
+
|
94
|
+
PLATFORMS
|
95
|
+
arm64-darwin-20
|
96
|
+
|
97
|
+
DEPENDENCIES
|
98
|
+
bundler (~> 2.3.5)
|
99
|
+
minitest (~> 5.0)
|
100
|
+
minitest-focus (~> 1.1.2)
|
101
|
+
minitest-reporters (~> 1.4.2)
|
102
|
+
mocha (~> 1.11.2)
|
103
|
+
pry (~> 0.14.1)
|
104
|
+
rake (~> 13.0)
|
105
|
+
south_african_air_quality_index!
|
106
|
+
timecop (~> 0.9.1)
|
107
|
+
webmock (~> 3.8.3)
|
108
|
+
|
109
|
+
BUNDLED WITH
|
110
|
+
2.3.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Jason Chalom
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# South African Air Quality Index
|
2
|
+
A client for the South African Air Quality Index (SAAQIS)
|
3
|
+
This is an unofficial project and still a work in progress (WIP) ... more to come soon.
|
4
|
+
|
5
|
+
Based on this website: https://saaqis.environment.gov.za/
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'south_african_air_quality_index'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install south_african_air_quality_index
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'south_african_air_quality_index'
|
27
|
+
client = SouthAfricanAirQualityIndex::Client.new
|
28
|
+
|
29
|
+
# To list stations and available monitors:
|
30
|
+
client.stations
|
31
|
+
|
32
|
+
# To get the correct list of info for reports
|
33
|
+
station_names = ['City of Johannesburg', 'City of Ekurhuleni', 'City of Cape Town']
|
34
|
+
client.selected_stations(station_names, build_for_response: true)
|
35
|
+
|
36
|
+
# To get a report from one stations
|
37
|
+
# Some defaults that are used:
|
38
|
+
# interval: DEFAULT_INTERVAL (60)
|
39
|
+
# report_type: REPORT_TYPE (average)
|
40
|
+
#
|
41
|
+
# station_name - will do a best match to the name
|
42
|
+
# start_date - can be a Time, DateTime or string 30/01/2022 00:00
|
43
|
+
# end_date - can be a Time, DateTime or string 30/01/2022 00:00
|
44
|
+
station_name = 'City of Ekurhuleni'
|
45
|
+
start_date = Time.now - (60 * 60)
|
46
|
+
end_date = Time.now
|
47
|
+
client.station_report(station_name, start_date, end_date)
|
48
|
+
|
49
|
+
# To get a report from multiple stations at once
|
50
|
+
# Some defaults that are used:
|
51
|
+
# interval: DEFAULT_INTERVAL (60)
|
52
|
+
# report_type: REPORT_TYPE (average)
|
53
|
+
#
|
54
|
+
# station_names - will do a best match to the name
|
55
|
+
# start_date - can be a Time, DateTime or string 30/01/2022 00:00
|
56
|
+
# end_date - can be a Time, DateTime or string 30/01/2022 00:00
|
57
|
+
station_names = ['City of Johannesburg', 'City of Ekurhuleni', 'City of Cape Town']
|
58
|
+
start_date = Time.now - (60 * 60)
|
59
|
+
end_date = Time.now
|
60
|
+
client.multi_station_report(station_names, start_date, end_date)
|
61
|
+
```
|
62
|
+
|
63
|
+
### Endpoints
|
64
|
+
- Stations
|
65
|
+
- GetStationReportData
|
66
|
+
- GetMultiStationReportData
|
67
|
+
|
68
|
+
Other endpoints have not been implemented.
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
75
|
+
|
76
|
+
### Tests
|
77
|
+
To run tests execute:
|
78
|
+
|
79
|
+
$ rake test
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/trex22/south_african_air_quality_index. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
88
|
+
|
89
|
+
## Code of Conduct
|
90
|
+
|
91
|
+
Everyone interacting in the SouthAfricanAirQualityIndex: project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/trex22/south_african_air_quality_index/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "south_african_air_quality_index"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
module SouthAfricanAirQualityIndex
|
2
|
+
class Client
|
3
|
+
include ::SouthAfricanAirQualityIndex::Constants
|
4
|
+
|
5
|
+
attr_reader :base_path, :port, :stations
|
6
|
+
|
7
|
+
def initialize(base_path: BASE_PATH, port: 80)
|
8
|
+
@base_path = base_path
|
9
|
+
@port = port
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.compatible_api_version
|
13
|
+
'v1'
|
14
|
+
end
|
15
|
+
|
16
|
+
# This is the version of the API docs this client was built off-of
|
17
|
+
def self.api_version
|
18
|
+
'v1 2022-06-08'
|
19
|
+
end
|
20
|
+
|
21
|
+
# Endpoints
|
22
|
+
|
23
|
+
# Memoize stations as they are unlikely to change often
|
24
|
+
def stations
|
25
|
+
@stations ||= send(http_method: :get, path: 'ajax/getAllStationsNew')
|
26
|
+
end
|
27
|
+
|
28
|
+
def stations_from_code(codes, build_for_response: false)
|
29
|
+
stations['body']['Stations'].select do |station|
|
30
|
+
codes.map(&:to_s).include?(station["serialCode"].to_s)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def selected_stations(station_names)
|
35
|
+
stations['body']['Stations'].select do |station|
|
36
|
+
station_matches?(station_names, station)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def station_report(station_name, start_date, end_date, interval: DEFAULT_INTERVAL, report_type: REPORT_TYPE)
|
41
|
+
station = selected_stations([station_name]).first
|
42
|
+
return if station.empty?
|
43
|
+
|
44
|
+
monitor_ids = fetch_monitor_ids(station)
|
45
|
+
|
46
|
+
body = {
|
47
|
+
"StationId": station['serialCode'],
|
48
|
+
"MonitorsChannels": monitor_ids,
|
49
|
+
"reportName": STATION_REPORT,
|
50
|
+
"startDateAbsolute": start_date.to_s,
|
51
|
+
"endDateAbsolute": end_date.to_s,
|
52
|
+
"startDate": start_date.to_s,
|
53
|
+
"endDate": end_date.to_s,
|
54
|
+
"reportType": report_type,
|
55
|
+
"fromTb": 60,
|
56
|
+
"toTb": 60
|
57
|
+
}.to_json
|
58
|
+
|
59
|
+
send(http_method: :get, path: 'report/GetStationReportData', body: body, params: { 'InPopUp': false })
|
60
|
+
end
|
61
|
+
|
62
|
+
def multi_station_report(station_names, start_date, end_date, interval: DEFAULT_INTERVAL, report_type: REPORT_TYPE)
|
63
|
+
extracted_stations = selected_stations(station_names)
|
64
|
+
|
65
|
+
monitor_channels_by_station_id = extracted_stations.map { |station|
|
66
|
+
[station['serialCode'].to_s, fetch_monitor_ids(station)]
|
67
|
+
}.to_h
|
68
|
+
|
69
|
+
body = {
|
70
|
+
"monitorChannelsByStationId": monitor_channels_by_station_id,
|
71
|
+
"reportName": HOURLY_REPORT,
|
72
|
+
"startDateAbsolute": start_date.to_s,
|
73
|
+
"endDateAbsolute": end_date.to_s,
|
74
|
+
"startDate": "/Date(#{Time.parse(start_date.to_s).to_i})/",
|
75
|
+
"endDate": "/Date(#{Time.parse(end_date.to_s).to_i})/",
|
76
|
+
"reportType": REPORT_TYPE,
|
77
|
+
"fromTb": DEFAULT_INTERVAL,
|
78
|
+
"toTb": DEFAULT_INTERVAL
|
79
|
+
}
|
80
|
+
|
81
|
+
monitor_channels_by_station_id.each.with_index do |pair, index|
|
82
|
+
hsh = {
|
83
|
+
"monitorChannelsByStationId[#{index}].Key": pair[0],
|
84
|
+
"monitorChannelsByStationId[#{index}].Value": pair[1]
|
85
|
+
}
|
86
|
+
|
87
|
+
body = body.merge(hsh)
|
88
|
+
end
|
89
|
+
|
90
|
+
send(http_method: :get, path: 'report/GetMultiStationReportData', body: body.to_json)
|
91
|
+
end
|
92
|
+
|
93
|
+
private
|
94
|
+
|
95
|
+
def send(http_method:, path:, body: {}, params: {})
|
96
|
+
start_time = micro_second_time
|
97
|
+
|
98
|
+
response = HTTParty.send(
|
99
|
+
http_method.to_sym,
|
100
|
+
construct_base_path(path, params),
|
101
|
+
body: body,
|
102
|
+
headers: { 'Content-Type': 'application/json' },
|
103
|
+
port: port,
|
104
|
+
format: :json
|
105
|
+
)
|
106
|
+
|
107
|
+
end_time = micro_second_time
|
108
|
+
construct_response_object(response, path, start_time, end_time)
|
109
|
+
end
|
110
|
+
|
111
|
+
def construct_response_object(response, path, start_time, end_time)
|
112
|
+
{
|
113
|
+
'body' => parse_body(response, path),
|
114
|
+
'headers' => response.headers,
|
115
|
+
'metadata' => construct_metadata(response, start_time, end_time)
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
def construct_metadata(response, start_time, end_time)
|
120
|
+
total_time = end_time - start_time
|
121
|
+
|
122
|
+
{
|
123
|
+
'start_time' => start_time,
|
124
|
+
'end_time' => end_time,
|
125
|
+
'total_time' => total_time
|
126
|
+
}
|
127
|
+
end
|
128
|
+
|
129
|
+
def micro_second_time
|
130
|
+
(Time.now.to_f * 1_000_000).to_i
|
131
|
+
end
|
132
|
+
|
133
|
+
def construct_base_path(path, params)
|
134
|
+
constructed_path = "#{base_path}/#{path}"
|
135
|
+
|
136
|
+
if params == {}
|
137
|
+
constructed_path
|
138
|
+
else
|
139
|
+
"#{constructed_path}?#{process_params(params)}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def parse_body(response, path)
|
144
|
+
JSON.parse(response.body) # Purposely not using HTTParty
|
145
|
+
rescue JSON::ParserError => _e
|
146
|
+
response.body
|
147
|
+
end
|
148
|
+
|
149
|
+
def process_params(params)
|
150
|
+
params.keys.map { |key| "#{key}=#{params[key]}" }.join('&')
|
151
|
+
end
|
152
|
+
|
153
|
+
def station_matches?(station_names, station)
|
154
|
+
station_names
|
155
|
+
.compact
|
156
|
+
.any? do |station_name|
|
157
|
+
processed_name = process_station(station_name)
|
158
|
+
|
159
|
+
process_station(station['city']) == processed_name ||
|
160
|
+
process_station(station['DisplayName']) == processed_name ||
|
161
|
+
process_station(station['name']) == processed_name ||
|
162
|
+
process_station(station['owner']) == processed_name ||
|
163
|
+
process_station(station['location']) == processed_name # TODO: Each monitor has a name too
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def fetch_monitor_ids(station)
|
168
|
+
station['monitors'].map do |monitor|
|
169
|
+
monitor['channel']
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def process_station(name)
|
174
|
+
name.downcase.gsub(' ', ' ')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SouthAfricanAirQualityIndex
|
2
|
+
module Constants
|
3
|
+
BASE_PATH = 'https://saaqis.environment.gov.za'
|
4
|
+
|
5
|
+
DEFAULT_INTERVAL = 60
|
6
|
+
STATION_REPORT = 'station report'.freeze
|
7
|
+
HOURLY_REPORT = 'hourly report'.freeze
|
8
|
+
REPORT_TYPE = 'Average'.freeze
|
9
|
+
|
10
|
+
# https://api-docs.iqair.com/?version=latest#important-notes
|
11
|
+
# https://www.airnow.gov/aqi/aqi-basics/
|
12
|
+
# https://www.weather.gov/safety/airquality-aqindex
|
13
|
+
AQI_INDEX = {
|
14
|
+
good: { lowest_level: 0, highest_level: 50, colour: 'green', description: 'Air quality is satisfactory, and air pollution poses little or no risk.' },
|
15
|
+
moderate: { lowest_level: 51, highest_level: 100, colour: 'yellow', description: 'Air quality is acceptable. However, there may be a risk for some people, particularly those who are unusually sensitive to air pollution.' },
|
16
|
+
unhealthy_for_sensitive_groups: { lowest_level: 101, highest_level: 150, colour: 'orange', description: 'Members of sensitive groups may experience health effects. The general public is less likely to be affected.' },
|
17
|
+
unhealthy: { lowest_level: 151, highest_level: 200, colour: 'red', description: 'Some members of the general public may experience health effects; members of sensitive groups may experience more serious health effects.' },
|
18
|
+
very_unhealthy: { lowest_level: 201, highest_level: 300, colour: 'purple', description: 'Health alert: The risk of health effects is increased for everyone.' },
|
19
|
+
hazardous: { lowest_level: 301, highest_level: 1000, colour: 'maroon', description: 'Health warning of emergency conditions: everyone is more likely to be affected.' }
|
20
|
+
}
|
21
|
+
|
22
|
+
def calculate_aqi_range(key)
|
23
|
+
value = AQI_INDEX[:key]
|
24
|
+
(value.lowest_level..value.highest_level).to_a
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/notes.txt
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
https://aqicn.org/city/south-africa/ekurhuleni/bedfordview/
|
2
|
+
https://saaqis.environment.gov.za/
|
3
|
+
|
4
|
+
https://saaqis.environment.gov.zacurl 'https://saaqis.environment.gov.za/report/MultiStationTable' \ -H 'authority: saaqis.environment.gov.za' \ -H 'accept: */*' \ -H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \ -H 'content-type: application/json; charset=UTF-8' \ -H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \ -H 'dnt: 1' \ -H 'origin: https://saaqis.environment.gov.za' \ -H 'referer: https://saaqis.environment.gov.za/' \ -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \ -H 'sec-ch-ua-mobile: ?0' \ -H 'sec-ch-ua-platform: "macOS"' \ -H 'sec-fetch-dest: empty' \ -H 'sec-fetch-mode: cors' \ -H 'sec-fetch-site: same-origin' \ -H 'sec-gpc: 1' \ -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \ -H 'x-requested-with: XMLHttpRequest' \ --data-raw '{"reportConfig":{"reportName":"hourly report","reportType":"Average","startDate":"08/06/2022 01:00","endDate":"09/06/2022 00:00","startDateAbsolute":"08/06/2022 01:00","endDateAbsolute":"09/06/2022 00:00","fromTb":60,"toTb":60,"monitorChannelsByStationId[0].Key":"34","monitorChannelsByStationId[0].Value":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"monitorChannelsByStationId[1].Key":"93","monitorChannelsByStationId[1].Value":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"monitorChannelsByStationId[2].Key":"161","monitorChannelsByStationId[2].Value":[28,27,25,23,11,14,31,35,1,29,12,26],"monitorChannelsByStationId[3].Key":"168","monitorChannelsByStationId[3].Value":[30,28,27,25,23,29]},"InPopUp":true,"isSummaryOnBottomTable":true}' \ --compressed
|
5
|
+
|
6
|
+
# Single Station
|
7
|
+
curl 'https://saaqis.environment.gov.za/report/GetStationReportData' \
|
8
|
+
-H 'authority: saaqis.environment.gov.za' \
|
9
|
+
-H 'accept: */*' \
|
10
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
11
|
+
-H 'content-type: application/json; charset=UTF-8' \
|
12
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
13
|
+
-H 'dnt: 1' \
|
14
|
+
-H 'origin: https://saaqis.environment.gov.za' \
|
15
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
16
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
17
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
18
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
19
|
+
-H 'sec-fetch-dest: empty' \
|
20
|
+
-H 'sec-fetch-mode: cors' \
|
21
|
+
-H 'sec-fetch-site: same-origin' \
|
22
|
+
-H 'sec-gpc: 1' \
|
23
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
24
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
25
|
+
--data-raw '{"StationId":168,"MonitorsChannels":[23,25,27,28,29,30],"reportName":"station report","startDateAbsolute":"08/06/2022 00:01","endDateAbsolute":"09/06/2022 00:00","startDate":"08/06/2022 00:01","endDate":"09/06/2022 23:01","reportType":"Average","fromTb":60,"toTb":60}' \
|
26
|
+
--compressed
|
27
|
+
|
28
|
+
# Hourly reports info
|
29
|
+
https://saaqis.environment.gov.za/Report/HourlyReports?InPopUp=True
|
30
|
+
|
31
|
+
curl 'https://saaqis.environment.gov.za/Report/HourlyReports?InPopUp=True' \
|
32
|
+
-H 'authority: saaqis.environment.gov.za' \
|
33
|
+
-H 'accept: */*' \
|
34
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
35
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
36
|
+
-H 'dnt: 1' \
|
37
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
38
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
39
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
40
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
41
|
+
-H 'sec-fetch-dest: empty' \
|
42
|
+
-H 'sec-fetch-mode: cors' \
|
43
|
+
-H 'sec-fetch-site: same-origin' \
|
44
|
+
-H 'sec-gpc: 1' \
|
45
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
46
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
47
|
+
--compressed
|
48
|
+
|
49
|
+
# Returns HTML with names etc ...
|
50
|
+
require 'httparty'
|
51
|
+
response = HTTParty.get('https://saaqis.environment.gov.za/Report/HourlyReports?InPopUp=False', headers: {'Content-Type' => 'application/json'});
|
52
|
+
|
53
|
+
response.body.split("\r\n").select { |row| row.include?("let")}
|
54
|
+
|
55
|
+
region_info = response.body.split("\r\n").select { |row| row.include?("let m_Regions =")}.first.delete!(';').delete!(" let m_Regions =").gsub('ru,', '"ru",').gsub('u,', '"u",').gsub('u}', '"u"}').gsub('fa,', '"fa",');
|
56
|
+
ru
|
57
|
+
|
58
|
+
puts region_info
|
59
|
+
JSON.parse(region_info)
|
60
|
+
|
61
|
+
# Multi Station Table (not useful)
|
62
|
+
curl 'https://saaqis.environment.gov.za/report/MultiStationTable' \
|
63
|
+
-H 'authority: saaqis.environment.gov.za' \
|
64
|
+
-H 'accept: */*' \
|
65
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
66
|
+
-H 'content-type: application/json; charset=UTF-8' \
|
67
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
68
|
+
-H 'dnt: 1' \
|
69
|
+
-H 'origin: https://saaqis.environment.gov.za' \
|
70
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
71
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
72
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
73
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
74
|
+
-H 'sec-fetch-dest: empty' \
|
75
|
+
-H 'sec-fetch-mode: cors' \
|
76
|
+
-H 'sec-fetch-site: same-origin' \
|
77
|
+
-H 'sec-gpc: 1' \
|
78
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
79
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
80
|
+
--data-raw '{"reportConfig":{"reportName":"hourly report","reportType":"Average","startDate":"08/06/2022 01:00","endDate":"09/06/2022 00:00","startDateAbsolute":"08/06/2022 01:00","endDateAbsolute":"09/06/2022 00:00","fromTb":60,"toTb":60,"monitorChannelsByStationId[0].Key":"34","monitorChannelsByStationId[0].Value":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"monitorChannelsByStationId[1].Key":"93","monitorChannelsByStationId[1].Value":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"monitorChannelsByStationId[2].Key":"161","monitorChannelsByStationId[2].Value":[28,27,25,23,11,14,31,35,1,29,12,26],"monitorChannelsByStationId[3].Key":"168","monitorChannelsByStationId[3].Value":[30,28,27,25,23,29]},"InPopUp":true,"isSummaryOnBottomTable":true}' \
|
81
|
+
--compressed
|
82
|
+
|
83
|
+
require 'httparty'
|
84
|
+
response = HTTParty.get('https://saaqis.environment.gov.za/report/MultiStationTable', headers: {'Content-Type' => 'application/json'});
|
85
|
+
|
86
|
+
# Multi Station report Data
|
87
|
+
curl 'https://saaqis.environment.gov.za/report/GetMultiStationReportData' \
|
88
|
+
-H 'authority: saaqis.environment.gov.za' \
|
89
|
+
-H 'accept: */*' \
|
90
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
91
|
+
-H 'content-type: application/json; charset=UTF-8' \
|
92
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
93
|
+
-H 'dnt: 1' \
|
94
|
+
-H 'origin: https://saaqis.environment.gov.za' \
|
95
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
96
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
97
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
98
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
99
|
+
-H 'sec-fetch-dest: empty' \
|
100
|
+
-H 'sec-fetch-mode: cors' \
|
101
|
+
-H 'sec-fetch-site: same-origin' \
|
102
|
+
-H 'sec-gpc: 1' \
|
103
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
104
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
105
|
+
--data-raw '{"monitorChannelsByStationId":{"34":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"93":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"161":[28,27,25,23,11,14,31,35,1,29,12,26],"168":[30,28,27,25,23,29]},"reportName":"hourly report","startDateAbsolute":"08/06/2022 01:00","endDateAbsolute":"09/06/2022 00:00","startDate":"08/06/2022 01:00","endDate":"10/06/2022 00:00","reportType":"Average","fromTb":60,"toTb":60,"monitorChannelsByStationId[0].Key":"34","monitorChannelsByStationId[0].Value":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"monitorChannelsByStationId[1].Key":"93","monitorChannelsByStationId[1].Value":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"monitorChannelsByStationId[2].Key":"161","monitorChannelsByStationId[2].Value":[28,27,25,23,11,14,31,35,1,29,12,26],"monitorChannelsByStationId[3].Key":"168","monitorChannelsByStationId[3].Value":[30,28,27,25,23,29]}' \
|
106
|
+
--compressed
|
107
|
+
|
108
|
+
# List Stations
|
109
|
+
curl 'https://saaqis.environment.gov.za/ajax/getAllStationsNew?_=1654684287297' \
|
110
|
+
-H 'authority: saaqis.environment.gov.za' \
|
111
|
+
-H 'accept: */*' \
|
112
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
113
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
114
|
+
-H 'dnt: 1' \
|
115
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
116
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
117
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
118
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
119
|
+
-H 'sec-fetch-dest: empty' \
|
120
|
+
-H 'sec-fetch-mode: cors' \
|
121
|
+
-H 'sec-fetch-site: same-origin' \
|
122
|
+
-H 'sec-gpc: 1' \
|
123
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
124
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
125
|
+
--compressed
|
126
|
+
|
127
|
+
require 'httparty'
|
128
|
+
response2 = HTTParty.get('https://saaqis.environment.gov.za/ajax/getAllStationsNew', headers: {'Content-Type' => 'application/json'});
|
129
|
+
|
130
|
+
stations = JSON.parse(response2.body);
|
131
|
+
stations["Irregularity"].size
|
132
|
+
stations["Stations"].size
|
133
|
+
|
134
|
+
r = stations["Stations"].first
|
135
|
+
stations["Stations"].map { |r| r.size }
|
136
|
+
|
137
|
+
|
138
|
+
# Multi stations report summary
|
139
|
+
curl 'https://saaqis.environment.gov.za/report/GetMultiStationReportSummary' \
|
140
|
+
-H 'authority: saaqis.environment.gov.za' \
|
141
|
+
-H 'accept: */*' \
|
142
|
+
-H 'accept-language: en-GB,en-US;q=0.9,en;q=0.8' \
|
143
|
+
-H 'content-type: application/json; charset=UTF-8' \
|
144
|
+
-H 'cookie: ASP.NET_SessionId=z4v3us4hod3anuee0cpv0sn4' \
|
145
|
+
-H 'dnt: 1' \
|
146
|
+
-H 'origin: https://saaqis.environment.gov.za' \
|
147
|
+
-H 'referer: https://saaqis.environment.gov.za/' \
|
148
|
+
-H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="102", "Google Chrome";v="102"' \
|
149
|
+
-H 'sec-ch-ua-mobile: ?0' \
|
150
|
+
-H 'sec-ch-ua-platform: "macOS"' \
|
151
|
+
-H 'sec-fetch-dest: empty' \
|
152
|
+
-H 'sec-fetch-mode: cors' \
|
153
|
+
-H 'sec-fetch-site: same-origin' \
|
154
|
+
-H 'sec-gpc: 1' \
|
155
|
+
-H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
|
156
|
+
-H 'x-requested-with: XMLHttpRequest' \
|
157
|
+
--data-raw '{"monitorChannelsByStationId":{"34":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"93":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"161":[28,27,25,23,11,14,31,35,1,29,12,26],"168":[30,28,27,25,23,29]},"reportName":"hourly report","startDateAbsolute":"08/06/2022 01:00","endDateAbsolute":"09/06/2022 00:00","startDate":"/Date(1654642800000)/","endDate":"/Date(1654725600000)/","reportType":"Average","fromTb":60,"toTb":60,"monitorChannelsByStationId[0].Key":"34","monitorChannelsByStationId[0].Value":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"monitorChannelsByStationId[1].Key":"93","monitorChannelsByStationId[1].Value":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"monitorChannelsByStationId[2].Key":"161","monitorChannelsByStationId[2].Value":[28,27,25,23,11,14,31,35,1,29,12,26],"monitorChannelsByStationId[3].Key":"168","monitorChannelsByStationId[3].Value":[30,28,27,25,23,29]}' \
|
158
|
+
--compressed
|
159
|
+
|
160
|
+
require 'httparty'
|
161
|
+
|
162
|
+
body = '{"monitorChannelsByStationId":{"34":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"93":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"161":[28,27,25,23,11,14,31,35,1,29,12,26],"168":[30,28,27,25,23,29]},"reportName":"hourly report","startDateAbsolute":"08/06/2022 01:00","endDateAbsolute":"09/06/2022 00:00","startDate":"/Date(1654642800000)/","endDate":"/Date(1654725600000)/","reportType":"Average","fromTb":60,"toTb":60,"monitorChannelsByStationId[0].Key":"34","monitorChannelsByStationId[0].Value":[30,28,27,25,23,11,6,3,2,4,5,14,9,8,7,31,35,1,29,12],"monitorChannelsByStationId[1].Key":"93","monitorChannelsByStationId[1].Value":[30,28,27,25,23,11,6,15,3,2,4,5,14,8,7,31,35,1,29,12,13],"monitorChannelsByStationId[2].Key":"161","monitorChannelsByStationId[2].Value":[28,27,25,23,11,14,31,35,1,29,12,26],"monitorChannelsByStationId[3].Key":"168","monitorChannelsByStationId[3].Value":[30,28,27,25,23,29]}'
|
163
|
+
|
164
|
+
response = HTTParty.get('https://saaqis.environment.gov.za/report/GetMultiStationReportData', body: JSON.parse(body).to_json, headers: {'Content-Type' => 'application/json'});
|
165
|
+
|
166
|
+
|
167
|
+
Types of SA Air Quality reports
|
168
|
+
- Analyze single station
|
169
|
+
- Analyse multi station
|
170
|
+
- Analyse Multiple Params
|
171
|
+
- Hourly monitoring data (Multiple stations, time ranges and multiple sensors)
|
172
|
+
- Wind / Pollution Roses (Wind direct and pollution graphs)
|
173
|
+
- Index Report (AQI)
|
174
|
+
- Matrix Report (1 station 1 metric gives stats)
|
175
|
+
|
176
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "south_african_air_quality_index/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "south_african_air_quality_index"
|
7
|
+
spec.version = SouthAfricanAirQualityIndex::VERSION
|
8
|
+
spec.authors = ["trex22"]
|
9
|
+
spec.email = ["contact@jasonchalom.com"]
|
10
|
+
|
11
|
+
spec.summary = "A client for using the South African Air Quality Index API in Ruby."
|
12
|
+
spec.description = "A client for using the South African Air Quality Index API in Ruby. This is an unofficial project."
|
13
|
+
spec.homepage = "https://github.com/TRex22/south_african_air_quality_index"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency "httparty", "~> 0.20"
|
26
|
+
spec.add_dependency "active_attr", "~> 0.15"
|
27
|
+
|
28
|
+
# Development dependancies
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.3.5"
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1.2"
|
33
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4.2"
|
34
|
+
spec.add_development_dependency "timecop", "~> 0.9.1"
|
35
|
+
spec.add_development_dependency "mocha", "~> 1.11.2"
|
36
|
+
spec.add_development_dependency "pry", "~> 0.14.1"
|
37
|
+
spec.add_development_dependency "webmock", "~> 3.8.3"
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: south_african_air_quality_index
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- trex22
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.20'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.20'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: active_attr
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.15'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.3.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.3.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '13.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '13.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest-focus
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.1.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.1.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-reporters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.4.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.4.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: timecop
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 0.9.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 0.9.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: mocha
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 1.11.2
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 1.11.2
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pry
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.14.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.14.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: webmock
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 3.8.3
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 3.8.3
|
167
|
+
description: A client for using the South African Air Quality Index API in Ruby. This
|
168
|
+
is an unofficial project.
|
169
|
+
email:
|
170
|
+
- contact@jasonchalom.com
|
171
|
+
executables: []
|
172
|
+
extensions: []
|
173
|
+
extra_rdoc_files: []
|
174
|
+
files:
|
175
|
+
- ".gitignore"
|
176
|
+
- CODE_OF_CONDUCT.md
|
177
|
+
- Gemfile
|
178
|
+
- Gemfile.lock
|
179
|
+
- LICENSE
|
180
|
+
- README.md
|
181
|
+
- Rakefile
|
182
|
+
- bin/console
|
183
|
+
- bin/setup
|
184
|
+
- lib/south_african_air_quality_index.rb
|
185
|
+
- lib/south_african_air_quality_index/client.rb
|
186
|
+
- lib/south_african_air_quality_index/constants.rb
|
187
|
+
- lib/south_african_air_quality_index/version.rb
|
188
|
+
- notes.txt
|
189
|
+
- south_african_air_quality_index.gemspec
|
190
|
+
homepage: https://github.com/TRex22/south_african_air_quality_index
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
metadata: {}
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubygems_version: 3.3.4
|
210
|
+
signing_key:
|
211
|
+
specification_version: 4
|
212
|
+
summary: A client for using the South African Air Quality Index API in Ruby.
|
213
|
+
test_files: []
|