kovid 0.6.0 → 0.6.5

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: d7d6bfb3cb9be53c0ba94fc9f788705f2878d31686ada02106fd2e5dd296b5fd
4
- data.tar.gz: b1d448270c2fed3bd31fd5f1311f32322bfe096cdec42e9cf7f99af99d5c0793
3
+ metadata.gz: 620426fc962e25e54afb7805dcf98131c1e58865ff477ffb9102e0d2ca90217d
4
+ data.tar.gz: 59daeb1837a6afaa795bed6479fde7c20c696a9f21a6a0f444ed1f63150e9ce1
5
5
  SHA512:
6
- metadata.gz: 175b4e746c10544101a29ce05ba76b28cc5542b95b198afb7584a2188cf570e551c304485ee6d09e464ecb5e81e7534bd3df9d81cfe4d52b6b9dab5368c6452c
7
- data.tar.gz: 2e16b56052821e5d7fbb04caf97ac1b019b5430548990aed576166144a61d24a4763c93589589a034ebe7b08f0f7cf350ba2582605eee8e9a98f66ce3e9ce37c
6
+ metadata.gz: 4741653673978adcaeadf3b22bfa8b2db1b3bae467ffca9fbca4c010b1c30b677ebcf6ced77dcda6ae4e90782678bd162f85ac913f70658fce6d7ad4beb05547
7
+ data.tar.gz: aac2306ed42a441c9673ad10ea47f2f3bde83a4dcb99de043cd63a3a352af6e4f3b42409e11de72f6a23f9e5630eb343dae5cec327c62f57fbcb5737071f6f15
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.5.8)
4
+ kovid (0.6.4)
5
5
  ascii_charts (~> 0.9.1)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -44,6 +44,7 @@ You can get continental information with the following commands:
44
44
 
45
45
  You can fetch US state-specific data:
46
46
  * `kovid state STATE` OR `kovid state "STATE NAME"`.
47
+ * `kovid states --all` or `kovid states -a` for data on all US states.
47
48
 
48
49
  Provinces
49
50
 
@@ -54,6 +54,10 @@ module Kovid
54
54
  Kovid::Request.states(states)
55
55
  end
56
56
 
57
+ def all_us_states
58
+ Kovid::Request.all_us_states
59
+ end
60
+
57
61
  def country_comparison(names_array)
58
62
  Kovid::Request.by_country_comparison(names_array)
59
63
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kovid
4
+ module Aggregators
5
+ def eu_aggregate(eu_data)
6
+ aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, '🇪🇺')
7
+ end
8
+
9
+ def europe_aggregate(europe_data)
10
+ aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, '🏰')
11
+ end
12
+
13
+ def africa_aggregate(africa_data)
14
+ aggregated_table(africa_data, 'Africa',
15
+ Kovid::Request::AFRICA_ISOS, '🌍')
16
+ end
17
+
18
+ def south_america_aggregate(south_america_data)
19
+ aggregated_table(south_america_data,
20
+ 'South America',
21
+ Kovid::Request::SOUTH_AMERICA_ISOS, '🌎')
22
+ end
23
+
24
+ def asia_aggregate(asia_data)
25
+ aggregated_table(asia_data, 'Asia', Kovid::Request::ASIA_ISOS, '🌏')
26
+ end
27
+ end
28
+ end
@@ -5,8 +5,6 @@ require 'kovid'
5
5
 
6
6
  module Kovid
7
7
  class CLI < Thor
8
- FULL_FLAG = %w[-f --full].freeze
9
-
10
8
  def self.exit_on_failure?
11
9
  true
12
10
  end
@@ -26,16 +24,22 @@ module Kovid
26
24
 
27
25
  desc 'check COUNTRY or check "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid check "hong kong".'
28
26
  method_option :full, aliases: '-f'
