kovid 0.4.0 β†’ 0.4.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8606d0dc6ea79758f85aa6de7cc7eed226b2e3e91f94280dfe41b6cd0b753d4
4
- data.tar.gz: 80c17f093508af48960a0c3c2f64b325017ba8cdbe1c0ae0274ec900cc66a9c6
3
+ metadata.gz: 96bc2442058a29c4830dbebb1baedc428f220b2b20762b150fa1ccd658648d4e
4
+ data.tar.gz: 11454ce4ed1f2c48778141e886cc8f9a86d8d1a3efb66caaa302f86586a17ec1
5
5
  SHA512:
6
- metadata.gz: 9894427b48ba543c215b9f05954360c0cbc2b40fc504a67b60d712f752a73e8c414e6304199caf737b8293ec690c933833df64be5586703c59bd6035750befad
7
- data.tar.gz: 4a6d09e351aecbc174e08e150246ba59ba616cddf52743603e35fb02403729eeeb77d6a6b98e6ee88dd2945ba73aa846bace99c3123af45e97c382fb3b717be8
6
+ metadata.gz: 45f3d74148f5807f9ef03ec5a4405d9aa337ddb98e7c54e8180fab64c31ce1ff9bc92ed4840f3287514046c926d1ffb5e6982a5048a7ea16e13fe15e3b210a64
7
+ data.tar.gz: 29654bae42cd1c257b2705554e7b7effd1fdde060bbd31bf3a413a4a120f4ef6187117af84bdba6d16c19b361cfcaa02d0e8013911a8d31922c99b6f0bc427ba
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+
9
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.3.16)
4
+ kovid (0.4.4)
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
+ [![Gem Version](https://badge.fury.io/rb/kovid.svg)](https://badge.fury.io/rb/kovid)
2
+ [![Open Source Helpers](https://www.codetriage.com/siaw23/kovid/badges/users.svg)](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,6 +29,12 @@ 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:
35
+ * `kovid africa`.
36
+
37
+
28
38
  πŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡ΊπŸ‡ͺπŸ‡Ί
29
39
 
30
40
  You can fetch aggregated EU (all 27 countries combined) data:
@@ -38,7 +48,6 @@ You can fetch US state-specific data:
38
48
  ##### πŸ”œ Upcoming Fetch Features πŸ‘·β€β™€οΈ
39
49
 
40
50
  * `kovid europe` Aggrated stats on Europe
41
- * `kovid africa` Aggrated stats on Africa
42
51
  * `kovid asia` Aggrated stats on Asia
43
52
  * `kovid south_america` Aggrated stats on South America
44
53
  ___
@@ -58,28 +67,32 @@ ___
58
67
  * `kovid history COUNTRY N` (history in the last N days).
59
68
  ___
60
69
  😷 **Total figures**
61
- * `kovid cases` (summary of reported incidents globally).
70
+ * `kovid world` (summary of reported incidents globally).
62
71
 
63
72
  **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
64
73
 
74
+ #### Histogram (Experimental) πŸ§ͺ
75
+
76
+ `kovid histogram COUNTRY M.YY` (draws a histogram of cases in the given month `M` and years `YY`)
77
+
65
78
  #### Commands Details
66
79
  To fetch basic data on a country run:
67
80
 
68
81
  `kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
69
82
 
70
- ![kovid](https://i.gyazo.com/ee88b41c05da3be0295dd3a158e7ba70.png "Covid data.")
83
+ ![kovid](https://i.gyazo.com/1d86ba2cd05f215b16c8d1fd13085c6e.png "Covid data.")
71
84
 
72
85
  For full table info on a country:
73
86
 
74
87
  `kovid check italy -f` OR `kovid check italy --full`
75
88
 
76
- ![kovid](https://i.gyazo.com/7e5afce548d8a01b9bdf3f8bdb529cd1.png "Covid data.")
89
+ ![kovid](https://i.gyazo.com/1d9720b9fa2c08fb801f5361fba359bb.png "Covid data.")
77
90
 
78
91
  To compare country stats:
79
92
 
80
- `kovid compare germany poland`
93
+ `kovid compare germany poland spain`
81
94
 
82
- ![kovid](https://i.gyazo.com/876b19988da4cd7b375cde3e23376ba7.png "Covid data.")
95
+ ![kovid](https://i.gyazo.com/4100e845fea6936f5c8d21d78617110d.png "Covid data.")
83
96
 
84
97
  To compare a countries stats with a full table:
85
98
 
@@ -99,6 +112,12 @@ To fetch EU data run:
99
112
 
100
113
  ![kovid](https://i.gyazo.com/0a78afae2a5b9d2beb9f2c61dc1d3ac7.png "Covid data.")
101
114
 
115
+ To fetch data on Africa:
116
+
117
+ `kovid africa`
118
+
119
+ ![kovid](https://i.gyazo.com/bc45fa53e2ff688e8a1f759f1bd1b972.png "Covid data.")
120
+
102
121
  You can check historical statistics by running
103
122
 
104
123
  `kovid history italy 7` eg:
@@ -107,11 +126,18 @@ You can check historical statistics by running
107
126
 
108
127
  To check for total figures:
109
128
 
110
- `kovid cases`
129
+ `kovid world`
111
130
 
112
131
  ![kovid](https://i.gyazo.com/e01f4769a2b9e31ce50cec212e55810c.png "Covid data.")
113
132
 
114
- ## Information Source
133
+ ## πŸ‘©πŸΎβ€πŸ”¬ Experimental Feature
134
+
135
+ `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.
136
+
137
+ ![kovid](https://i.gyazo.com/35833cba37be8ca10830fad066b85bb3.png "Covid data.")
138
+
139
+
140
+ ## Data Source
115
141
  > [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
142
 
117
143
 
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
@@ -12,6 +14,10 @@ module Kovid
12
14
  Kovid::Request.eu_aggregate
13
15
  end
14
16
 
17
+ def africa_aggregate
18
+ Kovid::Request.africa_aggregate
19
+ end
20
+
15
21
  def country(name)
16
22
  Kovid::Request.by_country(name)
17
23
  end
@@ -24,8 +30,8 @@ module Kovid
24
30
  Kovid::Request.state(state)
25
31
  end
26
32
 
27
- def states(*_states)
28
- Kovid::Request.states(state)
33
+ def states(*states)
34
+ Kovid::Request.states(states)
29
35
  end
30
36
 
31
37
  def country_comparison(names_array)
@@ -43,4 +49,8 @@ module Kovid
43
49
  def history(country, last)
44
50
  Kovid::Request.history(country, last)
45
51
  end
52
+
53
+ def histogram(country, date)
54
+ Kovid::Request.histogram(country, date)
55
+ end
46
56
  end
data/lib/kovid/cli.rb CHANGED
@@ -37,8 +37,8 @@ module Kovid
37
37
  data_source
38
38
  end
39
39
 
40
- desc 'cases', 'Returns total number of cases, deaths and recoveries.'
41
- def cases
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,28 @@ module Kovid
59
59
  data_source
60
60
  end
61
61
 
62
+
63
+ desc 'africa', 'Returns aggregated data on Africa.'
64
+ def africa
65
+ puts Kovid.africa_aggregate
66
+ data_source
67
+ end
68
+
69
+ desc 'version', 'Returns version of kovid'
70
+ def version
71
+ puts Kovid::VERSION
72
+ end
73
+
74
+ desc 'histogram', 'Returns a histogram of incidents.'
75
+ def histogram(country, date = nil)
76
+ if date.nil?
77
+ Kovid.info_table("Please add a month and year in the form 'M.YY'")
78
+ else
79
+ puts Kovid.histogram(country, date)
80
+ data_source
81
+ end
82
+ end
83
+
62
84
  private
63
85
 
64
86
  def fetch_country_stats(country)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'terminal-table'
4
+ module Kovid
5
+ module_function
6
+
7
+ def info_table(message)
8
+ rows = [[message.to_s]]
9
+ puts Terminal::Table.new title: '❗️', rows: rows
10
+ end
11
+ end
data/lib/kovid/request.rb CHANGED
@@ -10,17 +10,19 @@ 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
+ 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
14
+ SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
13
15
 
14
16
  class << self
15
17
  def eu_aggregate
16
18
  countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
17
19
 
18
- πŸ‡ͺπŸ‡Ί = countries_array.select do |hash|
20
+ eu_array = countries_array.select do |hash|
19
21
  EU_ISOS.include?(hash['countryInfo']['iso2'])
20
22
  end
21
23
 
22
- πŸ‘€, *πŸ‘₯ = πŸ‡ͺπŸ‡Ί
23
- eu_data = πŸ‘€.merge(*πŸ‘₯) do |key, left, right|
24
+ head, *tail = eu_array
25
+ eu_data = head.merge(*tail) do |key, left, right|
24
26
  left ||= 0
25
27
  right ||= 0
26
28
 
@@ -29,7 +31,27 @@ module Kovid
29
31
 
30
32
  Kovid::Tablelize.eu_aggregate(eu_data)
31
33
  rescue JSON::ParserError
32
- puts 'Server overwhelmed. Try again in a moment.'
34
+ puts SERVER_DOWN
35
+ end
36
+
37
+ def africa_aggregate
38
+ countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
39
+
40
+ africa_arry = countries_array.select do |hash|
41
+ AFRICA_ISOS.include?(hash['countryInfo']['iso2'])
42
+ end
43
+
44
+ head, *tail = africa_arry
45
+ africa_data = head.merge(*tail) do |key, left, right|
46
+ left ||= 0
47
+ right ||= 0
48
+
49
+ left + right unless %w[country countryInfo].include?(key)
50
+ end.compact
51
+
52
+ Kovid::Tablelize.africa_aggregate(africa_data)
53
+ rescue JSON::ParserError
54
+ puts SERVER_DOWN
33
55
  end
34
56
 
35
57
  def by_country(country_name)
@@ -41,7 +63,7 @@ module Kovid
41
63
  Kovid::Tablelize.country_table(response)
42
64
  end
43
65
  rescue JSON::ParserError
44
- puts 'Server overwhelmed. Try again in a moment.'
66
+ puts SERVER_DOWN
45
67
  end
46
68
 
47
69
  def by_country_full(country_name)
@@ -53,7 +75,7 @@ module Kovid
53
75
  Kovid::Tablelize.full_country_table(response)
54
76
  end
55
77
  rescue JSON::ParserError
56
- puts 'Server overwhelmed. Try again in a moment.'
78
+ puts SERVER_DOWN
57
79
  end
58
80
 
59
81
  def state(state)
@@ -61,7 +83,7 @@ module Kovid
61
83
 
62
84
  Kovid::Tablelize.full_state_table(response)
63
85
  rescue JSON::ParserError
64
- puts 'Server overwhelmed. Try again in a moment.'
86
+ puts SERVER_DOWN
65
87
  end
66
88
 
67
89
  def states(list)
@@ -69,38 +91,49 @@ module Kovid
69
91
 
70
92
  Kovid::Tablelize.compare_us_states(array)
71
93
  rescue JSON::ParserError
72
- puts 'Server overwhelmed. Try again in a moment.'
94
+ puts SERVER_DOWN
73
95
  end
74
96
 
75
97
  def by_country_comparison(list)
76
98
  array = fetch_countries(list)
77
99
  Kovid::Tablelize.compare_countries_table(array)
78
100
  rescue JSON::ParserError
79
- puts 'Server overwhelmed. Try again in a moment.'
101
+ puts SERVER_DOWN
80
102
  end
81
103
 
82
104
  def by_country_comparison_full(list)
83
105
  array = fetch_countries(list)
84
106
  Kovid::Tablelize.compare_countries_table_full(array)
85
107
  rescue JSON::ParserError
86
- puts 'Server overwhelmed. Try again in a moment.'
108
+ puts SERVER_DOWN
87
109
  end
88
110
 
89
111
  def cases
90
- response ||= JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
112
+ response = JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
91
113
 
92
114
  Kovid::Tablelize.cases(response)
93
115
  rescue JSON::ParserError
94
- puts 'Server overwhelmed. Try again in a moment.'
116
+ puts SERVER_DOWN
95
117
  end
96
118
 
97
119
  def history(country, last)
98
120
  history_path = UriBuilder.new('/v2/historical').url
99
- response ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
121
+ response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
100
122
 
101
123
  Kovid::Tablelize.history(response, last)
102
124
  rescue JSON::ParserError
103
- puts 'Server overwhelmed. Try again in a moment.'
125
+ puts SERVER_DOWN
126
+ end
127
+
128
+ def histogram(country, date)
129
+ history_path = UriBuilder.new('/v2/historical').url
130
+ response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
131
+
132
+ Kovid::Tablelize.histogram(response, date)
133
+ end
134
+
135
+ def capitalize_words(string)
136
+ string.split.map(&:capitalize).join(' ')
104
137
  end
105
138
 
106
139
  private
@@ -139,10 +172,6 @@ module Kovid
139
172
 
140
173
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
141
174
  end
142
-
143
- def capitalize_words(string)
144
- string.split.map(&:capitalize).join(' ')
145
- end
146
175
  end
147
176
  end
148
177
  end
@@ -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
- EU_AGGREGATE_HEADINGS = [
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
 
@@ -44,9 +65,9 @@ module Kovid
44
65
  headings = CASES_DEATHS_RECOVERED_CTODAY_DTODAY
45
66
  rows = [
46
67
  [
47
- data['cases'],
48
- data['deaths'],
49
- data['recovered'],
68
+ comma_delimit(data['cases']),
69
+ comma_delimit(data['deaths']),
70
+ comma_delimit(data['recovered']),
50
71
  check_if_positve(data['todayCases']),
51
72
  check_if_positve(data['todayDeaths'])
52
73
  ]
@@ -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
- rows << [
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
- check_if_positve(country['todayDeaths'])
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: headings, rows: rows)
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
- headings = [
141
- 'Country'.paint_white,
142
- 'Cases'.paint_white,
143
- 'Deaths'.paint_red,
144
- 'Recovered'.paint_green,
145
- 'Cases Today'.paint_white,
146
- 'Deaths Today'.paint_red,
147
- 'Critical'.paint_yellow,
148
- 'Cases/Million'.paint_white
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: headings, rows: rows)
168
+ Terminal::Table.new(headings: COMPARE_COUNTRY_TABLE_FULL, rows: rows)
167
169
  end
168
170
 
169
171
  def cases(cases)
@@ -219,6 +221,55 @@ 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
274
  rows = []
224
275
  rows << [
@@ -232,8 +283,27 @@ module Kovid
232
283
  ]
233
284
 
234
285
  Terminal::Table.new(
235
- title: 'Aggregated EU (27 States) Data'.upcase,
236
- headings: EU_AGGREGATE_HEADINGS,
286
+ title: 'πŸ‡ͺπŸ‡Ί' + 8203.chr(Encoding::UTF_8) + ' Aggregated EU (27 States) Data'.upcase,
287
+ headings: CONTINENTAL_AGGREGATE_HEADINGS,
288
+ rows: rows
289
+ )
290
+ end
291
+
292
+ def africa_aggregate(africa_data)
293
+ rows = []
294
+ rows << [
295
+ comma_delimit(africa_data['cases']),
296
+ check_if_positve(africa_data['todayCases']),
297
+ comma_delimit(africa_data['deaths']),
298
+ check_if_positve(africa_data['todayDeaths']),
299
+ comma_delimit(africa_data['recovered']),
300
+ comma_delimit(africa_data['active']),
301
+ comma_delimit(africa_data['critical'])
302
+ ]
303
+
304
+ Terminal::Table.new(
305
+ title: 'Aggregated Data of Africa (55 States)'.upcase,
306
+ headings: CONTINENTAL_AGGREGATE_HEADINGS,
237
307
  rows: rows
238
308
  )
239
309
  end
@@ -260,6 +330,11 @@ module Kovid
260
330
  data.map! { |number| comma_delimit(number) }
261
331
  end
262
332
  end
333
+
334
+ def scale(msg)
335
+ rows = [[msg]]
336
+ puts Terminal::Table.new title: 'SCALE', rows: rows
337
+ end
263
338
  end
264
339
  end
265
340
  end
data/lib/kovid/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.5'
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.4.0
4
+ version: 0.4.5
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-26 00:00:00.000000000 Z
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