kovid 0.6.4 → 0.6.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +59 -0
- data/Gemfile.lock +18 -3
- data/README.md +4 -1
- data/Rakefile +1 -0
- data/kovid.gemspec +10 -6
- data/lib/kovid.rb +6 -4
- data/lib/kovid/ascii_charts.rb +276 -0
- data/lib/kovid/cache.rb +0 -1
- data/lib/kovid/cli.rb +29 -20
- data/lib/kovid/constants.rb +33 -1
- data/lib/kovid/helpers.rb +22 -0
- data/lib/kovid/historians.rb +29 -23
- data/lib/kovid/painter.rb +0 -1
- data/lib/kovid/request.rb +125 -33
- data/lib/kovid/tablelize.rb +126 -160
- data/lib/kovid/version.rb +1 -1
- metadata +8 -5
data/lib/kovid/tablelize.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'terminal-table'
|
4
4
|
require 'date'
|
5
|
-
|
5
|
+
require_relative 'ascii_charts'
|
6
6
|
require_relative 'painter'
|
7
7
|
require_relative 'constants'
|
8
8
|
require_relative 'aggregators'
|
@@ -16,120 +16,50 @@ module Kovid
|
|
16
16
|
|
17
17
|
class << self
|
18
18
|
def country_table(data)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
check_if_positve(data['todayCases']),
|
23
|
-
comma_delimit(data['deaths']),
|
24
|
-
check_if_positve(data['todayDeaths']),
|
25
|
-
comma_delimit(data['recovered'])
|
26
|
-
]
|
27
|
-
]
|
28
|
-
|
29
|
-
if (iso = data['countryInfo']['iso2'])
|
30
|
-
Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
|
31
|
-
headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
|
32
|
-
rows: rows)
|
33
|
-
else
|
34
|
-
Terminal::Table.new(title: data['country'].upcase,
|
35
|
-
headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
|
36
|
-
rows: rows)
|
37
|
-
end
|
19
|
+
Terminal::Table.new(title: country_title(data),
|
20
|
+
headings: CASES_DEATHS_RECOVERED_CTODAY_DTODAY,
|
21
|
+
rows: [country_row(data)])
|
38
22
|
end
|
39
23
|
|
40
24
|
def full_country_table(data)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
comma_delimit(data['deaths']),
|
45
|
-
comma_delimit(data['recovered']),
|
46
|
-
check_if_positve(data['todayCases']),
|
47
|
-
check_if_positve(data['todayDeaths']),
|
48
|
-
comma_delimit(data['critical']),
|
49
|
-
comma_delimit(data['casesPerOneMillion'])
|
50
|
-
]
|
51
|
-
|
52
|
-
if iso = data['countryInfo']['iso2']
|
53
|
-
Terminal::Table.new(title: "#{country_emoji(iso)} #{data['country'].upcase}",
|
54
|
-
headings: FULL_COUNTRY_TABLE_HEADINGS,
|
55
|
-
rows: rows)
|
56
|
-
else
|
57
|
-
Terminal::Table.new(title: data['country'].upcase,
|
58
|
-
headings: FULL_COUNTRY_TABLE_HEADINGS,
|
59
|
-
rows: rows)
|
60
|
-
end
|
25
|
+
Terminal::Table.new(title: country_title(data),
|
26
|
+
headings: FULL_COUNTRY_TABLE_HEADINGS,
|
27
|
+
rows: [full_country_row(data)])
|
61
28
|
end
|
62
29
|
|
63
30
|
def full_province_table(province)
|
64
|
-
|
65
|
-
'
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
rows = []
|
70
|
-
rows << [province['stats']['confirmed'], province['stats']['deaths'], province['stats']['recovered']]
|
71
|
-
|
72
|
-
Terminal::Table.new(title: province['province'].upcase, headings: headings, rows: rows)
|
31
|
+
Terminal::Table.new(
|
32
|
+
title: province['province'].upcase,
|
33
|
+
headings: FULL_PROVINCE_TABLE_HEADINGS,
|
34
|
+
rows: [province_row(province)]
|
35
|
+
)
|
73
36
|
end
|
74
37
|
|
75
38
|
def full_state_table(state)
|
76
|
-
|
77
|
-
'
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
'Active'.paint_yellow
|
82
|
-
]
|
83
|
-
|
84
|
-
rows = []
|
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
|
-
]
|
92
|
-
|
93
|
-
Terminal::Table.new(title: state['state'].upcase, headings: headings, rows: rows)
|
39
|
+
Terminal::Table.new(
|
40
|
+
title: state['state'].upcase,
|
41
|
+
headings: FULL_STATE_TABLE_HEADINGS,
|
42
|
+
rows: [country_row(state)]
|
43
|
+
)
|
94
44
|
end
|
95
45
|
|
96
46
|
def compare_countries_table(data)
|
97
47
|
rows = []
|
98
48
|
|
99
49
|
data.each do |country|
|
100
|
-
base_rows =
|
101
|
-
|
102
|
-
check_if_positve(country['todayCases']),
|
103
|
-
comma_delimit(country['deaths']),
|
104
|
-
check_if_positve(country['todayDeaths']),
|
105
|
-
comma_delimit(country['recovered'])
|
106
|
-
]
|
107
|
-
|
108
|
-
rows << if (iso = country['countryInfo']['iso2'])
|
109
|
-
base_rows.unshift("#{country_emoji(iso)} #{country['country'].upcase}")
|
110
|
-
else
|
111
|
-
base_rows.unshift(country['country'].upcase.to_s)
|
112
|
-
end
|
50
|
+
base_rows = country_row(country)
|
51
|
+
rows << base_rows.unshift(country_title(country))
|
113
52
|
end
|
114
53
|
|
115
54
|
align_columns(:compare_country_table,
|
116
|
-
Terminal::Table.new(
|
117
|
-
|
55
|
+
Terminal::Table.new(
|
56
|
+
headings: COMPARE_COUNTRIES_TABLE_HEADINGS,
|
57
|
+
rows: rows
|
58
|
+
))
|
118
59
|
end
|
119
60
|
|
120
61
|
def compare_countries_table_full(data)
|
121
|
-
rows = data.map
|
122
|
-
[
|
123
|
-
country.fetch('country'),
|
124
|
-
comma_delimit(country.fetch('cases')),
|
125
|
-
comma_delimit(country.fetch('deaths')),
|
126
|
-
comma_delimit(country.fetch('recovered')),
|
127
|
-
check_if_positve(country.fetch('todayCases')),
|
128
|
-
check_if_positve(country.fetch('todayDeaths')),
|
129
|
-
comma_delimit(country.fetch('critical')),
|
130
|
-
comma_delimit(country.fetch('casesPerOneMillion'))
|
131
|
-
]
|
132
|
-
end
|
62
|
+
rows = data.map { |country| compare_countries_full_row(country) }
|
133
63
|
|
134
64
|
align_columns(:compare_country_table_full,
|
135
65
|
Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL,
|
@@ -139,23 +69,9 @@ module Kovid
|
|
139
69
|
def compare_us_states(data)
|
140
70
|
rows = data.map.with_index do |state, index|
|
141
71
|
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
|
-
]
|
72
|
+
us_state_row(state)
|
150
73
|
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
|
-
]
|
74
|
+
us_state_row(state).map(&:paint_highlight)
|
159
75
|
end
|
160
76
|
end
|
161
77
|
|
@@ -165,14 +81,7 @@ module Kovid
|
|
165
81
|
end
|
166
82
|
|
167
83
|
def compare_provinces(data)
|
168
|
-
rows = data.map
|
169
|
-
[
|
170
|
-
province['province'].upcase,
|
171
|
-
province['stats']['confirmed'],
|
172
|
-
province['stats']['deaths'],
|
173
|
-
province['stats']['recovered']
|
174
|
-
]
|
175
|
-
end
|
84
|
+
rows = data.map { |province| compare_provinces_row(province) }
|
176
85
|
|
177
86
|
align_columns(:compare_provinces,
|
178
87
|
Terminal::Table.new(headings: COMPARE_PROVINCES_HEADINGS,
|
@@ -180,29 +89,22 @@ module Kovid
|
|
180
89
|
end
|
181
90
|
|
182
91
|
def cases(cases)
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
comma_delimit(cases['recovered'])
|
189
|
-
]
|
190
|
-
]
|
191
|
-
|
192
|
-
Terminal::Table.new(title: '🌍 Total Number of Incidents Worldwide'.upcase, headings: headings, rows: rows)
|
92
|
+
Terminal::Table.new(
|
93
|
+
title: '🌍 Total Number of Incidents Worldwide'.upcase,
|
94
|
+
headings: CASES_DEATHS_RECOVERED,
|
95
|
+
rows: [cases_row(cases)]
|
96
|
+
)
|
193
97
|
end
|
194
98
|
|
195
99
|
private
|
196
100
|
|
197
|
-
def
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
def check_if_positve(num)
|
205
|
-
num.to_i.positive? ? "+#{comma_delimit(num)}" : comma_delimit(num).to_s
|
101
|
+
def country_title(data)
|
102
|
+
iso = data['countryInfo']['iso2']
|
103
|
+
if iso.nil?
|
104
|
+
data['country'].upcase
|
105
|
+
else
|
106
|
+
"#{country_emoji(iso)} #{data['country'].upcase}"
|
107
|
+
end
|
206
108
|
end
|
207
109
|
|
208
110
|
def country_emoji(iso)
|
@@ -210,10 +112,80 @@ module Kovid
|
|
210
112
|
8203.chr(Encoding::UTF_8)
|
211
113
|
end
|
212
114
|
|
213
|
-
def
|
214
|
-
|
215
|
-
|
216
|
-
|
115
|
+
def cases_row(data)
|
116
|
+
[
|
117
|
+
Kovid.comma_delimit(data['cases']),
|
118
|
+
Kovid.comma_delimit(data['deaths']),
|
119
|
+
Kovid.comma_delimit(data['recovered'])
|
120
|
+
]
|
121
|
+
end
|
122
|
+
|
123
|
+
# Also works for state
|
124
|
+
def country_row(data)
|
125
|
+
[
|
126
|
+
Kovid.comma_delimit(data['cases']),
|
127
|
+
Kovid.add_plus_sign(data['todayCases']),
|
128
|
+
Kovid.comma_delimit(data['deaths']),
|
129
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
130
|
+
Kovid.comma_delimit(data['recovered'])
|
131
|
+
]
|
132
|
+
end
|
133
|
+
|
134
|
+
def full_country_row(data)
|
135
|
+
[
|
136
|
+
Kovid.comma_delimit(data['cases']),
|
137
|
+
Kovid.comma_delimit(data['deaths']),
|
138
|
+
Kovid.comma_delimit(data['recovered']),
|
139
|
+
Kovid.add_plus_sign(data['todayCases']),
|
140
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
141
|
+
Kovid.comma_delimit(data['critical']),
|
142
|
+
Kovid.comma_delimit(data['casesPerOneMillion'])
|
143
|
+
]
|
144
|
+
end
|
145
|
+
|
146
|
+
def province_row(data)
|
147
|
+
[
|
148
|
+
data['stats']['confirmed'],
|
149
|
+
data['stats']['deaths'],
|
150
|
+
data['stats']['recovered']
|
151
|
+
]
|
152
|
+
end
|
153
|
+
|
154
|
+
def compare_provinces_row(data)
|
155
|
+
[
|
156
|
+
data['province'].upcase,
|
157
|
+
province_row(data)
|
158
|
+
].flatten
|
159
|
+
end
|
160
|
+
|
161
|
+
def compare_countries_full_row(data)
|
162
|
+
[
|
163
|
+
data.fetch('country'),
|
164
|
+
full_country_row(data)
|
165
|
+
].flatten
|
166
|
+
end
|
167
|
+
|
168
|
+
def us_state_row(data)
|
169
|
+
[
|
170
|
+
data.fetch('state').upcase,
|
171
|
+
Kovid.comma_delimit(data.fetch('cases')),
|
172
|
+
Kovid.add_plus_sign(data['todayCases']),
|
173
|
+
Kovid.comma_delimit(data['deaths']),
|
174
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
175
|
+
Kovid.comma_delimit(data.fetch('active'))
|
176
|
+
]
|
177
|
+
end
|
178
|
+
|
179
|
+
def aggregated_row(data)
|
180
|
+
[
|
181
|
+
Kovid.comma_delimit(data['cases']),
|
182
|
+
Kovid.add_plus_sign(data['todayCases']),
|
183
|
+
Kovid.comma_delimit(data['deaths']),
|
184
|
+
Kovid.add_plus_sign(data['todayDeaths']),
|
185
|
+
Kovid.comma_delimit(data['recovered']),
|
186
|
+
Kovid.comma_delimit(data['active']),
|
187
|
+
Kovid.comma_delimit(data['critical'])
|
188
|
+
]
|
217
189
|
end
|
218
190
|
|
219
191
|
def scale(msg)
|
@@ -222,32 +194,26 @@ module Kovid
|
|
222
194
|
end
|
223
195
|
|
224
196
|
def aggregated_table(collated_data, continent, iso, emoji)
|
225
|
-
title =
|
226
|
-
emoji + 8203.chr(Encoding::UTF_8) + \
|
227
|
-
" Aggregated Data on #{continent} (#{iso.size} States)".upcase
|
228
|
-
else
|
229
|
-
emoji + \
|
230
|
-
" Aggregated Data on #{continent} (#{iso.size} States)".upcase
|
231
|
-
end
|
232
|
-
|
233
|
-
rows = []
|
234
|
-
rows << [
|
235
|
-
comma_delimit(collated_data['cases']),
|
236
|
-
check_if_positve(collated_data['todayCases']),
|
237
|
-
comma_delimit(collated_data['deaths']),
|
238
|
-
check_if_positve(collated_data['todayDeaths']),
|
239
|
-
comma_delimit(collated_data['recovered']),
|
240
|
-
comma_delimit(collated_data['active']),
|
241
|
-
comma_delimit(collated_data['critical'])
|
242
|
-
]
|
197
|
+
title = aggregated_table_title(continent, iso, emoji)
|
243
198
|
|
244
199
|
Terminal::Table.new(
|
245
200
|
title: title,
|
246
201
|
headings: CONTINENTAL_AGGREGATE_HEADINGS,
|
247
|
-
rows:
|
202
|
+
rows: [aggregated_row(collated_data)]
|
248
203
|
)
|
249
204
|
end
|
250
205
|
|
206
|
+
def aggregated_table_title(continent, iso, emoji)
|
207
|
+
aggregated_data_continent = ' Aggregated Data on ' \
|
208
|
+
"#{continent} (#{iso.size} States)".upcase
|
209
|
+
|
210
|
+
if emoji.codepoints.size > 1
|
211
|
+
emoji + 8203.chr(Encoding::UTF_8) + aggregated_data_continent
|
212
|
+
else
|
213
|
+
emoji + aggregated_data_continent
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
251
217
|
def align_columns(table_type, table)
|
252
218
|
return table unless RIGHT_ALIGN_COLUMNS[table_type]
|
253
219
|
|
data/lib/kovid/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
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.9
|
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-
|
11
|
+
date: 2020-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: carmen
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rainbow
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -105,6 +105,8 @@ extra_rdoc_files: []
|
|
105
105
|
files:
|
106
106
|
- ".gitignore"
|
107
107
|
- ".rspec"
|
108
|
+
- ".rubocop.yml"
|
109
|
+
- ".rubocop_todo.yml"
|
108
110
|
- ".travis.yml"
|
109
111
|
- CODE_OF_CONDUCT.md
|
110
112
|
- Gemfile
|
@@ -119,6 +121,7 @@ files:
|
|
119
121
|
- kovid.gemspec
|
120
122
|
- lib/kovid.rb
|
121
123
|
- lib/kovid/aggregators.rb
|
124
|
+
- lib/kovid/ascii_charts.rb
|
122
125
|
- lib/kovid/cache.rb
|
123
126
|
- lib/kovid/cli.rb
|
124
127
|
- lib/kovid/constants.rb
|