Class: Roebe::CovidLethality

Inherits:
Base show all
Defined in:
lib/roebe/classes/covid_lethality.rb

Overview

Roebe::CovidLethality

Constant Summary collapse

FILE_N_PEOPLE_IN_THESE_COUNTRIES =
#

FILE_N_PEOPLE_IN_THESE_COUNTRIES

bl $ROEBE/yaml/n_people_in_these_countries.yml
#
"#{Roebe::PROJECT_BASE_DIRECTORY}yaml/n_people_in_these_countries.yml"

Constants inherited from Base

Base::COLOURS, Base::HOME_DIRECTORY_OF_USER_X, Base::N, Base::NAMESPACE

Instance Method Summary collapse

Methods inherited from Base

#actions, #append_this_onto_that_file, #append_what_into, #be_silent, #be_verbose?, #beautiful_url, #burlywood, #call_next, #chdir, #cheerful_guy, #cliner, #complex_esystem, #convert_global_env, #copy_directory, #copy_file, #cornflowerblue, #create_directory, #crimson, #current_month?, #current_time?, #current_year?, #cyan, #darkcyan, #darkgreen, #darkkhaki, #darkslateblue, #deeppink, #delete_symlink, #do_not_use_the_base_colours, #do_use_the_base_colours, #e, #ecomment, #editor_to_use?, #efancy, #eimp, #emphasis, #ensure_main_encoding, #ensure_utf_encoding, #eparse, #erev, #esteelblue, #etomato, #ewarn, #firebrick, #get_current_day, #get_current_month, #get_files_and_directories, #get_files_from, #get_german_name_for_this_weekday, #gold, #green, #grey, #hh_mm_ss, #hh_mm_ss_day_month_year, #home_dir?, #home_directory_of_user_x?, #infer_the_namespace, #internal_hash?, #is_a_directory?, #is_a_file?, #is_a_jpg_file?, #is_an_image_file?, #is_archive?, #is_audio_file?, #is_in_studium_dir?, #is_multimedia_file?, #is_on_roebe?, #is_on_windows?, #is_studium_available?, #is_symlink?, #is_this_a_ruby_file?, #is_video_file?, #iso_encoding?, #le, #left_colour, #lightblue, #lightgreen, #lightseagreen, #lightsteelblue, #lime, #limegreen, #localhost_to_data, #log_directory?, #main_encoding?, #mediumorchid, #mediumpurple, #mediumseagreen, #mediumslateblue, #mediumspringgreen, #mediumturquoise, #mkdir_p, #mv, #n_days_in_this_month, #n_pages_in_this_pdf_file?, #namespace?, #no_file_exists_at, #olivedrab, #open_in_browser, #opne, #opnesystem, #opnn, #orange, #orchid, #palegoldenrod, #palevioletred, #pink, #powderblue, #programs_dir?, #project_base_dir?, #random_html_colour, #rds, #read_file_in_iso_encoding, #read_file_via_the_default_encoding, #read_lines_via_iso_encoding, #readlines_with_main_encoding, #red, #register_sigint, #remove, #remove_directory, #remove_file, #rename_kde_konsole_tab, #replace_localhost_with_data, #report_pwd, #require_rescue, #reset_the_internal_hash, #return_all_directories_from_this_directory, #return_all_files_from_this_directory, #return_current_directory, #return_dd_mm_yyyy, #return_file_or_directory_of, #return_files_from_pwd, #return_last_part_of_the_current_directory, #return_utc, #rev, #right_arrow?, #right_colour, #roebe_log_directory?, #rosybrown, #royalblue, #ruby_base_directory?, #run_in_background, #run_rcfiles_then_run_ata_via_qdbus, #sandybrown, #sdir, #seagreen, #set_be_verbose, #set_xorg_buffer, #sfancy, #sfile, #show_help, #silent_redirection?, #simp, #simple_esystem, #skyblue, #slateblue, #slategray, #springgreen, #steelblue, #swarn, #symlink, #teal, #temp_dir?, #to_camelcase, #to_counted_hash, #tomato, #touch, #try_to_require_the_beautiful_url_gem, #try_to_require_the_html_template, #try_to_require_the_open_gem, #try_to_require_the_program_information_gem, #try_to_require_the_xorg_buffer, #use_colours?, #verbose_truth, #weekday?, #word_wrap, #write_what_into, #yellow

Methods included from Base::CommandlineArguments

#append_onto_the_commandline_arguments, #clear_commandline_arguments, #commandline_arguments?, #commandline_arguments_as_string?, #commandline_arguments_without_leading_hyphens?, #first_argument?, #first_argument_without_leading_hyphens?, #has_an_argument_been_passed?, #remove_hyphened_arguments_from_the_commandline_arguments, #return_commandline_arguments_with_leading_hyphens, #second_argument?, #set_commandline_arguments

Constructor Details

#initialize(i = ARGV, run_already = true) ⇒ CovidLethality

#

initialize

#


35
36
37
38
39
40
41
# File 'lib/roebe/classes/covid_lethality.rb', line 35

def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  run if run_already
end

Instance Method Details

#process_this_dataset(i) ⇒ Object

#

process_this_dataset

#


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
# File 'lib/roebe/classes/covid_lethality.rb', line 71

