Module: Kovid::Historians
Constant Summary
Constants included
from AsciiCharts
AsciiCharts::VERSION
Constants included
from Constants
Constants::ADD_FOOTER_SIZE, Constants::CASES_DEATHS_RECOVERED, Constants::CASES_DEATHS_RECOVERED_CTODAY_DTODAY, Constants::COMPARE_COUNTRIES_TABLE_HEADINGS, Constants::COMPARE_COUNTRY_TABLE_FULL, Constants::COMPARE_PROVINCES_HEADINGS, Constants::COMPARE_STATES_HEADINGS, Constants::CONTINENTAL_AGGREGATE_HEADINGS, Constants::COUNTRY_LETTERS, Constants::DATE_CASES_DEATHS, Constants::DATE_CASES_DEATHS_RECOVERED, Constants::FOOTER_LINE_COLUMN, Constants::FOOTER_LINE_FOUR_COLUMNS, Constants::FOOTER_LINE_THREE_COLUMNS, Constants::FULL_COUNTRY_TABLE_HEADINGS, Constants::FULL_PROVINCE_TABLE_HEADINGS, Constants::FULL_STATE_TABLE_HEADINGS, Constants::RIGHT_ALIGN_COLUMNS, Constants::USA_ABBREVIATIONS
Instance Method Summary
collapse
Instance Method Details
#histogram(country, date_string) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/kovid/historians.rb', line 38
def histogram(country, date_string)
@date = date_string.split('.')
if @date.last.to_i != 20
Kovid.info_table('Only 2020 histgrams are available.')
return
end
country_cases = country['timeline']['cases']
positive_cases_figures = country_cases.values.reject(&:zero?)
dates = country_cases.reject { |_k, v| v.zero? }.keys
data = []
dates = dates.map do |date|
date.split('/')
end.select do |date|
date.last == @date.last
end.select do |date|
date.first == @date.first
end.map do |array|
array[1]
end.map(&:to_i).last(positive_cases_figures.count)
if dates.empty?
if @date.first.to_i > Time.now.month
msgs = [
'Seriously...??! 😏', 'Did you just check the future??',
'You just checked the future Morgan.',
'Knowing too much of your future is never a good thing.'
]
Kovid.info_table(msgs.sample)
else
Kovid.info_table('Check your spelling/No infections for this month.')
end
else
dates.each_with_index do |val, index|
data << [val, positive_cases_figures[index]]
end
y_range = Kovid::AsciiCharts::Cartesian.new(
data, bar: true, hide_zero: true
).y_range
last_two_y = y_range.last 2
y_interval = last_two_y.last - last_two_y.first
scale("Scale on Y: #{y_interval}:#{(
y_interval / last_two_y.last.to_f * positive_cases_figures.last
).round(2) / y_interval}")
puts 'Experimental feature, please report issues.'
AsciiCharts::Cartesian.new(data, bar: true, hide_zero: true).draw
end
end
|
#history(data, days) ⇒ Object
#history_us_state(data, days) ⇒ Object