29
- def check(name)
30
- fetch_country_stats(name)
27
+ def check(*name)
28
+ if name.size == 1
29
+ fetch_country_stats(name.pop)
30
+ elsif options[:full]
31
+ puts Kovid.country_comparison_full(name)
32
+ else
33
+ puts Kovid.country_comparison(name)
34
+ end
31
35
  data_source
32
36
  end
37
+ map country: :check
33
38
 
34
- desc 'country COUNTRY or country "COUNTRY NAME"', 'Returns reported data on provided country. eg: "kovid country "hong kong".'
35
- method_option :full, aliases: '-f'
36
- def country(name)
37
- fetch_country_stats(name)
38
- data_source
39
+ desc 'compare COUNTRY COUNTRY', 'Deprecated. Will be removed in v7.0.0'
40
+ def compare(*_name)
41
+ Kovid.info_table("#compare is deprecated and will be removed in v7.0.0. \
42
+ \nPlease do `kovid check COUNTRY COUNTRY ...` instead.")
39
43
  end
40
44
 
41
45
  desc 'state STATE', 'Return reported data on provided state.'
@@ -44,19 +48,16 @@ module Kovid
44
48
  data_source
45
49
  end
46
50
 
47
- desc 'compare COUNTRY COUNTRY', 'Returns full comparison table for given countries. Accepts multiple countries.'
48
- def compare(*name)
49
- if FULL_FLAG.include?(name.fetch(-1))
50
- puts Kovid.country_comparison_full(name[0..-2])
51
+ desc 'states STATE STATE or states --all', 'Returns full comparison table for the given states. Accepts multiple states.'
52
+ method_option :all, aliases: '-a'
53
+ def states(*states)
54
+ if options[:all]
55
+ puts Kovid.all_us_states
51
56
  else
52
- puts Kovid.country_comparison(name)
57
+ downcased_states = states.map(&:downcase)
58
+ puts Kovid.states(downcased_states)
53
59
  end
54
- data_source
55
- end
56
60
 
57
- desc 'states STATE STATE', 'Returns full comparison table for the given states. Accepts multiple states.'
58
- def states(*states)
59
- puts Kovid.states(states)
60
61
  data_source
61
62
  end
62
63
 
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kovid
4
+ module Constants
5
+ CASES_DEATHS_RECOVERED = [
6
+ 'Cases'.paint_white,
7
+ 'Deaths'.paint_red,
8
+ 'Recovered'.paint_green
9
+ ].freeze
10
+
11
+ CASES_DEATHS_RECOVERED_CTODAY_DTODAY = [
12
+ 'Cases'.paint_white,
13
+ 'Cases Today'.paint_white,
14
+ 'Deaths'.paint_red,
15
+ 'Deaths Today'.paint_red,
16
+ 'Recovered'.paint_green
17
+ ].freeze
18
+
19
+ DATE_CASES_DEATHS_RECOVERED = [
20
+ 'Date'.paint_white,
21
+ 'Cases'.paint_white,
22
+ 'Deaths'.paint_red,
23
+ 'Recovered'.paint_green
24
+ ].freeze
25
+
26
+ CONTINENTAL_AGGREGATE_HEADINGS = [
27
+ 'Cases'.paint_white,
28
+ 'Cases Today'.paint_white,
29
+ 'Deaths'.paint_red,
30
+ 'Deaths Today'.paint_red,
31
+ 'Recovered'.paint_green,
32
+ 'Active'.paint_yellow,
33
+ 'Critical'.paint_red
34
+ ].freeze
35
+
36
+ COMPARE_COUNTRY_TABLE_FULL = [
37
+ 'Country'.paint_white,
38
+ 'Cases'.paint_white,
39
+ 'Deaths'.paint_red,
40
+ 'Recovered'.paint_green,
41
+ 'Cases Today'.paint_white,
42
+ 'Deaths Today'.paint_red,
43
+ 'Critical'.paint_yellow,
44
+ 'Cases/Million'.paint_white
45
+ ].freeze
46
+
47
+ COMPARE_COUNTRIES_TABLE_HEADINGS = [
48
+ 'Country'.paint_white,
49
+ 'Cases'.paint_white,
50
+ 'Cases Today'.paint_white,
51
+ 'Deaths'.paint_red,
52
+ 'Deaths Today'.paint_red,
53
+ 'Recovered'.paint_green
54
+ ].freeze
55
+
56
+ FULL_COUNTRY_TABLE_HEADINGS = [
57
+ 'Cases'.paint_white,
58
+ 'Deaths'.paint_red,
59
+ 'Recovered'.paint_green,
60
+ 'Cases Today'.paint_white,
61
+ 'Deaths Today'.paint_red,
62
+ 'Critical'.paint_yellow,
63
+ 'Cases/Million'.paint_white
64
+ ].freeze
65
+
66
+ COMPARE_STATES_HEADINGS = [
67
+ 'State'.paint_white,
68
+ 'Cases'.paint_white,
69
+ 'Cases Today'.paint_white,
70
+ 'Deaths'.paint_red,
71
+ 'Deaths Today'.paint_red,
72
+ 'Active'.paint_yellow
73
+ ].freeze
74
+
75
+ COMPARE_PROVINCES_HEADINGS = [
76
+ 'Province'.paint_white,
77
+ 'Confirmed'.paint_white,
78
+ 'Deaths'.paint_red,
79
+ 'Recovered'.paint_green
80
+ ].freeze
81
+
82
+ FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
83
+ COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
84
+
85
+ RIGHT_ALIGN_COLUMNS = {
86
+ compare_country_table_full: [1, 2, 3, 4, 5, 6, 7],
87
+ compare_country_table: [1, 2, 3, 4, 5],
88
+ compare_us_states: [1, 2, 3, 4, 5],
89
+ compare_provinces: [1, 2, 3]
90
+ }.freeze
91
+ end
92
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Kovid
4
+ module Historians
5
+ include Constants
6
+
7
+ def history(country, last)
8
+ # Write checks for when country is spelt wrong.
9
+ headings = DATE_CASES_DEATHS_RECOVERED
10
+ rows = []
11
+
12
+ stats = if last
13
+ transpose(country).last(last.to_i)
14
+ else
15
+ transpose(country)
16
+ end
17
+
18
+ dates = if last
19
+ country['timeline']['cases'].keys.last(last.to_i)
20
+ else
21
+ country['timeline']['cases'].keys
22
+ end
23
+
24
+ unless last
25
+ stats = stats.reject { |stat| stat[0].to_i.zero? && stat[1].to_i.zero? }
26
+ dates = dates.last(stats.count)
27
+ end
28
+
29
+ stats.each_with_index do |val, index|
30
+ val.unshift(Kovid.dateman(dates[index]))
31
+ end.each do |row|
32
+ rows << row
33
+ end
34
+
35
+ if stats.size > 10
36
+ rows << FOOTER_LINE
37
+ rows << DATE_CASES_DEATHS_RECOVERED
38
+ end
39
+
40
+ Terminal::Table.new(
41
+ title: country['country'].upcase,
42
+ headings: headings,
43
+ rows: rows
44
+ )
45
+ end
46
+
47
+ def histogram(country, date_string)
48
+ @date = date_string.split('.')
49
+
50
+ if @date.last.to_i != 20
51
+ Kovid.info_table('Only 2020 histgrams are available.')
52
+ return
53
+ end
54
+
55
+ # From dates where number of !cases.zero?
56
+ positive_cases_figures = country['timeline']['cases'].values.reject(&:zero?)
57
+ dates = country['timeline']['cases'].reject { |_k, v| v.zero? }.keys
58
+ data = []
59
+
60
+ # TODO: Refactor
61
+ # Returns array of days.to_i from the date param
62
+ dates = dates.map do |date|
63
+ date.split('/')
64
+ end.select do |date|
65
+ date.last == @date.last
66
+ end.select do |date|
67
+ date.first == @date.first
68
+ end.map do |array|
69
+ array[1]
70
+ end.map(&:to_i).last(positive_cases_figures.count)
71
+
72
+ # Arranges dates and figures in [x,y] for histogram
73
+ # With x being day, y being number of cases
74
+ if dates.empty?
75
+ if @date.first.to_i > Time.now.month
76
+ msgs = [
77
+ 'Seriously...??! 😏', 'Did you just check the future??',
78
+ 'You just checked the future Morgan.',
79
+ 'Knowing too much of your future is never a good thing.'
80
+ ]
81
+
82
+ Kovid.info_table(msgs.sample)
83
+ else
84
+ Kovid.info_table('Check your spelling/No infections for this month.')
85
+ end
86
+
87
+ else
88
+ dates.each_with_index do |val, index|
89
+ data << [val, positive_cases_figures[index]]
90
+ end
91
+ y_range = AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).y_range
92
+
93
+ last_two_y = y_range.last 2
94
+ y_interval = last_two_y.last - last_two_y.first
95
+
96
+ scale("Scale on Y: #{y_interval}:#{(y_interval / last_two_y.last.to_f * positive_cases_figures.last).round(2) / y_interval}")
97
+
98
+ puts 'Experimental feature, please report issues.'
99
+
100
+ AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
101
+ end
102
+ end
103
+ end
104
+ end
@@ -18,4 +18,8 @@ class String
18
18
  def paint_yellow
