kovid 0.5.8 → 0.6.4

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: c9e98d79edab013cca60f87fb6d029bb52f134aabb62acca2f8e05f6ee2895aa
4
- data.tar.gz: f7b831b8a6df27d48677b3388d0384ffa1ad89ba9ea7d9b93cb28e113bcedd46
3
+ metadata.gz: e96265776776cbca749c7c1651fd462883deeeefc52150afffbd444f1752bae3
4
+ data.tar.gz: 7721bcc8cf1e5d342b8808f020515d6167a7dee2b8a1bda04d1b56d3a0fd11ab
5
5
  SHA512:
6
- metadata.gz: 36912afb5ad4c9cf3c5bc26251dfedbb1b6607cd9f8dba25d1bf659a9ae65b7b1b09334cbff4515469b493a8d05ece640908dfae3e0cc31ceaeffd5823a11274
7
- data.tar.gz: 37115e8aa26d5e35ab3063cce1437d2db20ba9339bf79fc286a20ee503334ff717927fe4a766bd1d3f2ae97d419eb802fcf4a6711dbd9b01ca199bc11ba024bf
6
+ metadata.gz: dd21b726c0a68398e565c470477da359f05e23b7b356dd95e1f18232168caa922262974db6aa5c2ddc7fc6223c6fae31ed824a8b41d61c73627d0fc5013a740e
7
+ data.tar.gz: 81a35f27819d5f6eeadb699bcc0ab9a73ab61cb8f3fb0f4d487d3fa13bbc333afb1138d99f413e6b30bab437144513a4fc461dc924f3f94dc9d9ec0c4def0445
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.5.7)
4
+ kovid (0.6.3)
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
 
data/kovid.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  spec.post_install_message = "
41
41
  ============================================================================
42
- COVID-19 has devasted the world. But while we're fighting
42
+ COVID-19 has devasted the world. While we're fighting
43
43
  with the novel coronavirus, I think stats on the issue should be
44
44
  accessible.
45
45
 
data/lib/kovid.rb CHANGED
@@ -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
data/lib/kovid/cli.rb CHANGED
@@ -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,18 @@ 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
- else
52
- puts Kovid.country_comparison(name)
53
- end
51
+ desc 'states STATE STATE', 'Returns full comparison table for the given states. Accepts multiple states.'
52
+ def states(*states)
53
+ downcased_states = states.map(&:downcase)
54
+
55
+ puts Kovid.states(downcased_states)
54
56
  data_source
55
57
  end
56
58
 
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)
59
+ desc 'states -a', 'Returns full comparison table for all US states'
60
+ method_option :all, aliases: '-a'
61
+ def states
62
+ puts Kovid.all_us_states
60
63
  data_source
61
64
  end
62
65
 
@@ -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
data/lib/kovid/painter.rb CHANGED
@@ -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
data/lib/kovid/request.rb CHANGED
@@ -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,105 +4,25 @@ 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
- 'Deaths'.paint_red,
20
- 'Recovered'.paint_green,
21
- 'Cases Today'.paint_white,
22
- 'Deaths Today'.paint_red
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
  [
101
21
  comma_delimit(data['cases']),
102
- comma_delimit(data['deaths']),
103
- comma_delimit(data['recovered']),
104
22
  check_if_positve(data['todayCases']),
105
- check_if_positve(data['todayDeaths'])
23
+ comma_delimit(data['deaths']),
24
+ check_if_positve(data['todayDeaths']),
25
+ comma_delimit(data['recovered'])
106
26
  ]
107
27
  ]
108
28
 
@@ -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)
data/lib/kovid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.5.8'
4
+ VERSION = '0.6.4'
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.5.8
4
+ version: 0.6.4
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-02 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
@@ -135,8 +138,8 @@ metadata:
135
138
  source_code_uri: https://github.com/siaw23/kovid
136
139
  changelog_uri: https://github.com/siaw23/kovid
137
140
  post_install_message: "\n ============================================================================\n
138
- \ COVID-19 has devasted the world. But while we're fighting\n with the
139
- novel coronavirus, I think stats on the issue should be\n accessible.\n\n There
141
+ \ COVID-19 has devasted the world. While we're fighting\n with the novel
142
+ coronavirus, I think stats on the issue should be\n accessible.\n\n There
140
143
  isn't much we can do now besides following procedures and hoping\n for the
141
144
  best.\n\n Stay safe!\n Emmanuel Hayford.\n https://emmanuelhayford.com\n\n
142
145
  \ PS: I'm in search of a Rails/Ruby job.\n\n You can hire me (siawmensah@gmail.com).\n