Class: AreaDataVariable
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AreaDataVariable
- Defined in:
- app/models/area_data_variable.rb
Class Method Summary collapse
Instance Method Summary collapse
- #availability_by_country ⇒ Object
- #availability_by_country_and_long_year ⇒ Object
- #categories ⇒ Object
- #category_id ⇒ Object
- #construct_synthetic_mnemonic(sample_geog_level) ⇒ Object
-
#construct_synthetic_mnemonic_sym(sample_geog_level) ⇒ Object
Need this to be accessible before retrieving area_data_values, since the synthetic_mnemonic is needed at request time but the data isn’t known yet.
- #data_type ⇒ Object
- #implied_decimal_places ⇒ Object
- #len ⇒ Object
- #long_description ⇒ Object
-
#mnemonic_sym ⇒ Object
return the mnemonic for this variable as a symbol.
- #to_s ⇒ Object
-
#var_for_sample_level(sample_geog_level) ⇒ Object
given a sample_geog_level, return the sample_level_area_data_variable for this var for that sample_geog_level.
Class Method Details
.long_description(area_data_variables) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/models/area_data_variable.rb', line 128 def self.long_description(area_data_variables) if area_data_variables.count > 0 str = [] area_data_variables.each do |adv| str << adv.long_description end str.join("\n") else "No Area-level Variables" end end |
Instance Method Details
#availability_by_country ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'app/models/area_data_variable.rb', line 97 def availability_by_country store = {} sample_level_area_data_variables.includes(terrapop_sample: :country).find_each do |sladv| unless sladv.terrapop_sample.country.nil? country_code = sladv.terrapop_sample.country.full_name store[country_code] ||= [] store[country_code] << sladv.terrapop_sample.year end end store = Hash[store.sort] _availability_by_country = {} store.each { |key, val| _availability_by_country[key] = val.uniq.sort } _availability_by_country end |
#availability_by_country_and_long_year ⇒ Object
92 93 94 |
# File 'app/models/area_data_variable.rb', line 92 def availability_by_country_and_long_year terrapop_samples.map{ |terrapop_sample| terrapop_sample.short_country_name_long_year }.uniq end |
#categories ⇒ Object
87 88 89 |
# File 'app/models/area_data_variable.rb', line 87 def categories [] end |
#category_id ⇒ Object
118 119 120 |
# File 'app/models/area_data_variable.rb', line 118 def category_id area_data_table.category_id end |
#construct_synthetic_mnemonic(sample_geog_level) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/models/area_data_variable.rb', line 47 def construct_synthetic_mnemonic(sample_geog_level) mnm = "#{mnemonic}_" mnm += if sample_geog_level.geolink_variable.nil? "#{sample_geog_level.terrapop_sample.short_country_name.upcase}_#{sample_geog_level.country_level.geog_unit.code.upcase}" else "#{sample_geog_level.geolink_variable.mnemonic}" end mnm += "_#{sample_geog_level.terrapop_sample.dataset_identifier}" mnm.upcase end |
#construct_synthetic_mnemonic_sym(sample_geog_level) ⇒ Object
Need this to be accessible before retrieving area_data_values, since the synthetic_mnemonic is needed at request time but the data isn’t known yet.
42 43 44 |
# File 'app/models/area_data_variable.rb', line 42 def construct_synthetic_mnemonic_sym(sample_geog_level) construct_synthetic_mnemonic(sample_geog_level).to_sym end |
#data_type ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/area_data_variable.rb', line 70 def data_type case measurement_type.label when 'Count', 'Modal' 'integer' when 'Mean', 'Median', 'Percentage', 'Area' 'decimal' else 'integer' end end |
#implied_decimal_places ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'app/models/area_data_variable.rb', line 60 def implied_decimal_places case data_type when 'integer' 0 when 'decimal' 3 end end |
#len ⇒ Object
82 83 84 |
# File 'app/models/area_data_variable.rb', line 82 def len 10 end |
#long_description ⇒ Object
123 124 125 |
# File 'app/models/area_data_variable.rb', line 123 def long_description mnemonic + " " + label + " (" + measurement_type.label + ")" end |
#mnemonic_sym ⇒ Object
return the mnemonic for this variable as a symbol.
35 36 37 |
# File 'app/models/area_data_variable.rb', line 35 def mnemonic_sym mnemonic.to_sym end |
#to_s ⇒ Object
113 114 115 |
# File 'app/models/area_data_variable.rb', line 113 def to_s mnemonic.nil? ? "<not set>" : mnemonic end |
#var_for_sample_level(sample_geog_level) ⇒ Object
given a sample_geog_level, return the sample_level_area_data_variable for this var for that sample_geog_level. there should only be one.
29 30 31 |
# File 'app/models/area_data_variable.rb', line 29 def var_for_sample_level(sample_geog_level) sample_level_area_data_variables.belonging_to_level(sample_geog_level).first end |