19
19
  Rainbow(self).yellow.bg(:black).bold
20
20
  end
21
+
22
+ def paint_highlight
23
+ Rainbow(self).underline
24
+ end
21
25
  end
@@ -70,7 +70,7 @@ module Kovid
70
70
  def by_country(country_name)
71
71
  response = fetch_country(country_name)
72
72
 
73
- if response.values.first.include?('not found')
73
+ if response.key?('message')
74
74
  not_found(country_name)
75
75
  else
76
76
  Kovid::Tablelize.country_table(response)
@@ -82,7 +82,7 @@ module Kovid
82
82
  def by_country_full(country_name)
83
83
  response = fetch_country(country_name)
84
84
 
85
- if response.values.first.include?('not found')
85
+ if response.key?('message')
86
86
  not_found(country_name)
87
87
  else
88
88
  Kovid::Tablelize.full_country_table(response)
@@ -117,10 +117,17 @@ module Kovid
117
117
  puts SERVER_DOWN
118
118
  end
119
119
 
120
- def states(list)
121
- array = fetch_states(list)
120
+ def states(states)
121
+ compared_states = fetch_compared_states(states)
122
122
 
123
- Kovid::Tablelize.compare_us_states(array)
123
+ Kovid::Tablelize.compare_us_states(compared_states)
124
+ rescue JSON::ParserError
125
+ puts SERVER_DOWN
126
+ end
127
+
128
+ def all_us_states
129
+ state_data = fetch_state_data
130
+ Kovid::Tablelize.compare_us_states(state_data)
124
131
  rescue JSON::ParserError
