kovid 0.6.12 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 26d90f05df4a479c2865ce9e3bff414453680fa72f37dd841ce149410a144bb5
4
- data.tar.gz: 8f69a755906441b1b81df5786e1594e17ee9cccd11f293f555c9c047cf470b00
3
+ metadata.gz: 4c0bc9550073aaff0f2e6fb4a4175b4147bacf6c43d4d47d0177771845d30f01
4
+ data.tar.gz: 5e960a7772a01ad8c67c77284eaebc46cb55827522e6890f62b935b87d6e3494
5
5
  SHA512:
6
- metadata.gz: baa1784856b2544065f1883f19dddb3f3b4269da62c8a727f372f41e245c6646a8221dfd187eb804fd3919effa9dc3e0a29ba39f9d838635072b463920bc7535
7
- data.tar.gz: c74e0235df9d9511d241c9d0f162a691222ce8abbad6065ffe4cf670ca5238dd7fc497306445bedebe94365f850060a37524413a8b7322fee200a20da2215ff8
6
+ metadata.gz: 7f65a6ea777bde11958ab2c3d43f73b63d83d23b18f5c21757be1e46e8ebda407b762714b32d1cab819cde75a41344735799670e41b17bd9e5a175d2e52892a0
7
+ data.tar.gz: d542e777ce15d0d0236faf62264d7fd2679b4655295e51be4871ba2f1c4990fb658f9d02fc6824357a73cb94e8cd54013b8a5106819e21ded1ad6d9c07b0dbcd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.6.11)
4
+ kovid (0.6.12)
5
5
  carmen (~> 1.1.3)
6
6
  rainbow (~> 3.0)
7
7
  terminal-table (~> 1.8)
data/README.md CHANGED
@@ -76,6 +76,12 @@ ___
76
76
  * `kovid history COUNTRY N` (history in the last N days).
77
77
  * `kovid history STATE --usa`
78
78
  ___
79
+ 😷 **Top N (by cases/deaths for countries and US States)**
80
+ * `kovid top N` (top N countries in number of cases).
81
+ * `kovid top N -d` OR `kovid top N --deaths` (top N countries in number of deaths).
82
+ * `kovid top N --states` (top N US states in number of cases).
83
+ * `kovid top N --states -d` (top N countries in number of deaths).
84
+ ___
79
85
 
80
86
  **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
81
87
 
@@ -139,6 +145,32 @@ To check for total figures:
139
145
 
