kovid 0.6.13 → 0.6.14

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
  SHA256:
3
- metadata.gz: 4c0bc9550073aaff0f2e6fb4a4175b4147bacf6c43d4d47d0177771845d30f01
4
- data.tar.gz: 5e960a7772a01ad8c67c77284eaebc46cb55827522e6890f62b935b87d6e3494
3
+ metadata.gz: 2896f04560ac519045555f79fc0d8cdcbcee7ed9069aecd1ebdbcba181584927
4
+ data.tar.gz: fe15af9091b1a03ae8ac6a78e712c5a7dc7dd1a7b433e45b9c6bdad05c709f22
5
5
  SHA512:
6
- metadata.gz: 7f65a6ea777bde11958ab2c3d43f73b63d83d23b18f5c21757be1e46e8ebda407b762714b32d1cab819cde75a41344735799670e41b17bd9e5a175d2e52892a0
7
- data.tar.gz: d542e777ce15d0d0236faf62264d7fd2679b4655295e51be4871ba2f1c4990fb658f9d02fc6824357a73cb94e8cd54013b8a5106819e21ded1ad6d9c07b0dbcd
6
+ metadata.gz: 9a4260377fa1d38f2b9dd9f7b94bdcf3527e437f2c89e15d15d1a0b87df11a09934baa56a6d8b13f1e1a588b0590b4a1646f7ca6f9c96a141f1b2178054bc358
7
+ data.tar.gz: c9c313cf8982980845c5d73d5da9e9d9cab82738825762bbceb3a07e511f7ccae1d12516cadd80bfb86fa88c8a2dd4b58615db396a0ba901d7fa94fbddcd21c7
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.6.12)
4
+ kovid (0.6.13)
5
5
  carmen (~> 1.1.3)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
@@ -11,12 +11,12 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activesupport (6.0.2.2)
14
+ activesupport (6.0.3.1)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 0.7, < 2)
17
17
  minitest (~> 5.1)
18
18
  tzinfo (~> 1.1)
19
- zeitwerk (~> 2.2)
19
+ zeitwerk (~> 2.2, >= 2.2.2)
20
20
  carmen (1.1.3)
21
21
  activesupport (>= 3.0.0)
22
22
  concurrent-ruby (1.1.6)
@@ -24,25 +24,25 @@ GEM
24
24
  docile (1.3.2)
25
25
  ethon (0.12.0)
26
26
  ffi (>= 1.3.0)
27
- ffi (1.12.2)
28
- i18n (1.8.2)
27
+ ffi (1.13.0)
28
+ i18n (1.8.3)
29
29
  concurrent-ruby (~> 1.0)
30
- minitest (5.14.0)
30
+ minitest (5.14.1)
31
31
  rainbow (3.0.0)
32
32
  rake (12.3.3)
33
33
  rspec (3.9.0)
34
34
  rspec-core (~> 3.9.0)
35
35
  rspec-expectations (~> 3.9.0)
36
36
  rspec-mocks (~> 3.9.0)
37
- rspec-core (3.9.1)
38
- rspec-support (~> 3.9.1)
39
- rspec-expectations (3.9.1)
37
+ rspec-core (3.9.2)
38
+ rspec-support (~> 3.9.3)
39
+ rspec-expectations (3.9.2)
40
40
  diff-lcs (>= 1.2.0, < 2.0)
41
41
  rspec-support (~> 3.9.0)
42
42
  rspec-mocks (3.9.1)
43
43
  diff-lcs (>= 1.2.0, < 2.0)
44
44
  rspec-support (~> 3.9.0)
45
- rspec-support (3.9.2)
45
+ rspec-support (3.9.3)
46
46
  simplecov (0.18.5)
47
47
  docile (~> 1.1)
48
48
  simplecov-html (~> 0.11)
@@ -51,7 +51,7 @@ GEM
51
51
  unicode-display_width (~> 1.1, >= 1.1.1)
52
52
  thor (1.0.1)
53
53
  thread_safe (0.3.6)
54
- typhoeus (1.3.1)
54
+ typhoeus (1.4.0)
55
55
  ethon (>= 0.9.0)