125
132
  puts SERVER_DOWN
126
133
  end
@@ -175,22 +182,19 @@ module Kovid
175
182
  end
176
183
 
177
184
  def fetch_countries(list)
178
- array = []
185
+ list.map do |country|
186
+ JSON.parse(Typhoeus.get(COUNTRIES_PATH + "/#{country}", cache_ttl: 900).response_body)
187
+ end.sort_by { |json| -json['cases'] }
188
+ end
179
189
 
180
- list.each do |country|
181
- array << JSON.parse(Typhoeus.get(COUNTRIES_PATH + "/#{country}", cache_ttl: 900).response_body)
182
- end
190
+ def fetch_compared_states(submitted_states)
191
+ state_data = fetch_state_data
183
192
 
184
- array = array.sort_by { |json| -json['cases'] }
193
+ state_data.select { |state| submitted_states.include?(state['state'].downcase) }
185
194
  end
186
195
 
187
- def fetch_states(list)
188
- states_json = JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
189
- states_array = []
190
-
191
- states_json.select do |state|
192
- states_array << state if list.include?(state['state'].downcase)
193
- end
196
+ def fetch_state_data
197
+ JSON.parse(Typhoeus.get(STATES_URL, cache_ttl: 900).response_body)
194
198
  end
195
199
 
