kovid 0.4.2 โ 0.4.3
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 +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +3 -1
- data/README.md +18 -3
- data/kovid.gemspec +2 -0
- data/lib/kovid.rb +8 -2
- data/lib/kovid/cli.rb +17 -2
- data/lib/kovid/helpers.rb +11 -0
- data/lib/kovid/request.rb +23 -15
- data/lib/kovid/tablelize.rb +78 -24
- data/lib/kovid/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc2e30c94c8148c8849241849c6b0340429f0a271ade0927091098972e4fc914
|
4
|
+
data.tar.gz: 54197f1917738844f1c36e3c1f513deb254d5e47ecb97e8b62db198fded53935
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ebeeeccb550b36ecd7376ba78894434eb2b980c2dbd57e6552e8037400694cf548926e8eea642c0929f974522220804c0a4092344f9f5122df8a5ff257a3695
|
7
|
+
data.tar.gz: 4f423a115a7c06d937960085e795bb77196f4513434951f1cdf01a3b41ad7892ea561eea73e8046a67a84ff47c4d497b530b08c607af783ddd4e421708091d18
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kovid (0.4.
|
4
|
+
kovid (0.4.2)
|
5
|
+
ascii_charts (~> 0.9.1)
|
5
6
|
rainbow (~> 3.0)
|
6
7
|
terminal-table (~> 1.8)
|
7
8
|
thor (~> 1.0)
|
@@ -10,6 +11,7 @@ PATH
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
13
|
specs:
|
14
|
+
ascii_charts (0.9.1)
|
13
15
|
diff-lcs (1.3)
|
14
16
|
docile (1.3.2)
|
15
17
|
ethon (0.12.0)
|
data/README.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
[](https://badge.fury.io/rb/kovid)
|
2
|
+
[](https://www.codetriage.com/siaw23/kovid)
|
3
|
+
|
4
|
+
|
1
5
|
# ๐ฆ Kovid
|
2
6
|
|
3
7
|
Kovid is a small CLI app to fetch data surrounding the coronavirus pandemic of 2019. I found myself checking [Wikipedia](https://en.wikipedia.org/wiki/2019%E2%80%9320_coronavirus_pandemic) constantly for information so I thought I'd build this to provide info directly in the terminal. It's where some of us spend time more.
|
@@ -58,10 +62,14 @@ ___
|
|
58
62
|
* `kovid history COUNTRY N` (history in the last N days).
|
59
63
|
___
|
60
64
|
๐ท **Total figures**
|
61
|
-
* `kovid
|
65
|
+
* `kovid world` (summary of reported incidents globally).
|
62
66
|
|
63
67
|
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
64
68
|
|
69
|
+
#### Histogram (Experimental) ๐งช
|
70
|
+
|
71
|
+
`kovid histogram COUNTRY M.YY` (draws a histogram of cases in the given month `M` and years `YY`)
|
72
|
+
|
65
73
|
#### Commands Details
|
66
74
|
To fetch basic data on a country run:
|
67
75
|
|
@@ -107,11 +115,18 @@ You can check historical statistics by running
|
|
107
115
|
|
108
116
|
To check for total figures:
|
109
117
|
|
110
|
-
`kovid
|
118
|
+
`kovid world`
|
111
119
|
|
112
120
|

|
113
121
|
|
114
|
-
##
|
122
|
+
## ๐ฉ๐พโ๐ฌ Experimental Feature
|
123
|
+
|
124
|
+
`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.
|
125
|
+
|
126
|
+

|
127
|
+
|
128
|
+
|
129
|
+
## Data Source
|
115
130
|
> [JHU CSSE GISand Data](https://gisanddata.maps.arcgis.com/apps/opsdashboard/index.html#/bda7594740fd40299423467b48e9ecf6) and https://www.worldometers.info/coronavirus/ via [NovelCOVID/API](https://github.com/novelcovid/api)
|
116
131
|
|
117
132
|
|
data/kovid.gemspec
CHANGED
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_dependency "terminal-table", "~> 1.8"
|
23
23
|
spec.add_dependency "typhoeus", "~> 1.3"
|
24
24
|
spec.add_dependency "rainbow", "~> 3.0"
|
25
|
+
spec.add_dependency "ascii_charts", "~> 0.9.1"
|
26
|
+
|
25
27
|
|
26
28
|
spec.add_development_dependency "simplecov", "~> 0.18"
|
27
29
|
|
data/lib/kovid.rb
CHANGED
@@ -4,6 +4,8 @@ require 'kovid/version'
|
|
4
4
|
require 'kovid/request'
|
5
5
|
|
6
6
|
module Kovid
|
7
|
+
require 'kovid/helpers'
|
8
|
+
|
7
9
|
class Error < StandardError; end
|
8
10
|
|
9
11
|
module_function
|
@@ -24,8 +26,8 @@ module Kovid
|
|
24
26
|
Kovid::Request.state(state)
|
25
27
|
end
|
26
28
|
|
27
|
-
def states(*
|
28
|
-
Kovid::Request.states(
|
29
|
+
def states(*states)
|
30
|
+
Kovid::Request.states(states)
|
29
31
|
end
|
30
32
|
|
31
33
|
def country_comparison(names_array)
|
@@ -43,4 +45,8 @@ module Kovid
|
|
43
45
|
def history(country, last)
|
44
46
|
Kovid::Request.history(country, last)
|
45
47
|
end
|
48
|
+
|
49
|
+
def histogram(country, date)
|
50
|
+
Kovid::Request.histogram(country, date)
|
51
|
+
end
|
46
52
|
end
|
data/lib/kovid/cli.rb
CHANGED
@@ -37,8 +37,8 @@ module Kovid
|
|
37
37
|
data_source
|
38
38
|
end
|
39
39
|
|
40
|
-
desc '
|
41
|
-
def
|
40
|
+
desc 'world', 'Returns total number of cases, deaths and recoveries.'
|
41
|
+
def world
|
42
42
|
puts Kovid.cases
|
43
43
|
data_source
|
44
44
|
end
|
@@ -59,6 +59,21 @@ module Kovid
|
|
59
59
|
data_source
|
60
60
|
end
|
61
61
|
|
62
|
+
desc 'version', 'Returns version of kovid'
|
63
|
+
def version
|
64
|
+
puts Kovid::VERSION
|
65
|
+
end
|
66
|
+
|
67
|
+
desc 'histogram', 'Returns a histogram of incidents.'
|
68
|
+
def histogram(country, date = nil)
|
69
|
+
if date.nil?
|
70
|
+
Kovid.info_table("Please add a month and year in the form 'M.YY'")
|
71
|
+
else
|
72
|
+
puts Kovid.histogram(country, date)
|
73
|
+
data_source
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
62
77
|
private
|
63
78
|
|
64
79
|
def fetch_country_stats(country)
|
data/lib/kovid/request.rb
CHANGED
@@ -10,6 +10,7 @@ module Kovid
|
|
10
10
|
COUNTRIES_PATH = UriBuilder.new('/countries').url
|
11
11
|
STATES_URL = UriBuilder.new('/states').url
|
12
12
|
EU_ISOS = %w[AT BE BG CY CZ DE DK EE ES FI FR GR HR HU IE IT LT LU LV MT NL PL PT RO SE SI SK].freeze
|
13
|
+
SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
|
13
14
|
|
14
15
|
class << self
|
15
16
|
def eu_aggregate
|
@@ -29,7 +30,7 @@ module Kovid
|
|
29
30
|
|
30
31
|
Kovid::Tablelize.eu_aggregate(eu_data)
|
31
32
|
rescue JSON::ParserError
|
32
|
-
puts
|
33
|
+
puts SERVER_DOWN
|
33
34
|
end
|
34
35
|
|
35
36
|
def by_country(country_name)
|
@@ -41,7 +42,7 @@ module Kovid
|
|
41
42
|
Kovid::Tablelize.country_table(response)
|
42
43
|
end
|
43
44
|
rescue JSON::ParserError
|
44
|
-
puts
|
45
|
+
puts SERVER_DOWN
|
45
46
|
end
|
46
47
|
|
47
48
|
def by_country_full(country_name)
|
@@ -53,7 +54,7 @@ module Kovid
|
|
53
54
|
Kovid::Tablelize.full_country_table(response)
|
54
55
|
end
|
55
56
|
rescue JSON::ParserError
|
56
|
-
puts
|
57
|
+
puts SERVER_DOWN
|
57
58
|
end
|
58
59
|
|
59
60
|
def state(state)
|
@@ -61,7 +62,7 @@ module Kovid
|
|
61
62
|
|
62
63
|
Kovid::Tablelize.full_state_table(response)
|
63
64
|
rescue JSON::ParserError
|
64
|
-
puts
|
65
|
+
puts SERVER_DOWN
|
65
66
|
end
|
66
67
|
|
67
68
|
def states(list)
|
@@ -69,38 +70,49 @@ module Kovid
|
|
69
70
|
|
70
71
|
Kovid::Tablelize.compare_us_states(array)
|
71
72
|
rescue JSON::ParserError
|
72
|
-
puts
|
73
|
+
puts SERVER_DOWN
|
73
74
|
end
|
74
75
|
|
75
76
|
def by_country_comparison(list)
|
76
77
|
array = fetch_countries(list)
|
77
78
|
Kovid::Tablelize.compare_countries_table(array)
|
78
79
|
rescue JSON::ParserError
|
79
|
-
puts
|
80
|
+
puts SERVER_DOWN
|
80
81
|
end
|
81
82
|
|
82
83
|
def by_country_comparison_full(list)
|
83
84
|
array = fetch_countries(list)
|
84
85
|
Kovid::Tablelize.compare_countries_table_full(array)
|
85
86
|
rescue JSON::ParserError
|
86
|
-
puts
|
87
|
+
puts SERVER_DOWN
|
87
88
|
end
|
88
89
|
|
89
90
|
def cases
|
90
|
-
response
|
91
|
+
response = JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
|
91
92
|
|
92
93
|
Kovid::Tablelize.cases(response)
|
93
94
|
rescue JSON::ParserError
|
94
|
-
puts
|
95
|
+
puts SERVER_DOWN
|
95
96
|
end
|
96
97
|
|
97
98
|
def history(country, last)
|
98
99
|
history_path = UriBuilder.new('/v2/historical').url
|
99
|
-
response
|
100
|
+
response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
|
100
101
|
|
101
102
|
Kovid::Tablelize.history(response, last)
|
102
103
|
rescue JSON::ParserError
|
103
|
-
puts
|
104
|
+
puts SERVER_DOWN
|
105
|
+
end
|
106
|
+
|
107
|
+
def histogram(country, date)
|
108
|
+
history_path = UriBuilder.new('/v2/historical').url
|
109
|
+
response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
|
110
|
+
|
111
|
+
Kovid::Tablelize.histogram(response, date)
|
112
|
+
end
|
113
|
+
|
114
|
+
def capitalize_words(string)
|
115
|
+
string.split.map(&:capitalize).join(' ')
|
104
116
|
end
|
105
117
|
|
106
118
|
private
|
@@ -139,10 +151,6 @@ module Kovid
|
|
139
151
|
|
140
152
|
states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
|
141
153
|
end
|
142
|
-
|
143
|
-
def capitalize_words(string)
|
144
|
-
string.split.map(&:capitalize).join(' ')
|
145
|
-
end
|
146
154
|
end
|
147
155
|
end
|
148
156
|
end
|
data/lib/kovid/tablelize.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'terminal-table'
|
4
4
|
require 'date'
|
5
5
|
require_relative 'painter'
|
6
|
+
require 'ascii_charts'
|
6
7
|
|
7
8
|
module Kovid
|
8
9
|
class Tablelize
|
@@ -37,6 +38,17 @@ module Kovid
|
|
37
38
|
'Critical'.paint_red
|
38
39
|
].freeze
|
39
40
|
|
41
|
+
COMPARE_COUNTRY_TABLE_FULL = [
|
42
|
+
'Country'.paint_white,
|
43
|
+
'Cases'.paint_white,
|
44
|
+
'Deaths'.paint_red,
|
45
|
+
'Recovered'.paint_green,
|
46
|
+
'Cases Today'.paint_white,
|
47
|
+
'Deaths Today'.paint_red,
|
48
|
+
'Critical'.paint_yellow,
|
49
|
+
'Cases/Million'.paint_white
|
50
|
+
].freeze
|
51
|
+
|
40
52
|
FOOTER_LINE = ['------------', '------------', '------------'].freeze
|
41
53
|
COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
|
42
54
|
|
@@ -137,33 +149,21 @@ module Kovid
|
|
137
149
|
end
|
138
150
|
|
139
151
|
def compare_countries_table_full(data)
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
rows = []
|
152
|
+
rows = data.map do |country|
|
153
|
+
[
|
154
|
+
country.fetch('country'),
|
155
|
+
comma_delimit(country.fetch('cases')),
|
156
|
+
comma_delimit(country.fetch('deaths')),
|
157
|
+
comma_delimit(country.fetch('recovered')),
|
158
|
+
check_if_positve(country.fetch('todayCases')),
|
159
|
+
check_if_positve(country.fetch('todayDeaths')),
|
160
|
+
comma_delimit(country.fetch('critical')),
|
161
|
+
comma_delimit(country.fetch('casesPerOneMillion'))
|
152
162
|
|
153
|
-
data.each do |country|
|
154
|
-
rows << [
|
155
|
-
country['country'],
|
156
|
-
comma_delimit(country['cases']),
|
157
|
-
comma_delimit(country['deaths']),
|
158
|
-
comma_delimit(country['recovered']),
|
159
|
-
check_if_positve(country['todayCases']),
|
160
|
-
check_if_positve(country['todayDeaths']),
|
161
|
-
comma_delimit(country['critical']),
|
162
|
-
comma_delimit(country['casesPerOneMillion'])
|
163
163
|
]
|
164
164
|
end
|
165
165
|
|
166
|
-
Terminal::Table.new(headings:
|
166
|
+
Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL, rows: rows)
|
167
167
|
end
|
168
168
|
|
169
169
|
def cases(cases)
|
@@ -219,6 +219,55 @@ module Kovid
|
|
219
219
|
)
|
220
220
|
end
|
221
221
|
|
222
|
+
def histogram(country, date_string)
|
223
|
+
@date = date_string.split('.')
|
224
|
+
|
225
|
+
if @date.last.to_i != 20
|
226
|
+
Kovid.info_table('Only 2020 histgrams are available.')
|
227
|
+
return
|
228
|
+
end
|
229
|
+
|
230
|
+
# From dates where number of !cases.zero?
|
231
|
+
positive_cases_figures = country['timeline']['cases'].values.reject!(&:zero?)
|
232
|
+
dates = country['timeline']['cases'].reject { |_k, v| v.zero? }.keys
|
233
|
+
data = []
|
234
|
+
|
235
|
+
# Improve this later, like everything else.
|
236
|
+
# Returns array of days.to_i from the date param
|
237
|
+
dates = dates.map do |date|
|
238
|
+
date.split('/')
|
239
|
+
end.select do |date|
|
240
|
+
date.last == @date.last
|
241
|
+
end.select do |date|
|
242
|
+
date.first == @date.first
|
243
|
+
end.map do |array|
|
244
|
+
array[1]
|
245
|
+
end.map(&:to_i).last(positive_cases_figures.count)
|
246
|
+
|
247
|
+
# Arranges dates and figures in [x,y] for histogram
|
248
|
+
# With x being day, y being number of cases
|
249
|
+
if dates.empty?
|
250
|
+
if @date.first.to_i > Time.now.month
|
251
|
+
Kovid.info_table('Seriously...??! ๐')
|
252
|
+
else
|
253
|
+
Kovid.info_table('No infections for this month.')
|
254
|
+
end
|
255
|
+
|
256
|
+
else
|
257
|
+
dates.each_with_index do |val, index|
|
258
|
+
data << [val, positive_cases_figures[index]]
|
259
|
+
end
|
260
|
+
y_range = AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).y_range
|
261
|
+
|
262
|
+
last_two_y = y_range.last 2
|
263
|
+
y_interval = last_two_y.last - last_two_y.first
|
264
|
+
|
265
|
+
scale("Scale on Y: #{y_interval}:#{(y_interval / last_two_y.last.to_f * positive_cases_figures.last).round(2) / y_interval}")
|
266
|
+
|
267
|
+
AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
222
271
|
def eu_aggregate(eu_data)
|
223
272
|
rows = []
|
224
273
|
rows << [
|
@@ -232,7 +281,7 @@ module Kovid
|
|
232
281
|
]
|
233
282
|
|
234
283
|
Terminal::Table.new(
|
235
|
-
title:
|
284
|
+
title: '๐ช๐บ' + 8203.chr(Encoding::UTF_8) + ' Aggregated EU (27 States) Data'.upcase,
|
236
285
|
headings: EU_AGGREGATE_HEADINGS,
|
237
286
|
rows: rows
|
238
287
|
)
|
@@ -260,6 +309,11 @@ module Kovid
|
|
260
309
|
data.map! { |number| comma_delimit(number) }
|
261
310
|
end
|
262
311
|
end
|
312
|
+
|
313
|
+
def scale(msg)
|
314
|
+
rows = [[msg]]
|
315
|
+
puts Terminal::Table.new title: 'SCALE', rows: rows
|
316
|
+
end
|
263
317
|
end
|
264
318
|
end
|
265
319
|
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.4.
|
4
|
+
version: 0.4.3
|
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-03-
|
11
|
+
date: 2020-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ascii_charts
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.9.1
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.9.1
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: simplecov
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,6 +120,7 @@ files:
|
|
106
120
|
- lib/kovid.rb
|
107
121
|
- lib/kovid/cache.rb
|
108
122
|
- lib/kovid/cli.rb
|
123
|
+
- lib/kovid/helpers.rb
|
109
124
|
- lib/kovid/painter.rb
|
110
125
|
- lib/kovid/request.rb
|
111
126
|
- lib/kovid/tablelize.rb
|