56
56
  tzinfo (1.2.7)
57
57
  thread_safe (~> 0.1)
@@ -13,8 +13,9 @@ module Kovid
13
13
  'Cases Today'.paint_white,
14
14
  'Deaths'.paint_red,
15
15
  'Deaths Today'.paint_red,
16
+ 'Active'.paint_yellow,
16
17
  'Recovered'.paint_green,
17
- 'Tests'.paint_white,
18
+ 'Tests'.paint_white
18
19
  ].freeze
19
20
 
20
21
  DATE_CASES_DEATHS_RECOVERED = [
@@ -63,10 +64,12 @@ module Kovid
63
64
 
64
65
  FULL_COUNTRY_TABLE_HEADINGS = [
65
66
  'Cases'.paint_white,
66
- 'Deaths'.paint_red,
67
- 'Recovered'.paint_green,
68
67
  'Cases Today'.paint_white,
68
+ 'Deaths'.paint_red,
69
69
  'Deaths Today'.paint_red,
70
+ 'Active'.paint_yellow,
71
+ 'Recovered'.paint_green,
72
+ 'Tests'.paint_white,
70
73
  'Critical'.paint_yellow,
71
74
  'Cases/Million'.paint_white
72
75
  ].freeze
@@ -110,6 +113,9 @@ module Kovid
110
113
 
111
114
  FOOTER_LINE_FOUR_COLUMNS = FOOTER_LINE_COLUMN * 4
112
115
 
116
+ # Add footer if rows exceed this number
117
+ ADD_FOOTER_SIZE = 10
118
+
113
119
  COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
114
120
 
115
121
  RIGHT_ALIGN_COLUMNS = {
@@ -25,12 +25,6 @@ module Kovid
25
25
  num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
26
26
  end
27
27
 
28
- def format_country_history_numbers(load)
29
- load['timeline'].values.map(&:values).transpose.each do |data|
30
- data.map! { |number| Kovid.comma_delimit(number) }
31
- end
32
- end
33
-
34
28
  def lookup_us_state(state)
35
29
  us = Carmen::Country.coded('USA')
36
30
  lookup = us.subregions.coded(state) || us.subregions.named(state)
@@ -5,42 +5,32 @@ module Kovid
5
5
  include Constants
6
6
  include AsciiCharts
7
7
 
8
- def history(location, days)
9
- rows = []
8
+ def history(data, days)
9
+ rows = history_rows(data, days)
10
10
 
11
- stats = Kovid.format_country_history_numbers(location).last(days.to_i)
12
- dates = location['timeline']['cases'].keys.last(days.to_i)
13
-
14
- if days.to_i >= 30
15
- stats = stats.reject { |stat| stat[0].to_i.zero? && stat[1].to_i.zero? }
16
- dates = dates.last(stats.count)
11
+ if rows.size > ADD_FOOTER_SIZE
12
+ rows << FOOTER_LINE_FOUR_COLUMNS
13
+ rows << DATE_CASES_DEATHS_RECOVERED
17
14
  end
18
15
 
19
- stats.each_with_index do |val, index|
20
- val.unshift(Kovid.dateman(dates[index]))
21
- end.each do |row|
22
- rows << row
23
- end
16
+ Terminal::Table.new(
17
+ title: data['country'].try(:upcase),
18
+ headings: DATE_CASES_DEATHS_RECOVERED,
19
+ rows: rows
20
+ )
21
+ end
24
22
 
25
- # Title and Column format if Country or US State
26
- if location['country']
27
- title = location['country'].try(:upcase)
28
- col_format = DATE_CASES_DEATHS_RECOVERED
29
- footer = FOOTER_LINE_FOUR_COLUMNS
30
- else
31
- title = location['state'].try(:upcase)
32
- col_format = DATE_CASES_DEATHS
33
- footer = FOOTER_LINE_THREE_COLUMNS
34
- end
23
+ def history_us_state(data, days)
24
+ rows = history_rows(data, days)
35
25
 
36
- if stats.size > 10
37
- rows << footer
38
- rows << col_format
26
+ if rows.size > ADD_FOOTER_SIZE
27
+ rows << FOOTER_LINE_THREE_COLUMNS
28
+ rows << DATE_CASES_DEATHS
39
29
  end
40
30
 
41
31
  Terminal::Table.new(
42
- title: title,
43
- headings: col_format,
32
+ title: data['state'].try(:upcase),
33
+ headings: DATE_CASES_DEATHS,
44
34
  rows: rows
45
35
  )
46
36
  end
@@ -106,5 +96,20 @@ module Kovid
106
96
  AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
107
97
  end
108
98
  end
99
+
100
+ private
101
+
102
+ def history_rows(data, days)
103
+ data['timeline']['cases'].map do |date, cases|
104
+ formatted_date = Kovid.dateman(date)
105
+ cases = Kovid.comma_delimit(cases)
106
+ deaths = Kovid.comma_delimit(data['timeline']['deaths'][date])
107
+ recovered = Kovid.comma_delimit(data['timeline']['recovered'][date]) if data['timeline'].has_key? 'recovered'
108
+
109
+ row = [formatted_date, cases, deaths]
110
+ row << recovered unless recovered.nil?
111
+ row
112
+ end.last(days.to_i)
113
+ end
109
114
  end
110
115
  end
@@ -162,13 +162,7 @@ module Kovid
162
162
  end
163
163
 
164
164
  def history(country, days)
165
- history_path = UriBuilder.new('/v2/historical').url
166
-
167
- response = JSON.parse(
168
- Typhoeus.get(
169
- history_path + "/#{country}", cache_ttl: 900
170
- ).response_body
171
- )
165
+ response = fetch_history(country)
172
166
 
173
167
  if response.key?('message')
174
168
  not_found(country) do |c|
@@ -182,14 +176,8 @@ module Kovid
182
176
  end
183
177
 
184
178
  def history_us_state(state, days)
185
- history_path = UriBuilder.new('/v2/historical/usacounties').url
186
- state = Kovid.lookup_us_state(state).downcase
187
-
188
- response = JSON.parse(
189
- Typhoeus.get(
190
- history_path + "/#{state}", cache_ttl: 900
191
- ).response_body
192
- )
179
+ state = Kovid.lookup_us_state(state).downcase
180
+ response = fetch_us_history(state)
193
181
 
194
182
  if response.respond_to?(:key?) && response.key?('message')
195
183
  return not_found(state)
@@ -201,22 +189,20 @@ module Kovid
201
189
  cases = usacounties_aggregator(response, 'cases')
202
190
  deaths = usacounties_aggregator(response, 'deaths')
203
191
 
204
- # normalize data so we can call Kovid::Tablelize.history on US State data
205
192
  response = {
206
193
  'state' => state,
207
194
  'timeline' => { 'cases' => cases, 'deaths' => deaths }
208
195
  }
209
196
 
210
- Kovid::Tablelize.history(response, days)
197
+ Kovid::Tablelize.history_us_state(response, days)
211
198
  rescue JSON::ParserError
212
199
  puts SERVER_DOWN
213
200
  end
214
201
 
215
202
  def histogram(country, date)
216
- history_path = UriBuilder.new('/v2/historical').url
217
203
  response = JSON.parse(
218
204
  Typhoeus.get(
219
- history_path + "/#{country}", cache_ttl: 900
205
+ HISTORICAL_URL + "/#{country}", cache_ttl: 900
220
206
  ).response_body
221
207
  )
222
208
 
@@ -312,6 +298,22 @@ module Kovid
312
298
  end.first
313
299
  end
314
300
 
301
+ def fetch_history(country)
302
+ JSON.parse(
303
+ Typhoeus.get(
304
+ HISTORICAL_URL + "/#{country}", cache_ttl: 900
305
+ ).response_body
306
+ )
307
+ end
308
+
309
+ def fetch_us_history(state)
310
+ JSON.parse(
311
+ Typhoeus.get(
312
+ HISTORICAL_US_URL + "/#{state}", cache_ttl: 900
313
+ ).response_body
314
+ )
315
+ end
316
+
315
317
  def aggregator(isos, meth)
316
318
  countries_array = JSON.parse(countries_request)
317
319
  country_array = countries_array.select do |hash|
@@ -325,9 +327,7 @@ module Kovid
325
327
  end
326
328
 
327
329
  def countries_request
328
- Typhoeus.get(
329
- UriBuilder.new('/v2/countries').url, cache_ttl: 900
330
- ).response_body
330
+ Typhoeus.get(COUNTRIES_PATH, cache_ttl: 900).response_body
331
331
  end
332
332
 
333
333
  def countries_aggregator(country_array)
@@ -39,7 +39,7 @@ module Kovid
39
39
  Terminal::Table.new(
40
40
  title: state['state'].upcase,
41
41
  headings: FULL_STATE_TABLE_HEADINGS,
42
- rows: [country_row(state)]
42
+ rows: [state_row(state)]
43
43
  )
44
44
  end
45
45
 
@@ -136,7 +136,6 @@ module Kovid
136
136
  ]
137
137
  end
138
138
 
139
- # Also works for state
140
139
  def country_row(data)
141
140
  [
142
141
  Kovid.comma_delimit(data['cases']),
@@ -144,6 +143,7 @@ module Kovid
144
143
  Kovid.comma_delimit(data['deaths']),
145
144
  Kovid.add_plus_sign(data['todayDeaths']),
146
145
  Kovid.comma_delimit(data['active']),
146
+ Kovid.comma_delimit(data['recovered']),
147
147
  Kovid.comma_delimit(data['tests'])
148
148
  ]
149
149
  end
@@ -151,15 +151,29 @@ module Kovid
151
151
  def full_country_row(data)
152
152
  [
153
153
  Kovid.comma_delimit(data['cases']),
154
- Kovid.comma_delimit(data['deaths']),
155
- Kovid.comma_delimit(data['recovered']),
156
154
  Kovid.add_plus_sign(data['todayCases']),
155
+ Kovid.comma_delimit(data['deaths']),
157
156
  Kovid.add_plus_sign(data['todayDeaths']),
157
+ Kovid.comma_delimit(data['active']),
158
+ Kovid.comma_delimit(data['recovered']),
159
+ Kovid.comma_delimit(data['tests']),
160
+
158
161
  Kovid.comma_delimit(data['critical']),
159
162
  Kovid.comma_delimit(data['casesPerOneMillion'])
160
163
  ]
161
164
  end
162
165
 
166
+ def state_row(data)
167
+ [
168
+ Kovid.comma_delimit(data['cases']),
169
+ Kovid.add_plus_sign(data['todayCases']),
170
+ Kovid.comma_delimit(data['deaths']),
171
+ Kovid.add_plus_sign(data['todayDeaths']),
172
+ Kovid.comma_delimit(data['active']),
173
+ Kovid.comma_delimit(data['tests'])
174
+ ]
175
+ end
176
+
163
177
  def province_row(data)
164
178
  [
165
179
  data['stats']['confirmed'],
@@ -255,17 +269,16 @@ module Kovid
255
269
  end
256
270
 
257
271
  def top_heading(options)
258
- if options[:location] == :countries
259
- return ['Country'.paint_white] + FULL_COUNTRY_TABLE_HEADINGS
260
- end
272
+ full_country_table = ['Country'.paint_white] + FULL_COUNTRY_TABLE_HEADINGS
273
+ full_state_table = ['State'.paint_white] + FULL_STATE_TABLE_HEADINGS
261
274
 
262
- ['State'.paint_white] + FULL_STATE_TABLE_HEADINGS
275
+ options[:location] == :countries ? full_country_table : full_state_table
263
276
  end
264
277
 
265
278
  def top_title(options)
266
279
  incident = options[:incident].to_s
267
280
  location = options[:location].to_s
268
- "🌍 Top #{options[:count]} #{location} in #{incident}".upcase
281
+ "🌍 Top #{options[:count]} #{location} by #{incident}".upcase
269
282
  end
270
283
  end
271
284
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.6.13'
4
+ VERSION = '0.6.14'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kovid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13
4
+ version: 0.6.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emmanuel Hayford
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-13 00:00:00.000000000 Z
11
+ date: 2020-06-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carmen