kovid 0.4.1 β†’ 0.4.6

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: c1fdf17c2bf3ee3d706fbc1bc7d274db81975b8114f8e2e62438c5ad46cdfa5f
4
- data.tar.gz: d1239c4af7d0a8335f896ff57030820eb44d9406c3af77c05c2bf2a3d811fe8e
3
+ metadata.gz: 851facd4cdf0be330b04c5e0f81c91d8a5c5fdaea314751540d224e108c4464d
4
+ data.tar.gz: b36ce66c70a12df6930ca30d78ccf7628b06d6a4c70563e6382a8db584d96e6a
5
5
  SHA512:
6
- metadata.gz: 5325df59747b7de0284605d0b1a7fe6dd3e3d22650a67cf6a20670bc3a952d8cf7d8bed66a3f44452084a94ddfe357e65e8bb9dd060e094e6af16b57866ecc71
7
- data.tar.gz: 91baa1b2d686736c01f847dd415182e22f1af47eb68be4a1bc04170ddc95d2d8fdcdd8183c5917ca750cd0ce9e71c436e9b27e8a952ccc981620247c46f28da0
6
+ metadata.gz: 7ef46bb27fef43b9e032dfc81cb05389b22cd199a46f5d0c354794f892552aefb9bc765cc0fde64145e75961086622e29a06de057cc6acb66c192b46c9438890
7
+ data.tar.gz: f0e2aad02999132f9505586886545116c915d98b90701b6a8f98410b0c27ca64c8990cfe841c75c2096c5023cc11bd0922eafa0ac0258f5e7de3f8e0dd31ede1
data/Gemfile CHANGED
@@ -5,3 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
+
9
+
@@ -1,7 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kovid (0.4.0)
4
+ kovid (0.4.5)
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,16 @@ 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
+ 🏰🏰🏰
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:
@@ -37,8 +51,6 @@ You can fetch US state-specific data:
37
51
 
38
52
  ##### πŸ”œ Upcoming Fetch Features πŸ‘·β€β™€οΈ
39
53
 
40
- * `kovid europe` Aggrated stats on Europe
41
- * `kovid africa` Aggrated stats on Africa
42
54
  * `kovid asia` Aggrated stats on Asia
43
55
  * `kovid south_america` Aggrated stats on South America
44
56
  ___
@@ -58,28 +70,32 @@ ___
58
70
  * `kovid history COUNTRY N` (history in the last N days).
59
71
  ___
60
72
  😷 **Total figures**
61
- * `kovid cases` (summary of reported incidents globally).
73
+ * `kovid world` (summary of reported incidents globally).
62
74
 
63
75
  **NOTE:** If you find it irritating to have to type `kovid state STATE`, `covid state STATE` works as well.
64
76
 
77
+ #### Histogram (Experimental) πŸ§ͺ
78
+
79
+ `kovid histogram COUNTRY M.YY` (draws a histogram of cases in the given month `M` and years `YY`)
80
+
65
81
  #### Commands Details
66
82
  To fetch basic data on a country run:
67
83
 
68
84
  `kovid check ghana`. If the location contains spaces: `kovid check "Diamond Princess"`
69
85
 
