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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e95d98dc4481abd6914bab36e8eb3313acfc6332bb3f94bb53779bd99779c67
4
- data.tar.gz: 05c94ef16032c1dc71d96d216b45b6df0f7c7627926dd6d6ca093fa17779d8f0
3
+ metadata.gz: cc2e30c94c8148c8849241849c6b0340429f0a271ade0927091098972e4fc914
4
+ data.tar.gz: 54197f1917738844f1c36e3c1f513deb254d5e47ecb97e8b62db198fded53935
5
5
  SHA512:
6
- metadata.gz: b55936c92247fe5b8bb46b5638e33ee44b79ffc114f10706dd660812be61b346dce6ce9482c28b70a8277cfbce9346623e7d369f0ce78018708bd50e4e185ac1
7
- data.tar.gz: 42219acd66bb2f467173b3c9e75b946bcbc26283ce7c662fa93d9a74eec965d33a0dd66cbf0ca6f7c926dd87467315d4241f464ddcbb57a050ac34b9aad7652a
6
+ metadata.gz: 2ebeeeccb550b36ecd7376ba78894434eb2b980c2dbd57e6552e8037400694cf548926e8eea642c0929f974522220804c0a4092344f9f5122df8a5ff257a3695
7
+ data.tar.gz: 4f423a115a7c06d937960085e795bb77196f4513434951f1cdf01a3b41ad7892ea561eea73e8046a67a84ff47c4d497b530b08c607af783ddd4e421708091d18
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.4.1)
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
+ [![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.
@@ -58,10 +62,14 @@ ___
58
62
  * `kovid history COUNTRY N` (history in the last N days).
59
63
  ___
60
64
  ๐Ÿ˜ท **Total figures**
61
- * `kovid cases` (summary of reported incidents globally).
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 cases`
118
+ `kovid world`
111
119
 
112
120
  ![kovid](https://i.gyazo.com/e01f4769a2b9e31ce50cec212e55810c.png "Covid data.")
113
121
 
114
- ## Information Source
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
+ ![kovid](https://i.gyazo.com/35833cba37be8ca10830fad066b85bb3.png "Covid data.")
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(*_states)
28
- Kovid::Request.states(state)
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 '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,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)
@@ -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,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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
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 'Server overwhelmed. Try again in a moment.'
87
+ puts SERVER_DOWN
87
88
  end
88
89
 
89
90
  def cases
90
- response ||= JSON.parse(Typhoeus.get(UriBuilder.new('/all').url, cache_ttl: 900).response_body)
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 'Server overwhelmed. Try again in a moment.'
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 ||= JSON.parse(Typhoeus.get(history_path + "/#{country}", cache_ttl: 900).response_body)
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 'Server overwhelmed. Try again in a moment.'
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
@@ -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
- 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
+ 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: headings, rows: rows)
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: "๐Ÿ‡ช๐Ÿ‡บ" + 8203.chr(Encoding::UTF_8) + " Aggregated EU (27 States) Data".upcase,
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kovid
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
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.2
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-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