kovid 0.4.2 β 0.4.7
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 +44 -10
- data/kovid.gemspec +2 -0
- data/lib/kovid.rb +19 -2
- data/lib/kovid/cli.rb +35 -2
- data/lib/kovid/helpers.rb +11 -0
- data/lib/kovid/request.rb +68 -24
- data/lib/kovid/tablelize.rb +135 -57
- 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: cb6de6563f95f22115b3e04efc65267d59fa949a5e68dee22063c9a58438ebc0
|
|
4
|
+
data.tar.gz: 87e2bf23684c8ca538fd68ae23d77e7daeff2b3fdba7a249442628e671a69675
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff8f7e1afca67e4218d7d4491d86a34bc54cdcd49993aa515aaa0186d53a73f882ab2e6eabfcda0747ac0a0e5baefe95773982e6b786aeedb77f70f7ec696183
|
|
7
|
+
data.tar.gz: fcb797d8367ddf05ef080f3272522fd2b52761fab6a1e3b02ba8367230ff9eeb05b7f0bcbe03887a3cb6d6fdc6c10f7d7f94343a5baa329f2ea9a2956cf335fa
|
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.6)
|
|
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.
|
|
@@ -25,11 +29,26 @@ You can run `kovid --help` to see the full list of available commands.
|
|
|
25
29
|
* `kovid check COUNTRY` OR `kovid country COUNTRY`.
|
|
26
30
|
* `kovid check COUNTRY -f` OR `kovid check COUNTRY --full`.
|
|
27
31
|
|
|
32
|
+
π¦π¦π¦
|
|
33
|
+
|
|
34
|
+
You can fetch aggregated data on Africa (55 states):
|
|
35
|
+
* `kovid africa`.
|
|
36
|
+
|
|
37
|
+
π°π°π°
|
|
38
|
+
|
|
39
|
+
You can fetch aggregated Europe (all 44 countries combined) data:
|
|
40
|
+
* `kovid europe`.
|
|
41
|
+
|
|
28
42
|
πͺπΊπͺπΊπͺπΊ
|
|
29
43
|
|
|
30
44
|
You can fetch aggregated EU (all 27 countries combined) data:
|
|
31
45
|
* `kovid eu`.
|
|
32
46
|
|
|
47
|
+
πππ
|
|
48
|
+
|
|
49
|
+
You can fetch aggregated South America (all 15 countries combined) data:
|
|
50
|
+
* `kovid sa`.
|
|
51
|
+
|
|
33
52
|
πΊπΈπΊπΈπΊπΈ
|
|
34
53
|
|
|
35
54
|
You can fetch US state-specific data:
|
|
@@ -37,10 +56,8 @@ You can fetch US state-specific data:
|
|
|
37
56
|
|
|
38
57
|
##### π Upcoming Fetch Features π·ββοΈ
|
|
39
58
|
|
|
40
|
-
* `kovid europe` Aggrated stats on Europe
|
|
41
|
-
* `kovid africa` Aggrated stats on Africa
|
|
42
59
|
* `kovid asia` Aggrated stats on Asia
|
|
43
|
-
|
|
60
|
+
|
|
44
61
|
___
|
|
45
62
|
π· **Comparing**
|
|
46
63
|
* `kovid compare FOO BAR` (sorts by cases DESC).
|
|
@@ -58,28 +75,32 @@ ___
|
|
|
58
75
|
* `kovid history COUNTRY N` (history in the last N days).
|
|
59
76
|
___
|
|
60
77
|
π· **Total figures**
|
|
61
|
-
* `kovid
|
|
78
|
+
* `kovid world` (summary of reported incidents globally).
|
|
62
79
|
|
|
63
80
|
**NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
|
|
64
81
|
|
|
82
|
+
#### Histogram (Experimental) π§ͺ
|
|
83
|
+
|
|
84
|
+
`kovid histogram COUNTRY M.YY` (draws a histogram of cases in the given month `M` and years `YY`)
|
|
85
|
+
|
|
65
86
|
#### Commands Details
|
|
66
87
|
To fetch basic data on a country run:
|
|
67
88
|
|
|
68
89
|
`kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
|
|
69
90
|
|
|
70
|
-

|
|
71
92
|
|
|
72
93
|
For full table info on a country:
|
|
73
94
|
|
|
74
95
|
`kovid check italy -f` OR `kovid check italy --full`
|
|
75
96
|
|
|
76
|
-

