lita-onewheel-aqi 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 790b606deb76e9e81cbfde72a363c46e4d5d2aa0
4
- data.tar.gz: 3e827a32469286d8785e7c5f364483aa8ae1f6f4
3
+ metadata.gz: 9d04773171d0c0dd5ae10537abfe5d3131a25d54
4
+ data.tar.gz: 39d74cd311c6c2fbf1c3bc8870849f7fa793c08d
5
5
  SHA512:
6
- metadata.gz: f58f3e7abbd496f090757b5432a15b6b3bb61909958900e9c61f2455ab7908c40c7867ec1ea9dd913efd15e3906408bb40ee73429d6eb4b4aaa9315ffaef75e7
7
- data.tar.gz: 1710cbc07724c8c8e64e3a036eb3ba42a11fbf871a617c90163cd87395742f3200278ba85142d8e1a2d9b1dc5326fa9c249b28d04226cf2b8f7ea12a1ecad957
6
+ metadata.gz: 514b49d9f19dfa4ef1b2321b9f1b207bf9228717bba124d666d6e00532e71192687908e527b32ce74ed5c7093c7596623d72ca05e4b58f6c0b5bce85d1526703
7
+ data.tar.gz: da51c6ec10fb801c5c7c2b69955f81f4d393bc4864ab42c48be64359134647129229f8c78f915781ca91f6f577ad93d654d16615467e3f4a3fbae142980456ba
@@ -82,7 +82,7 @@ module Lita
82
82
  end
83
83
 
84
84
  def get_location(response)
85
- location = if response.matches[0].to_s.casecmp('aqi').zero?
85
+ location = if response.matches[0][0].to_s.length == 1
86
86
  ''
87
87
  else
88
88
  response.matches[0][0]
@@ -125,6 +125,8 @@ module Lita
125
125
 
126
126
  if aqi['data']['iaqi']['pm25']
127
127
  reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
128
+ ugm3 = pm25_to_ugm3 aqi['data']['iaqi']['pm25']['v'].to_s
129
+ reply += "#{ugm3} µgm3(est) "
128
130
  end
129
131
  if aqi['data']['iaqi']['pm10']
130
132
  reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
@@ -160,11 +162,13 @@ module Lita
160
162
  if aqi['data']['iaqi']['p']
161
163
  reply += 'pressure: ' + aqi['data']['iaqi']['p']['v'].to_s + 'mb '
162
164
  end
163
- if aqi['data']['iaqi']['pm10']
164
- reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
165
- end
166
165
  if aqi['data']['iaqi']['pm25']
167
166
  reply += 'pm25: ' + color_str(aqi['data']['iaqi']['pm25']['v'].to_s) + ' '
167
+ ugm3 = pm25_to_ugm3 aqi['data']['iaqi']['pm25']['v']
168
+ reply += "#{ugm3} µgm3(est) "
169
+ end
170
+ if aqi['data']['iaqi']['pm10']
171
+ reply += 'pm10: ' + color_str(aqi['data']['iaqi']['pm10']['v'].to_s) + ' '
168
172
  end
169
173
  if aqi['data']['iaqi']['t']
170
174
  reply += 'temp: ' + aqi['data']['iaqi']['t']['v'].to_s + 'C '
@@ -206,17 +210,6 @@ module Lita
206
210
  str
207
211
  end
208
212
 
209
- def extract_pmtwofive(aqi)
210
- Lita.logger.debug "extract_pmtwofive with #{aqi}"
211
- pm25 = ''
212
- pm25 = if aqi['data']['iaqi']['pm25']
213
- aqi['data']['iaqi']['pm25']['v']
214
- else
215
- "No PM2.5 data for #{aqi['data']['city']['name']}"
216
- end
217
- pm25
218
- end
219
-
220
213
  # Geographical stuffs
221
214
  # Now with less caching!
222
215
  def optimistic_geo_wrapper(query)
@@ -237,6 +230,28 @@ module Lita
237
230
  lat: geocoded['geometry']['location']['lat'],
238
231
  lng: geocoded['geometry']['location']['lng'] }
239
232
  end
233
+
234
+ # Particulate Matter 2.5 to micrograms per cubic meter
235
+ def pm25_to_ugm3(pm25)
236
+ ranges = {
237
+ 0..50 => [0, 50, 0.0, 12.0],
238
+ 51..100 => [51, 100, 12.1, 35.4],
239
+ 101..150 => [101, 150, 35.5, 55.4],
240
+ 151..200 => [151, 200, 55.5, 150.4],
241
+ 201..300 => [201, 300, 150.5, 250.4],
242
+ 301..500 => [301, 500, 250.5, 500]
243
+ }
244
+ ranges.keys.each do |range_key|
245
+ next unless range_key.cover? pm25.to_i
246
+ low = ranges[range_key][0]
247
+ high = ranges[range_key][1]
248
+ min = ranges[range_key][2]
249
+ max = ranges[range_key][3]
250
+ step = (max - min) / (high - low)
251
+ ugm3 = (pm25.to_i - low) * step + min
252
+ return ugm3.round(2)
253
+ end
254
+ end
240
255
  end
241
256
 
242
257
  Lita.register_handler(OnewheelAqi)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'lita-onewheel-aqi'
3
- spec.version = '2.0.9'
3
+ spec.version = '2.0.10'
4
4
  spec.authors = ['Andrew Kreps']
5
5
  spec.email = ['andrew.kreps@gmail.com']
6
6
  spec.description = 'AQI data retrieval bot'
@@ -34,11 +34,11 @@ describe Lita::Handlers::OnewheelAqi, lita_handler: true do
34
34
 
35
35
  it 'queries the aqi' do
36
36
  send_command 'aqi'
37
- expect(replies.last).to include("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ pm25: 0876 pm10: 0340 updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
37
+ expect(replies.last).to include("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ pm25: 0876 23.99 µgm3(est) pm10: 0340 updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
38
38
  end
39
39
 
40
40
  it 'queries the aqideets' do
41
41
  send_command 'aqideets'
42
- expect(replies.last).to eq("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ humidity: 11% pressure: 1014mb pm10: 0340 pm25: 0876 temp: 34.65C updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
42
+ expect(replies.last).to eq("AQI for Portland, OR, USA, ⚠️ 08Moderate ⚠️ humidity: 11% pressure: 1014mb pm25: 0876 23.99 µgm3(est) pm10: 0340 temp: 34.65C updated 0860 minutes ago. 14(http://aqicn.org/city/usa/oregon/government-camp-multorpor-visibility/)")
43
43
  end
44
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-aqi
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps