kovid 0.6.12 → 0.6.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +32 -0
- data/lib/kovid.rb +4 -0
- data/lib/kovid/cli.rb +31 -1
- data/lib/kovid/constants.rb +4 -9
- data/lib/kovid/request.rb +18 -1
- data/lib/kovid/tablelize.rb +44 -0
- data/lib/kovid/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c0bc9550073aaff0f2e6fb4a4175b4147bacf6c43d4d47d0177771845d30f01
|
4
|
+
data.tar.gz: 5e960a7772a01ad8c67c77284eaebc46cb55827522e6890f62b935b87d6e3494
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f65a6ea777bde11958ab2c3d43f73b63d83d23b18f5c21757be1e46e8ebda407b762714b32d1cab819cde75a41344735799670e41b17bd9e5a175d2e52892a0
|
7
|
+
data.tar.gz: d542e777ce15d0d0236faf62264d7fd2679b4655295e51be4871ba2f1c4990fb658f9d02fc6824357a73cb94e8cd54013b8a5106819e21ded1ad6d9c07b0dbcd
|
data/Gemfile.lock
CHANGED
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.
|
data/lib/kovid.rb
CHANGED
data/lib/kovid/cli.rb
CHANGED
@@ -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
|
data/lib/kovid/constants.rb
CHANGED
@@ -102,18 +102,13 @@ module Kovid
|
|
102
102
|
'Recovered'.paint_green
|
103
103
|
].freeze
|
104
104
|
|
105
|
-
|
106
|
-
'------------',
|
107
|
-
'------------',
|
105
|
+
FOOTER_LINE_COLUMN = [
|
108
106
|
'------------'
|
109
107
|
].freeze
|
110
108
|
|
111
|
-
|
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
|
|
data/lib/kovid/request.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/kovid/tablelize.rb
CHANGED
@@ -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
|
data/lib/kovid/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-05-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carmen
|