|
|
77
98
|
|
|
78
99
|
To compare country stats:
|
|
79
100
|
|
|
80
|
-
`kovid compare germany poland`
|
|
101
|
+
`kovid compare germany poland spain`
|
|
81
102
|
|
|
82
|
-

|
|
83
104
|
|
|
84
105
|
To compare a countries stats with a full table:
|
|
85
106
|
|
|
@@ -99,6 +120,12 @@ To fetch EU data run:
|
|
|
99
120
|
|
|
100
121
|

|
|
101
122
|
|
|
123
|
+
To fetch data on Africa:
|
|
124
|
+
|
|
125
|
+
`kovid africa`
|
|
126
|
+
|
|
127
|
+

|
|
128
|
+
|
|
102
129
|
You can check historical statistics by running
|
|
103
130
|
|
|
104
131
|
`kovid history italy 7` eg:
|
|
@@ -107,11 +134,18 @@ You can check historical statistics by running
|
|
|
107
134
|
|
|
108
135
|
To check for total figures:
|
|
109
136
|
|
|
110
|
-
`kovid
|
|
137
|
+
`kovid world`
|
|
111
138
|
|
|
112
139
|

|
|
113
140
|
|
|
114
|
-
##
|
|
141
|
+
## π©πΎβπ¬ Experimental Feature
|
|
142
|
+
|
|
143
|
+
`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.
|
|
144
|
+
|
|
145
|
+