70
- ![kovid](https://i.gyazo.com/ee88b41c05da3be0295dd3a158e7ba70.png "Covid data.")
86
+ ![kovid](https://i.gyazo.com/1d86ba2cd05f215b16c8d1fd13085c6e.png "Covid data.")
71
87
 
72
88
  For full table info on a country:
73
89
 
74
90
  `kovid check italy -f` OR `kovid check italy --full`
75
91
 
76
- ![kovid](https://i.gyazo.com/7e5afce548d8a01b9bdf3f8bdb529cd1.png "Covid data.")
92
+ ![kovid](https://i.gyazo.com/1d9720b9fa2c08fb801f5361fba359bb.png "Covid data.")
77
93
 
78
94
  To compare country stats:
79
95
 
80
- `kovid compare germany poland`
96
+ `kovid compare germany poland spain`
81
97
 
82
- ![kovid](https://i.gyazo.com/876b19988da4cd7b375cde3e23376ba7.png "Covid data.")
98
+ ![kovid](https://i.gyazo.com/4100e845fea6936f5c8d21d78617110d.png "Covid data.")
83
99
 
84
100
  To compare a countries stats with a full table:
85
101
 
@@ -99,6 +115,12 @@ To fetch EU data run:
99
115
 
100
116
  ![kovid](https://i.gyazo.com/0a78afae2a5b9d2beb9f2c61dc1d3ac7.png "Covid data.")
101
117
 
118
+ To fetch data on Africa:
119
+
120
+ `kovid africa`
121
+
122
+ ![kovid](https://i.gyazo.com/bc45fa53e2ff688e8a1f759f1bd1b972.png "Covid data.")
123
+
102
124
  You can check historical statistics by running
103
125
 
104
126
  `kovid history italy 7` eg:
@@ -107,11 +129,18 @@ You can check historical statistics by running
107
129
 
108
130
  To check for total figures:
109
131
 
110
- `kovid cases`
132
+ `kovid world`
111
133
 
112
134
  ![kovid](https://i.gyazo.com/e01f4769a2b9e31ce50cec212e55810c.png "Covid data.")
113
135
 
114
- ## Information Source
136
+ ## πŸ‘©πŸΎβ€πŸ”¬ Experimental Feature
137
+
138
+ `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.
139
+
140
+ ![kovid](https://i.gyazo.com/35833cba37be8ca10830fad066b85bb3.png "Covid data.")
141
+
142
+
143
+ ## Data Source
115
144
  > [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
145
 
117
146
 
@@ -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
 
@@ -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,13 @@ 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
14
23
 
15
24
  def country(name)
16
25
  Kovid::Request.by_country(name)
@@ -24,8 +33,8 @@ module Kovid
24
33
  Kovid::Request.state(state)
25
34
  end
26
35
 
27
- def states(*_states)
28
- Kovid::Request.states(state)
36
+ def states(*states)
37
+ Kovid::Request.states(states)
29
38
  end
30
39
 
31
40
  def country_comparison(names_array)
@@ -43,4 +52,8 @@ module Kovid
43
52
  def history(country, last)
44
53
  Kovid::Request.history(country, last)
45
54
  end
55
+
56
+ def histogram(country, date)
57
+ Kovid::Request.histogram(country, date)
58
+ end
46
59
  end
@@ -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,33 @@ 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 'version', 'Returns version of kovid'
75
+ def version
76
+ puts Kovid::VERSION
77
+ end
78
+
79
+ desc 'histogram', 'Returns a histogram of incidents.'
80
+ def histogram(country, date = nil)
81
+ if date.nil?
82
+ Kovid.info_table("Please add a month and year in the form 'M.YY'")
83
+ else
84
+ puts Kovid.histogram(country, date)
85
+ data_source
86
+ end
87
+ end
88
+
62
89
  private
63
90
 
64
91
  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
@@ -10,26 +10,34 @@ 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
+
16
+ SERVER_DOWN = 'Server overwhelmed. Please try again in a moment.'
13
17
 
14
18
  class << self
15
19
  def eu_aggregate
16
- countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
20
+ eu_proc = proc do |data|
21
+ Kovid::Tablelize.eu_aggregate(data)
22
+ end
23
+
24
+ aggregator(EU_ISOS, eu_proc)
25
+ end
17
26
 
18
- πŸ‡ͺπŸ‡Ί = countries_array.select do |hash|
19
- EU_ISOS.include?(hash['countryInfo']['iso2'])
27
+ def europe_aggregate
28
+ europe_proc = proc do |data|
29
+ Kovid::Tablelize.europe_aggregate(data)
20
30
  end
21
31
 
22
- πŸ‘€, *πŸ‘₯ = πŸ‡ͺπŸ‡Ί
23
- eu_data = πŸ‘€.merge(*πŸ‘₯) do |key, left, right|
24
- left ||= 0
25
- right ||= 0
32
+ aggregator(EUROPE_ISOS, europe_proc)
33
+ end
26
34
 
27
- left + right unless %w[country countryInfo].include?(key)
28
- end.compact
35
+ def africa_aggregate
36
+ africa_proc = proc do |data|
37
+ Kovid::Tablelize.africa_aggregate(data)
38
+ end
29
39
 
30
- Kovid::Tablelize.eu_aggregate(eu_data)
31
- rescue JSON::ParserError
32
- puts 'Server overwhelmed. Try again in a moment.'
40
+ aggregator(AFRICA_ISOS, africa_proc)
33
41
  end
34
42
 
35
43
  def by_country(country_name)
@@ -41,7 +49,7 @@ module Kovid
41
49
  Kovid::Tablelize.country_table(response)
42
50
  end
43
51
  rescue JSON::ParserError
44
- puts 'Server overwhelmed. Try again in a moment.'
52
+ puts SERVER_DOWN
45
53
  end
46
54
 
47
55
  def by_country_full(country_name)
@@ -53,7 +61,7 @@ module Kovid
53
61
  Kovid::Tablelize.full_country_table(response)
54
62
  end
55
63
  rescue JSON::ParserError
56
- puts 'Server overwhelmed. Try again in a moment.'
64
+ puts SERVER_DOWN
57
65
  end
58
66
 
59
67
  def state(state)
@@ -61,7 +69,7 @@ module Kovid
61
69
 
62
70
  Kovid::Tablelize.full_state_table(response)
63
71
  rescue JSON::ParserError
64
- puts 'Server overwhelmed. Try again in a moment.'
72
+ puts SERVER_DOWN
65
73
  end
66
74
 
67
75
  def states(list)
@@ -69,38 +77,49 @@ module Kovid
69
77
 
70
78
  Kovid::Tablelize.compare_us_states(array)
71
79
  rescue JSON::ParserError
72
- puts 'Server overwhelmed. Try again in a moment.'
80
+ puts SERVER_DOWN
73
81
  end
74
82
 
75
83
  def by_country_comparison(list)
76
84
  array = fetch_countries(list)
77
85
  Kovid::Tablelize.compare_countries_table(array)
78
86
  rescue JSON::ParserError
79
- puts 'Server overwhelmed. Try again in a moment.'
87
+ puts SERVER_DOWN
80
88
  end
81
89
 
82
90
  def by_country_comparison_full(list)
83
91
  array = fetch_countries(list)
84
92
  Kovid::Tablelize.compare_countries_table_full(array)
85
93
  rescue JSON::ParserError
86
- puts 'Server overwhelmed. Try again in a moment.'
94
+ puts SERVER_DOWN
87
95
  end
88
96
 
89
97
  def cases
90
- response ||= JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
98
+ response = JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
91
99
 
92
100
  Kovid::Tablelize.cases(response)
93
101
  rescue JSON::ParserError
94
- puts 'Server overwhelmed. Try again in a moment.'
102
+ puts SERVER_DOWN
95
103
  end
96
104
 
97
105
  def history(country, last)
98
106
  history_path = UriBuilder.new('/v2/historical').url
99
- response ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
107
+ response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
100
108
 
101
109
  Kovid::Tablelize.history(response, last)
102
110
  rescue JSON::ParserError
103
- puts 'Server overwhelmed. Try again in a moment.'
111
+ puts SERVER_DOWN
112
+ end
113
+
114
+ def histogram(country, date)
115
+ history_path = UriBuilder.new('/v2/historical').url
116
+ response = JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
117
+
118
+ Kovid::Tablelize.histogram(response, date)
119
+ end
120
+
121
+ def capitalize_words(string)
122
+ string.split.map(&:capitalize).join(' ')
104
123
  end
105
124
 
106
125
  private
@@ -140,8 +159,25 @@ module Kovid
140
159
  states_array.select { |state_name| state_name['state'] == capitalize_words(state) }.first
141
160
  end
142
161
 
143
- def capitalize_words(string)
144
- string.split.map(&:capitalize).join(' ')
162
+ def aggregator(isos, meth)
163
+ countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body)
164
+
165
+ country_array = countries_array.select do |hash|
166
+ isos.include?(hash['countryInfo']['iso2'])
167
+ end
168
+
169
+ head, *tail = country_array
170
+ data = head.merge(*tail) do |key, left, right|
171
+ left ||= 0
172
+ right ||= 0
173
+
174
+ left + right unless %w[country countryInfo].include?(key)
175
+ end.compact
176
+
177
+ # Kovid::Tablelize.eu_aggregate(data)
178
+ meth.call(data)
179
+ rescue JSON::ParserError
180
+ puts SERVER_DOWN
145
181
  end
146
182
  end
147
183
  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,23 +221,65 @@ 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
- rows = []
224
- rows << [
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
- Terminal::Table.new(
235
- title: "πŸ‡ͺπŸ‡Ί" + 8203.chr(Encoding::UTF_8) + " Aggregated EU (27 States) Data".upcase,
236
- headings: EU_AGGREGATE_HEADINGS,
237
- rows: rows
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, '🌍')
239
283
  end
240
284
 
241
285
  private
@@ -260,6 +304,36 @@ module Kovid
260
304
  data.map! { |number| comma_delimit(number) }
261
305
  end
262
306
  end
307
+
308
+ def scale(msg)
309
+ rows = [[msg]]
310
+ puts Terminal::Table.new title: 'SCALE', rows: rows
311
+ end
312
+
313
+ def aggregated_table(collated_data, continent, iso, emoji)
314
+ title = if emoji.codepoints.size > 1
315
+ emoji + 8203.chr(Encoding::UTF_8) + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
316
+ else
317
+ emoji + " Aggregated Data of #{continent} (#{iso.size} States)".upcase
318
+ end
319
+
320
+ rows = []
321
+ rows << [
322
+ comma_delimit(collated_data['cases']),
323
+ check_if_positve(collated_data['todayCases']),
324
+ comma_delimit(collated_data['deaths']),
325
+ check_if_positve(collated_data['todayDeaths']),
326
+ comma_delimit(collated_data['recovered']),
327
+ comma_delimit(collated_data['active']),
328
+ comma_delimit(collated_data['critical'])
329
+ ]
330
+
331
+ Terminal::Table.new(
332
+ title: title,
333
+ headings: CONTINENTAL_AGGREGATE_HEADINGS,
334
+ rows: rows
335
+ )
336
+ end
263
337
  end
264
338
  end
265
339
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.4.1'
4
+ VERSION = '0.4.6'
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.1
4
+ version: 0.4.6
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-27 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