196
200
  def fetch_country(country_name)
@@ -4,97 +4,17 @@ require 'terminal-table'
4
4
  require 'date'
5
5
  require 'ascii_charts'
6
6
  require_relative 'painter'
7
+ require_relative 'constants'
8
+ require_relative 'aggregators'
9
+ require_relative 'historians'
7
10
 
8
11
  module Kovid
9
12
  class Tablelize
10
- class << self
11
- CASES_DEATHS_RECOVERED = [
12
- 'Cases'.paint_white,
13
- 'Deaths'.paint_red,
14
- 'Recovered'.paint_green
15
- ].freeze
16
-
17
- CASES_DEATHS_RECOVERED_CTODAY_DTODAY = [
18
- 'Cases'.paint_white,
19
- 'Cases Today'.paint_white,
20
- 'Deaths'.paint_red,
21
- 'Deaths Today'.paint_red,
22
- 'Recovered'.paint_green
23
- ].freeze
24
-
25
- DATE_CASES_DEATHS_RECOVERED = [
26
- 'Date'.paint_white,
27
- 'Cases'.paint_white,
28
- 'Deaths'.paint_red,
29
- 'Recovered'.paint_green
30
- ].freeze
31
-
32
- CONTINENTAL_AGGREGATE_HEADINGS = [
33
- 'Cases'.paint_white,
34
- 'Cases Today'.paint_white,
35
- 'Deaths'.paint_red,
36
- 'Deaths Today'.paint_red,
37
- 'Recovered'.paint_green,
38
- 'Active'.paint_yellow,
39
- 'Critical'.paint_red
40
- ].freeze
41
-
42
- COMPARE_COUNTRY_TABLE_FULL = [
43
- 'Country'.paint_white,
44
- 'Cases'.paint_white,
45
- 'Deaths'.paint_red,
46
- 'Recovered'.paint_green,
47
- 'Cases Today'.paint_white,
48
- 'Deaths Today'.paint_red,
49
- 'Critical'.paint_yellow,
50
- 'Cases/Million'.paint_white
51
- ].freeze
52
-
53
- COMPARE_COUNTRIES_TABLE_HEADINGS = [
54
- 'Country'.paint_white,
55
- 'Cases'.paint_white,
56
- 'Cases Today'.paint_white,
57
- 'Deaths'.paint_red,
58
- 'Deaths Today'.paint_red,
59
- 'Recovered'.paint_green
60
- ].freeze
61
-
62
- FULL_COUNTRY_TABLE_HEADINGS = [
63
- 'Cases'.paint_white,
64
- 'Deaths'.paint_red,
65
- 'Recovered'.paint_green,
66
- 'Cases Today'.paint_white,
67
- 'Deaths Today'.paint_red,
68
- 'Critical'.paint_yellow,
69
- 'Cases/Million'.paint_white
70
- ].freeze
71
-
72
- COMPARE_STATES_HEADINGS = [
73
- 'State'.paint_white,
74
- 'Cases'.paint_white,
75
- 'Cases Today'.paint_white,
76
- 'Deaths'.paint_red,
77
- 'Deaths Today'.paint_red,
78
- 'Active'.paint_yellow
79
- ].freeze
80
-
81
- COMPARE_PROVINCES_HEADINGS = [
82
- 'Province'.paint_white,
83
- 'Confirmed'.paint_white,
84
- 'Deaths'.paint_red,
85
- 'Recovered'.paint_green
86
- ].freeze
87
-
88
- FOOTER_LINE = ['------------', '------------', '------------', '------------'].freeze
89
- COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
90
-
91
- RIGHT_ALIGN_COLUMNS = {
92
- compare_country_table_full: [1, 2, 3, 4, 5, 6, 7],
93
- compare_country_table: [1, 2, 3, 4, 5],
94
- compare_us_states: [1, 2, 3, 4, 5],
95
- compare_provinces: [1, 2, 3]
96
- }.freeze
13
+ extend Kovid::Constants
14
+ extend Kovid::Aggregators
15
+ extend Kovid::Historians
97
16
 