def process_this_dataset(i)
  if i.is_a? Array
    @hash = {}
    i.each {|entry|
      splitted = entry.split('  ').map {|entry| entry.strip }
      # =================================================================== #
      # splitted would now look like something like this:
      #
      #   ["United States", "211_698", "4_720", "8_805"]
      #
      # =================================================================== #
      empty_entries_rejected = splitted.reject {|entry| entry.empty? } # China    80_881  3_226
      name_of_the_country = empty_entries_rejected.first
      n_deaths   = empty_entries_rejected[2].to_i
      n_infected = empty_entries_rejected[1].to_i
      lethality_percentage   = (n_deaths * 100.0) / n_infected
      infectivity_percentage = (n_infected * 100.0) / return_n_people_in_this_country(name_of_the_country)  
      @hash[name_of_the_country] = {
        n_infected:             n_infected,
        n_deaths:               n_deaths,
        lethality_percentage:   lethality_percentage.round(3),
        infectivity_percentage: infectivity_percentage
      }
    }
  end
end

#read_in_the_dataset_from_the_ruby_fileObject

#

read_in_the_dataset_from_the_ruby_file

#


64
65
66
# File 'lib/roebe/classes/covid_lethality.rb', line 64

def read_in_the_dataset_from_the_ruby_file
  @dataset = DATA.read
end

#reportObject

#

report

#


128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/roebe/classes/covid_lethality.rb', line 128

def report
  e
  @hash.each_pair {|name_of_the_country, dataset|
    n_deaths          = dataset[:n_deaths].to_f
    n_infected_people = dataset[:n_infected].to_f
    n_people          = @n_people_in_these_countries[name_of_the_country].to_i
    lethality_compared_to_n_people = (
      n_deaths * 100.0
    ) / n_people
    case name_of_the_country
    when /^United Kingdom$/i
      name_of_the_country = 'UK'
    when /^United States$/i
      name_of_the_country = 'USA'
    end
    print "  #{steelblue(name_of_the_country.ljust(12))}"
    percentage = (
      n_deaths.to_f * 100.0
    ) / n_infected_people
    percentage_infectivity = ((n_infected_people * 100.0) / n_people).round(3).to_s
    # ===================================================================== #
    # First show the percentage-lethality value.
    # ===================================================================== #
    e '  '+sfancy(percentage.to_s.to_f.round(1).to_s.rjust(4)+'% lethality, ')+
      ' '+lightgreen(
        ('%.3f' % percentage_infectivity.to_f).to_s+
        '% infectivity, '
      )+
      mediumseagreen(
        'n deaths: '+n_deaths.to_i.to_s.rjust(5)
      )+
      steelblue(
        ' [n people: '+n_people.to_i.to_s.rjust(10)+
        '; lethality compared to n people: '+
        lethality_compared_to_n_people.round(4).to_s+'%]'
      )
    if @show_how_many_people_live_in_that_country
      e '  n people in this country: '+steelblue(
          return_n_people_in_this_country(name_of_the_country).to_s
        )
    end
  }
  report_the_global_lethality(@hash)
  e
end

#report_the_global_lethality(i = @hash) ⇒ Object

#

report_the_global_lethality

This method will report the global lethality, as percentage value, such as “4.3%”.

#


180
181
182
183
184
185
186
187
188
189
190
# File 'lib/roebe/classes/covid_lethality.rb', line 180

def report_the_global_lethality(i = @hash)
  selection = i.map {|name_of_the_country, inner_hash|
    inner_hash[:lethality_percentage]
  }
  sum = selection.sum.to_f
  result = sum / selection.size
  e '-'*80
  e 'The '+steelblue('global lethality')+' is: '+
     royalblue(result.round(3).to_s+'%')
  e
end

#resetObject

#

reset (reset tag)

#


46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/roebe/classes/covid_lethality.rb', line 46

def reset
  super()
  infer_the_namespace
  # ======================================================================= #
  # === @show_how_many_people_live_in_that_country
  # ======================================================================= #
  @show_how_many_people_live_in_that_country = true
  # ======================================================================= #
  # === @n_people_in_these_countries
  # ======================================================================= #
  @n_people_in_these_countries = YAML.load_file(
    FILE_N_PEOPLE_IN_THESE_COUNTRIES
  )
end

#return_n_people_in_this_country(i) ⇒ Object

#

return_n_people_in_this_country

#


195
196
197
198
199
200
201
# File 'lib/roebe/classes/covid_lethality.rb', line 195

def return_n_people_in_this_country(i)
  case i
  when 'USA'
    i = 'United States'
  end
  @n_people_in_these_countries[i]
end

#runObject

#

run

#


206
207
208
209
210
211
212
# File 'lib/roebe/classes/covid_lethality.rb', line 206

def run
  read_in_the_dataset_from_the_ruby_file
  splitted = @dataset.split("\n")
  process_this_dataset(splitted)
  sort_the_dataset
  report
end

#sort_the_dataset(sort_by = :infectivity_percentage) ⇒ Object

#

sort_the_dataset (sort tag)

This can go directly on @hash, more or less. Currently the method will sort on the entry called :lethality_percentage.

This can be controlled by the argument to the method.

Suggested parameters for that argument are:

:n_infected
:lethality_percentage
:infectivity_percentage
#


113
114
115
116
117
118
119
120
121
122
123
# File 'lib/roebe/classes/covid_lethality.rb', line 113

def sort_the_dataset(
    sort_by = :infectivity_percentage # :lethality_percentage # :n_infected
  )
  _ = @hash.sort_by {|name_of_the_country, inner_hash|
    inner_hash[sort_by]
  }.reverse
  @hash.clear
  _.each {|name_of_the_country, inner_hash|
    @hash[name_of_the_country] = inner_hash
  }
end