140
146
  ![kovid](https://i.gyazo.com/e01f4769a2b9e31ce50cec212e55810c.png "Covid data.")
141
147
 
148
+ To fetch top 5 countries in number of cases or deaths:
149
+
150
+ `kovid top`
151
+
152
+ ![kovid](https://i.gyazo.com/79443079a6c834094fc21c90dd02b78c.png "Covid data.")
153
+
154
+ `kovid top --deaths` OR `kovid top -d`
155
+
156
+ ![kovid](https://i.gyazo.com/8136a7acc2cb67d1621b3db0df822cd5.png "Covid data.")
157
+
158
+ It is also possible to fetch top US states in number of cases or deaths:
159
+
160
+ `kovid top --states`
161
+
162
+ ![kovid](https://i.gyazo.com/7ee5a1e6affdec838783183024c4604d.png "Covid data.")
163
+
164
+ `kovid top --states --deaths` OR `kovid top --states -d`
165
+
166
+ ![kovid](https://i.gyazo.com/2c3cb7e1218deff44c9d440dab93a3b1.png "Covid data.")
167
+
168
+ To fetch more number of countries or US states you can pass N. eg:
169
+
170
+ `kovid top 10`
171
+
172
+ ![kovid](https://i.gyazo.com/64663ff25c1ff61701e84871948640f4.png "Covid data.")
173
+
142
174
  ## 👩🏾‍🔬 Experimental Feature
143
175
 
144
176
  `kovid histogram italy 3.20` tries to build a histogram on number of cases. In the example here `3.20` is date in the format of `M.YY`. If you can please play with it and report issues on how this could be improved.
@@ -79,4 +79,8 @@ module Kovid
79
79
  def histogram(country, date)
80
80
  Kovid::Request.histogram(country, date)
81
81
  end
82
+
83
+ def top(count, options = { location: :countries, incident: :cases })
84
+ Kovid::Request.top(count, options)
85
+ end
82
86
  end
@@ -133,6 +133,20 @@ module Kovid
133
133
  end
134
134
  end
135
135
 
136
+ desc 'top N',
137
+ 'Returns top N countries or states in an incident (number of cases or
138
+ deaths).'
139
+ method_option :countries
140
+ method_option :states
141
+ method_option :cases, aliases: '-c'
142
+ method_option :deaths, aliases: '-d'
143
+ def top(count = 5)
144
+ count = count.to_i
145
+ count = 5 if count.zero?
146
+ puts Kovid.top(count, prepare_top_params(options))
147
+ data_source
148
+ end
149
+
136
150
  private
137
151
 
138
152
  def fetch_country_stats(country)
@@ -147,10 +161,26 @@ module Kovid
147
161
  source = <<~TEXT
148
162
  #{Time.now}
149
163
  Sources:
164
+ * worldometers.info/coronavirus
150
165
  * Johns Hopkins University
151
- * https://www.worldometers.info/coronavirus
152
166
  TEXT
153
167
  puts source
154
168
  end
169
+
170
+ def prepare_top_params(options)
171
+ params = {
172
+ location: :countries,
173
+ incident: :cases
174
+ }
175
+
176
+ if !options[:states].nil? && options[:countries].nil?
177
+ params[:location] = :states
178
+ end
179
+
180
+ if !options[:deaths].nil? && options[:cases].nil?
181
+ params[:incident] = :deaths
182
+ end
183
+ params
184
+ end
155
185
  end
156
186
  end
@@ -102,18 +102,13 @@ module Kovid
102
102
  'Recovered'.paint_green
103
103
  ].freeze
104
104
 
105
- FOOTER_LINE_THREE_COLUMNS = [
106
- '------------',
107
- '------------',
105
+ FOOTER_LINE_COLUMN = [
108
106
  '------------'
109
107
  ].freeze
110
108
 
111
- FOOTER_LINE_FOUR_COLUMNS = [
112
- '------------',
113
- '------------',
114
- '------------',
115
- '------------'
116
- ].freeze
109
+ FOOTER_LINE_THREE_COLUMNS = FOOTER_LINE_COLUMN * 3
110
+
111
+ FOOTER_LINE_FOUR_COLUMNS = FOOTER_LINE_COLUMN * 4
117
112
 
118
113
  COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
119
114
 
@@ -223,6 +223,19 @@ module Kovid
223
223
  Kovid::Tablelize.histogram(response, date)
224
224
  end
225
225
 
226
+ def top(count, options)
227
+ response = JSON.parse(
228
+ Typhoeus.get(
229
+ top_url(options[:location]) +
230
+ "?sort=#{options[:incident]}",
231
+ cache_ttl: 900
232
+ ).response_body
233
+ )
234
+
235
+ Kovid::Tablelize.top(response.first(count),
236
+ options.merge({ count: count }))
237
+ end
238
+
226
239
  def capitalize_words(string)
227
240
  string.split.map(&:capitalize).join(' ')
228
241
  end
@@ -332,11 +345,15 @@ module Kovid
332
345
  data.inject({}) do |base, other|
333
346
  base.merge(other['timeline'][key]) do |_k, l, r|
334
347
  l ||= 0
335
- l ||= 0
348
+ r ||= 0
336
349
  l + r
337
350
  end
338
351
  end.compact
339
352
  end
353
+
354
+ def top_url(location)
355
+ location == :countries ? COUNTRIES_PATH : STATES_URL
356
+ end
340
357
  end
341
358
  end
342
359
  end
@@ -96,6 +96,22 @@ module Kovid
96
96
  )
97
97
  end
98
98
 
99
+ def top(data, options)
100
+ headings = top_heading(options)
101
+ rows = data.map { |location| top_row(location, options) }
102
+
103
+ if options[:count] > 10
104
+ rows << FOOTER_LINE_COLUMN * headings.count
105
+ rows << headings
106
+ end
107
+
108
+ Terminal::Table.new(
109
+ title: top_title(options),
110
+ headings: headings,
111
+ rows: rows
112
+ )
113
+ end
114
+
99
115
  private
100
116
 
101
117
  def country_title(data)
@@ -223,6 +239,34 @@ module Kovid
223
239
  end
224
240
  table
225
241
  end
242
+
243
+ def top_row(data, options)
244
+ if options[:location] == :countries
245
+ return [
246
+ country_title(data),
247
+ full_country_row(data)
248
+ ].flatten
249
+ end
250
+
251
+ [
252
+ data['state'].upcase,
253
+ country_row(data)
254
+ ].flatten
255
+ end
256
+
257
+ def top_heading(options)
258
+ if options[:location] == :countries
259
+ return ['Country'.paint_white] + FULL_COUNTRY_TABLE_HEADINGS
260
+ end
261
+
262
+ ['State'.paint_white] + FULL_STATE_TABLE_HEADINGS
263
+ end
264
+
265
+ def top_title(options)
266
+ incident = options[:incident].to_s
267
+ location = options[:location].to_s
268
+ "🌍 Top #{options[:count]} #{location} in #{incident}".upcase
269
+ end
226
270
  end
227
271
  end
228
272
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.6.12'
4
+ VERSION = '0.6.13'
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.12
4
+ version: 0.6.13
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-08 00:00:00.000000000 Z
11
+ date: 2020-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carmen