17
+ class << self
98
18
  def country_table(data)
99
19
  rows = [
100
20
  [
@@ -162,7 +82,13 @@ module Kovid
162
82
  ]
163
83
 
164
84
  rows = []
165
- rows << [state['cases'], check_if_positve(state['todayCases']), state['deaths'], check_if_positve(state['todayDeaths']), state['active']]
85
+ rows << [
86
+ comma_delimit(state['cases']),
87
+ check_if_positve(state['todayCases']),
88
+ comma_delimit(state['deaths']),
89
+ check_if_positve(state['todayDeaths']),
90
+ comma_delimit(state['active'])
91
+ ]
166
92
 
167
93
  Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
168
94
  end
@@ -211,15 +137,26 @@ module Kovid
211
137
  end
212
138
 
213
139
  def compare_us_states(data)
214
- rows = data.map do |state|
215
- [
216
- state.fetch('state').upcase,
217
- comma_delimit(state.fetch('cases')),
218
- check_if_positve(state['todayCases']),
219
- comma_delimit(state['deaths']),
220
- check_if_positve(state['todayDeaths']),
221
- comma_delimit(state.fetch('active'))
222
- ]
140
+ rows = data.map.with_index do |state, index|
141
+ if index.odd?
142
+ [
143
+ state.fetch('state').upcase,
144
+ comma_delimit(state.fetch('cases')),
145
+ check_if_positve(state['todayCases']),
146
+ comma_delimit(state['deaths']),
147
+ check_if_positve(state['todayDeaths']),
148
+ comma_delimit(state.fetch('active'))
149
+ ]
150
+ else
151
+ [
152
+ state.fetch('state').upcase.paint_highlight,
153
+ comma_delimit(state.fetch('cases')).paint_highlight,
154
+ check_if_positve(state['todayCases']).paint_highlight,
155
+ comma_delimit(state['deaths']).paint_highlight,
156
+ check_if_positve(state['todayDeaths']).paint_highlight,
157
+ comma_delimit(state.fetch('active')).paint_highlight
158
+ ]
159
+ end
223
160
  end
224
161
 
225
162
  align_columns(:compare_us_states,
@@ -255,126 +192,6 @@ module Kovid
255
192
  Terminal::Table.new(title: '🌍 Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
256
193
  end
257
194
 
258
- def history(country, last)
259
- # Write checks for when country is spelt wrong.
260
- headings = DATE_CASES_DEATHS_RECOVERED
261
- rows = []
262
-
263
- stats = if last
264
- transpose(country).last(last.to_i)
265
- else
266
- transpose(country)
267
- end
268
-
269
- dates = if last
270
- country['timeline']['cases'].keys.last(last.to_i)
271
- else
272
- country['timeline']['cases'].keys
273
- end
274
-
275
- unless last
276
- stats = stats.reject { |stat| stat[0].to_i.zero? && stat[1].to_i.zero? }
277
- dates = dates.last(stats.count)
278
- end
279
-
280
- stats.each_with_index do |val, index|
281
- val.unshift(Kovid.dateman(dates[index]))
282
- end.each do |row|
283
- rows << row
284
- end
285
-
286
- if stats.size > 10
287
- rows << FOOTER_LINE
288
- rows << DATE_CASES_DEATHS_RECOVERED
289
- end
290
-
291
- Terminal::Table.new(
292
- title: country['country'].upcase,
293
- headings: headings,
294
- rows: rows
295
- )
296
- end
297
-
298
- def histogram(country, date_string)
299
- @date = date_string.split('.')
300
-
301
- if @date.last.to_i != 20
302
- Kovid.info_table('Only 2020 histgrams are available.')
303
- return
304
- end
305
-
306
- # From dates where number of !cases.zero?
307
- positive_cases_figures = country['timeline']['cases'].values.reject(&:zero?)
308
- dates = country['timeline']['cases'].reject { |_k, v| v.zero? }.keys
309
- data = []
310
-
311
- # Improve this later, like everything else.
312
- # Returns array of days.to_i from the date param
313
- dates = dates.map do |date|
314
- date.split('/')
315
- end.select do |date|
316
- date.last == @date.last
317
- end.select do |date|
318
- date.first == @date.first
319
- end.map do |array|
320
- array[1]
321
- end.map(&:to_i).last(positive_cases_figures.count)
322
-
323
- # Arranges dates and figures in [x,y] for histogram
324
- # With x being day, y being number of cases
325
- if dates.empty?
326
- if @date.first.to_i > Time.now.month
327
- msgs = [
328
- 'Seriously...??! 😏', 'Did you just check the future??',
329
- 'You just checked the future Morgan.',
330
- 'Knowing too much of your future is never a good thing.'
331
- ]
332
-
333
- Kovid.info_table(msgs.sample)
334
- else
335
- Kovid.info_table('Check your spelling/No infections for this month.')
336
- end
337
-
338
- else
339
- dates.each_with_index do |val, index|
340
- data << [val, positive_cases_figures[index]]
341
- end
342
- y_range = AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).y_range
343
-
344
- last_two_y = y_range.last 2
345
- y_interval = last_two_y.last - last_two_y.first
346
-
347
- scale("Scale on Y: #{y_interval}:#{(y_interval / last_two_y.last.to_f * positive_cases_figures.last).round(2) / y_interval}")
348
-
349
- puts 'Experimental feature, please report issues.'
350
-
351
- AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
352
- end
353
- end
354
-
355
- def eu_aggregate(eu_data)
356
- aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, '🇪🇺')
357
- end
358
-
359
- def europe_aggregate(europe_data)
360
- aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, '🏰')
361
- end
362
-
363
- def africa_aggregate(africa_data)
364
- aggregated_table(africa_data, 'Africa',
365
- Kovid::Request::AFRICA_ISOS, '🌍')
366
- end
367
-
368
- def south_america_aggregate(south_america_data)
369
- aggregated_table(south_america_data,
370
- 'South America',
371
- Kovid::Request::SOUTH_AMERICA_ISOS, '🌎')
372
- end
373
-
374
- def asia_aggregate(asia_data)
375
- aggregated_table(asia_data, 'Asia', Kovid::Request::ASIA_ISOS, '🌏')
376
- end
377
-
378
195
  private
379
196
 
380
197
  def comma_delimit(number)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.6.0'
4
+ VERSION = '0.6.5'
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.0
4
+ version: 0.6.5
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-04-03 00:00:00.000000000 Z
11
+ date: 2020-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ascii_charts
@@ -118,9 +118,12 @@ files:
118
118
  - exe/kovid
119
119
  - kovid.gemspec
120
120
  - lib/kovid.rb
121
+ - lib/kovid/aggregators.rb
121
122
  - lib/kovid/cache.rb
122
123
  - lib/kovid/cli.rb
124
+ - lib/kovid/constants.rb
123
125
  - lib/kovid/helpers.rb
126
+ - lib/kovid/historians.rb
124
127
  - lib/kovid/painter.rb
125
128
  - lib/kovid/request.rb
126
129
  - lib/kovid/tablelize.rb