|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
## Data Source
|
|
115
149
|
> [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
150
|
|
|
117
151
|
|
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
|
|
@@ -11,6 +13,17 @@ module Kovid
|
|
|
11
13
|
def eu_aggregate
|
|
12
14
|
Kovid::Request.eu_aggregate
|
|
13
15
|
end
|
|
16
|
+
def europe_aggregate
|
|
17
|
+
Kovid::Request.europe_aggregate
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def africa_aggregate
|
|
21
|
+
Kovid::Request.africa_aggregate
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def south_america_aggregate
|
|
25
|
+
Kovid::Request.south_america_aggregate
|
|
26
|
+
end
|
|
14
27
|
|
|
15
28
|
def country(name)
|
|
16
29
|
Kovid::Request.by_country(name)
|
|
@@ -24,8 +37,8 @@ module Kovid
|
|
|
24
37
|
Kovid::Request.state(state)
|
|
25
38
|
end
|
|
26
39
|
|
|
27
|
-
def states(*
|
|
28
|
-
Kovid::Request.states(
|
|
40
|
+
def states(*states)
|
|
41
|
+
Kovid::Request.states(states)
|
|
29
42
|
end
|
|
30
43
|
|
|
31
44
|
def country_comparison(names_array)
|
|
@@ -43,4 +56,8 @@ module Kovid
|
|
|
43
56
|
def history(country, last)
|
|
44
57
|
Kovid::Request.history(country, last)
|
|
45
58
|
end
|
|
59
|
+
|
|
60
|
+
def histogram(country, date)
|
|
61
|
+
Kovid::Request.histogram(country, date)
|
|
62
|
+
end
|
|
46
63
|
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,39 @@ module Kovid
|
|
|
59
59
|
data_source
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
+
desc 'europe', 'Returns aggregated data on Europe.'
|
|
63
|
+
def europe
|
|
64
|
+
puts Kovid.europe_aggregate
|
|
65
|
+
data_source
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
desc 'africa', 'Returns aggregated data on Africa.'
|
|
69
|
+
def africa
|
|
70
|
+
puts Kovid.africa_aggregate
|
|
71
|
+
data_source
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
desc 'sa', 'Returns aggregated data on South America.'
|
|
75
|
+
def sa
|
|
76
|
+
puts Kovid.south_america_aggregate
|
|
77
|
+
data_source
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
desc 'version', 'Returns version of kovid'
|
|
81
|
+
def version
|
|
82
|
+
puts Kovid::VERSION
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
desc 'histogram', 'Returns a histogram of incidents.'
|
|
86
|
+
def histogram(country, date = nil)
|
|
87
|
+
if date.nil?
|
|
88
|
+
Kovid.info_table("Please add a month and year in the form 'M.YY'")
|
|
89
|
+
else
|
|
90
|
+
puts Kovid.histogram(country, date)
|
|
91
|
+
data_source
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
62
95
|
private
|
|
63
96
|
|
|
64
97
|
def fetch_country_stats(country)
|
data/lib/kovid/request.rb
CHANGED
|
@@ -10,26 +10,43 @@ 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
|
+
EUROPE_ISOS = EU_ISOS + %w[GB IS NO CH MC AD SM VA BA RS ME MK AL BY UA RU MD]
|
|
14
|
+
AFRICA_ISOS = %w[DZ AO BJ BW BF BI CM CV CF TD KM CD CG CI DJ EG GQ ER SZ ET GA GM GH GN GW KE LS LR LY MG MW ML MR MU MA MZ NA NE NG RW ST SN SC SL SO ZA SS SD TZ TG TN UG ZM ZW EH].freeze
|
|
15
|
+
SOUTH_AMERICA_ISOS = ["AR" "BO", "BV", "BR", "CL", "CO", "EC", "FK", "GF", "GY", "PY", "PE", "GS", "SR", "UY", "VE"]
|
|
16
|
+
|
|
17
|
+
SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
|
|
13
18
|
|
|
14
19
|
class << self
|
|
15
20
|
def eu_aggregate
|
|
16
|
-
|
|
21
|
+
eu_proc = proc do |data|
|
|
22
|
+
Kovid::Tablelize.eu_aggregate(data)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
aggregator(EU_ISOS, eu_proc)
|
|
26
|
+
end
|
|
17
27
|
|
|
18
|
-
|
|
19
|
-
|
|
28
|
+
def europe_aggregate
|
|
29
|
+
europe_proc = proc do |data|
|
|
30
|
+
Kovid::Tablelize.europe_aggregate(data)
|
|
20
31
|
end
|
|
21
32
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
left ||= 0
|
|
25
|
-
right ||= 0
|
|
33
|
+
aggregator(EUROPE_ISOS, europe_proc)
|
|
34
|
+
end
|
|
26
35
|
|
|
27
|
-
|
|
28
|
-
|
|
36
|
+
def africa_aggregate
|
|
37
|
+
africa_proc = proc do |data|
|
|
38
|
+
Kovid::Tablelize.africa_aggregate(data)
|
|
39
|
+
end
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
41
|
+
aggregator(AFRICA_ISOS, africa_proc)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def south_america_aggregate
|
|
45
|
+
south_america_proc = proc do |data|
|
|
46
|
+
Kovid::Tablelize.south_america_aggregate(data)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
aggregator(SOUTH_AMERICA_ISOS, south_america_proc)
|
|
33
50
|
end
|
|
34
51
|
|
|
35
52
|
def by_country(country_name)
|
|
@@ -41,7 +58,7 @@ module Kovid
|
|
|
41
58
|
Kovid::Tablelize.country_table(response)
|
|
42
59
|
end
|
|
43
60
|
rescue JSON::ParserError
|
|
44
|
-
puts
|
|
61
|
+
puts SERVER_DOWN
|
|
45
62
|
end
|
|
46
63
|
|
|
47
64
|
def by_country_full(country_name)
|
|
@@ -53,7 +70,7 @@ module Kovid
|
|
|
53
70
|
Kovid::Tablelize.full_country_table(response)
|
|
54
71
|
end
|
|
55
72
|
rescue JSON::ParserError
|
|
56
|
-
puts
|
|
73
|
+
puts SERVER_DOWN
|
|
57
74
|
end
|
|
58
75
|
|
|
59
76
|
def state(state)
|
|
@@ -61,7 +78,7 @@ module Kovid
|
|
|
61
78
|
|
|
62
79
|
Kovid::Tablelize.full_state_table(response)
|
|
63
80
|
rescue JSON::ParserError
|
|
64
|
-
puts
|
|
81
|
+
puts SERVER_DOWN
|
|
65
82
|
end
|
|
66
83
|
|
|
67
84
|
def states(list)
|
|
@@ -69,38 +86,49 @@ module Kovid
|
|
|
69
86
|
|
|
70
87
|
Kovid::Tablelize.compare_us_states(array)
|
|
71
88
|
rescue JSON::ParserError
|
|
72
|
-
puts
|
|
89
|
+
puts SERVER_DOWN
|
|
73
90
|
end
|
|
74
91
|
|
|
75
92
|
def by_country_comparison(list)
|
|
76
93
|
array = fetch_countries(list)
|
|
77
94
|
Kovid::Tablelize.compare_countries_table(array)
|
|
78
95
|
rescue JSON::ParserError
|
|
79
|
-
puts
|
|
96
|
+
puts SERVER_DOWN
|
|
80
97
|
end
|
|
81
98
|
|
|
82
99
|
def by_country_comparison_full(list)
|
|
83
100
|
array = fetch_countries(list)
|
|
84
101
|
Kovid::Tablelize.compare_countries_table_full(array)
|
|
85
102
|
rescue JSON::ParserError
|
|
86
|
-
puts
|
|
103
|
+
puts SERVER_DOWN
|
|
87
104
|
end
|
|
88
105
|
|
|
89
106
|
def cases
|
|
90
|
-
response
|
|
107
|
+
response = JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
|
|
91
108
|
|
|
92
109
|
Kovid::Tablelize.cases(response)
|
|
93
110
|
rescue JSON::ParserError
|
|
94
|
-
puts
|
|
111
|
+
puts SERVER_DOWN
|
|
95
112
|
end
|
|
96
113
|
|
|
97
114
|
def history(country, last)
|
|
98
115
|
history_path = UriBuilder.new('/v2/historical').url
|
|
99
|
-
response
|
|
116
|
+
response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
|
|
100
117
|
|
|
101
118
|
Kovid::Tablelize.history(response, last)
|
|
102
119
|
rescue JSON::ParserError
|
|
103
|
-
puts
|
|
120
|
+
puts SERVER_DOWN
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def histogram(country, date)
|
|
124
|
+
history_path = UriBuilder.new('/v2/historical').url
|
|
125
|
+
response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
|
|
126
|
+
|
|
127
|
+
Kovid::Tablelize.histogram(response, date)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
def capitalize_words(string)
|
|
131
|
+
string.split.map(&:capitalize).join(' ')
|
|
104
132
|
end
|
|
105
133
|
|
|
106
134
|
private
|
|
@@ -140,8 +168,24 @@ module Kovid
|
|
|
140
168
|
states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
|
|
141
169
|
end
|
|
142
170
|
|
|
143
|
-
def
|
|
144
|
-
|
|
171
|
+
def aggregator(isos, meth)
|
|
172
|
+
countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
|
|
173
|
+
|
|
174
|
+
country_array = countries_array.select do |hash|
|
|
175
|
+
isos.include?(hash['countryInfo']['iso2'])
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
head, *tail = country_array
|
|
179
|
+
data = head.merge(*tail) do |key, left, right|
|
|
180
|
+
left ||= 0
|
|
181
|
+
right ||= 0
|
|
182
|
+
|
|
183
|
+
left + right unless %w[country countryInfo].include?(key)
|
|
184
|
+
end.compact
|
|
185
|
+
|
|
186
|
+
meth === data
|
|
187
|
+
rescue JSON::ParserError
|
|
188
|
+
puts SERVER_DOWN
|
|
145
189
|
end
|
|
146
190
|
end
|
|
147
191
|
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
|
|
@@ -27,7 +28,7 @@ module Kovid
|
|
|
27
28
|
'Deaths'.paint_red
|
|
28
29
|
].freeze
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
CONTINENTAL_AGGREGATE_HEADINGS = [
|
|
31
32
|
'Cases'.paint_white,
|
|
32
33
|
'Cases Today'.paint_white,
|
|
33
34
|
'Deaths'.paint_red,
|
|
@@ -37,6 +38,26 @@ 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
|
+
|
|
52
|
+
COMPARE_COUNTRIES_TABLE_HEADINGS = [
|
|
53
|
+
'Country'.paint_white,
|
|
54
|
+
'Cases'.paint_white,
|
|
55
|
+
'Cases Today'.paint_white,
|
|
56
|
+
'Deaths'.paint_red,
|
|
57
|
+
'Deaths Today'.paint_red,
|
|
58
|
+
'Recovered'.paint_green
|
|
59
|
+
].freeze
|
|
60
|
+
|
|
40
61
|
FOOTER_LINE = ['------------', '------------', '------------'].freeze
|
|
41
62
|
COUNTRY_LETTERS = 'A'.upto('Z').with_index(127_462).to_h.freeze
|
|
42
63
|
|
|
@@ -57,8 +78,6 @@ module Kovid
|
|
|
57
78
|
else
|
|
58
79
|
Terminal::Table.new(title: data['country'].upcase, headings: headings, rows: rows)
|
|
59
80
|
end
|
|
60
|
-
# TODO: Rafactor this
|
|
61
|
-
# TODO: Fix emoji
|
|
62
81
|
end
|
|
63
82
|
|
|
64
83
|
def full_country_table(data)
|
|
@@ -111,59 +130,42 @@ module Kovid
|
|
|
111
130
|
end
|
|
112
131
|
|
|
113
132
|
def compare_countries_table(data)
|
|
114
|
-
headings = [
|
|
115
|
-
'Country'.paint_white,
|
|
116
|
-
'Cases'.paint_white,
|
|
117
|
-
'Deaths'.paint_red,
|
|
118
|
-
'Recovered'.paint_green,
|
|
119
|
-
'Cases Today'.paint_white,
|
|
120
|
-
'Deaths Today'.paint_red
|
|
121
|
-
]
|
|
122
|
-
|
|
123
133
|
rows = []
|
|
124
134
|
|
|
125
135
|
data.each do |country|
|
|
126
|
-
|
|
127
|
-
country['country'].upcase,
|
|
136
|
+
base_rows = [
|
|
128
137
|
comma_delimit(country['cases']),
|
|
129
|
-
comma_delimit(country['deaths']),
|
|
130
|
-
comma_delimit(country['recovered']),
|
|
131
138
|
check_if_positve(country['todayCases']),
|
|
132
|
-
|
|
139
|
+
comma_delimit(country['deaths']),
|
|
140
|
+
check_if_positve(country['todayDeaths']),
|
|
141
|
+
comma_delimit(country['recovered'])
|
|
133
142
|
]
|
|
143
|
+
|
|
144
|
+
rows << if iso = country['countryInfo']['iso2']
|
|
145
|
+
base_rows.unshift("#{country_emoji(iso)} #{country['country'].upcase}")
|
|
146
|
+
else
|
|
147
|
+
base_rows.unshift(country['country'].upcase.to_s)
|
|
148
|
+
end
|
|
134
149
|
end
|
|
135
150
|
|
|
136
|
-
Terminal::Table.new(headings:
|
|
151
|
+
Terminal::Table.new(headings: COMPARE_COUNTRIES_TABLE_HEADINGS, rows: rows)
|
|
137
152
|
end
|
|
138
153
|
|
|
139
154
|
def compare_countries_table_full(data)
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
rows = []
|
|
152
|
-
|
|
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'])
|
|
155
|
+
rows = data.map do |country|
|
|
156
|
+
[
|
|
157
|
+
country.fetch('country'),
|
|
158
|
+
comma_delimit(country.fetch('cases')),
|
|
159
|
+
comma_delimit(country.fetch('deaths')),
|
|
160
|
+
comma_delimit(country.fetch('recovered')),
|
|
161
|
+
check_if_positve(country.fetch('todayCases')),
|
|
162
|
+
check_if_positve(country.fetch('todayDeaths')),
|
|
163
|
+
comma_delimit(country.fetch('critical')),
|
|
164
|
+
comma_delimit(country.fetch('casesPerOneMillion'))
|
|
163
165
|
]
|
|
164
166
|
end
|
|
165
167
|
|
|
166
|
-
Terminal::Table.new(headings:
|
|
168
|
+
Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL, rows: rows)
|
|
167
169
|
end
|
|
168
170
|
|
|
169
171
|
def cases(cases)
|
|
@@ -219,23 +221,69 @@ module Kovid
|
|
|
219
221
|
)
|
|
220
222
|
end
|
|
221
223
|
|
|
224
|
+
def histogram(country, date_string)
|
|
225
|
+
@date = date_string.split('.')
|
|
226
|
+
|
|
227
|
+
if @date.last.to_i != 20
|
|
228
|
+
Kovid.info_table('Only 2020 histgrams are available.')
|
|
229
|
+
return
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# From dates where number of !cases.zero?
|
|
233
|
+
positive_cases_figures = country['timeline']['cases'].values.reject!(&:zero?)
|
|
234
|
+
dates = country['timeline']['cases'].reject { |_k, v| v.zero? }.keys
|
|
235
|
+
data = []
|
|
236
|
+
|
|
237
|
+
# Improve this later, like everything else.
|
|
238
|
+
# Returns array of days.to_i from the date param
|
|
239
|
+
dates = dates.map do |date|
|
|
240
|
+
date.split('/')
|
|
241
|
+
end.select do |date|
|
|
242
|
+
date.last == @date.last
|
|
243
|
+
end.select do |date|
|
|
244
|
+
date.first == @date.first
|
|
245
|
+
end.map do |array|
|
|
246
|
+
array[1]
|
|
247
|
+
end.map(&:to_i).last(positive_cases_figures.count)
|
|
248
|
+
|
|
249
|
+
# Arranges dates and figures in [x,y] for histogram
|
|
250
|
+
# With x being day, y being number of cases
|
|
251
|
+
if dates.empty?
|
|
252
|
+
if @date.first.to_i > Time.now.month
|
|
253
|
+
Kovid.info_table('Seriously...??! π')
|
|
254
|
+
else
|
|
255
|
+
Kovid.info_table('No infections for this month.')
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
else
|
|
259
|
+
dates.each_with_index do |val, index|
|
|
260
|
+
data << [val, positive_cases_figures[index]]
|
|
261
|
+
end
|
|
262
|
+
y_range = AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).y_range
|
|
263
|
+
|
|
264
|
+
last_two_y = y_range.last 2
|
|
265
|
+
y_interval = last_two_y.last - last_two_y.first
|
|
266
|
+
|
|
267
|
+
scale("Scale on Y: #{y_interval}:#{(y_interval / last_two_y.last.to_f * positive_cases_figures.last).round(2) / y_interval}")
|
|
268
|
+
|
|
269
|
+
AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
|
|
270
|
+
end
|
|
271
|
+
end
|
|
272
|
+
|
|
222
273
|
def eu_aggregate(eu_data)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
comma_delimit(eu_data['cases']),
|
|
226
|
-
check_if_positve(eu_data['todayCases']),
|
|
227
|
-
comma_delimit(eu_data['deaths']),
|
|
228
|
-
check_if_positve(eu_data['todayDeaths']),
|
|
229
|
-
comma_delimit(eu_data['recovered']),
|
|
230
|
-
comma_delimit(eu_data['active']),
|
|
231
|
-
comma_delimit(eu_data['critical'])
|
|
232
|
-
]
|
|
274
|
+
aggregated_table(eu_data, 'The EU', Kovid::Request::EU_ISOS, 'πͺπΊ')
|
|
275
|
+
end
|
|
233
276
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
277
|
+
def europe_aggregate(europe_data)
|
|
278
|
+
aggregated_table(europe_data, 'Europe', Kovid::Request::EUROPE_ISOS, "π°")
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
def africa_aggregate(africa_data)
|
|
282
|
+
aggregated_table(africa_data, 'Africa', Kovid::Request::AFRICA_ISOS, 'π')
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
def south_america_aggregate(south_america_data)
|
|
286
|
+
aggregated_table(south_america_data, 'South America', Kovid::Request::SOUTH_AMERICA_ISOS, "π")
|
|
239
287
|
end
|
|
240
288
|
|
|
241
289
|
private
|
|
@@ -260,6 +308,36 @@ module Kovid
|
|
|
260
308
|
data.map! { |number| comma_delimit(number) }
|
|
261
309
|
end
|
|
262
310
|
end
|
|
311
|
+
|
|
312
|
+
def scale(msg)
|
|
313
|
+
rows = [[msg]]
|
|
314
|
+
puts Terminal::Table.new title: 'SCALE', rows: rows
|
|
315
|
+
end
|
|
316
|
+
|
|
317
|
+
def aggregated_table(collated_data, continent, iso, emoji)
|
|
318
|
+
title = if emoji.codepoints.size > 1
|
|
319
|
+
emoji + 8203.chr(Encoding::UTF_8) + " Aggregated Data on #{continent} (#{iso.size} States)".upcase
|
|
320
|
+
else
|
|
321
|
+
emoji + " Aggregated Data on #{continent} (#{iso.size} States)".upcase
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
rows = []
|
|
325
|
+
rows << [
|
|
326
|
+
comma_delimit(collated_data['cases']),
|
|
327
|
+
check_if_positve(collated_data['todayCases']),
|
|
328
|
+
comma_delimit(collated_data['deaths']),
|
|
329
|
+
check_if_positve(collated_data['todayDeaths']),
|
|
330
|
+
comma_delimit(collated_data['recovered']),
|
|
331
|
+
comma_delimit(collated_data['active']),
|
|
332
|
+
comma_delimit(collated_data['critical'])
|
|
333
|
+
]
|
|
334
|
+
|
|
335
|
+
Terminal::Table.new(
|
|
336
|
+
title: title,
|
|
337
|
+
headings: CONTINENTAL_AGGREGATE_HEADINGS,
|
|
338
|
+
rows: rows
|
|
339
|
+
)
|
|
340
|
+
end
|
|
263
341
|
end
|
|
264
342
|
end
|
|
265
343
|
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.7
|
|
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
|