Class: RequestRasterVariable

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/request_raster_variable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.long_description(request_raster_variables) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'app/models/request_raster_variable.rb', line 124

def self.long_description(request_raster_variables)
  if request_raster_variables.count > 0
    mnemonics_operations = {}
    str = []
    
    request_raster_variables.each do |rrv|
      unless mnemonics_operations.has_key? rrv.raster_variable.mnemonic
        mnemonics_operations[rrv.raster_variable.mnemonic] = []
      end
      mnemonics_operations[rrv.raster_variable.mnemonic] << rrv.raster_operation.name
    end
    
    mnemonics_operations.each do |mnemonic,operations|
      m = mnemonic.dup
      str << m.widthize(16) + operations.join(", ")
    end
    
    str.join("\n")
  else
    "No Raster Operations"
  end
end

.mnemonic(raster_variable, raster_operation, raster_dataset, sample_geog_level) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/models/request_raster_variable.rb', line 14

def self.mnemonic(raster_variable, raster_operation, raster_dataset, sample_geog_level)
  #band = (!raster_dataset.nil? && !raster_dataset.raster_band_index.nil?) ? raster_dataset.raster_band_index : 1
  #band = 1 if band <= 0
  
  geography_name = SampleGeogLevel.geography_name(sample_geog_level)
  
  operation = raster_operation.nil? ? "" : "#{raster_operation.opcode}"
  
  mnem = "#{raster_variable.mnemonic}_#{operation}_#{geography_name}_#{raster_dataset.mnemonic}"
  
  # AreaDataRasterVariableMnemonicLookup(composite_mnemonic: string, mnemonic: string, raster_operation_opcode: string, geog_level: string, dataset_label: string, description: text)
  
  adrvml = AreaDataRasterVariableMnemonicLookup.where(composite_mnemonic: mnem).first
  
  if adrvml.nil?
    
    rd_desc = raster_dataset.long_description
    desc = raster_variable.label + "; " + rd_desc[:years] + "; " + (raster_operation.nil? ? "" : raster_operation.name) + "(" + raster_variable.units + ")"
    
    AreaDataRasterVariableMnemonicLookup.create!(composite_mnemonic: mnem, mnemonic: raster_variable.mnemonic, raster_operation_opcode: operation, geog_level: geography_name, dataset_label: raster_dataset.mnemonic, description: desc)
  end
  
  #"#{raster_variable.mnemonic}_#{operation}_#{band}_#{geography_name}"
  
  mnem
end

Instance Method Details

#categoriesObject



110
111
112
# File 'app/models/request_raster_variable.rb', line 110

def categories
  []
end

#data_typeObject



94
95
96
# File 'app/models/request_raster_variable.rb', line 94

def data_type
  "decimal"
end

#filenameObject

methods needed for syntax file generation. For Variable, they’re in the database. For Area_Data_Variable, they’re hardcoded similar to the structure here.



79
80
81
# File 'app/models/request_raster_variable.rb', line 79

def filename
  raster_variable.filename
end

#geography_nameObject

Moved to SampleGeogLevel def self.geography_name(sample_geog_level)

if sample_geog_level.nil?
  ""
else
  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
end

end



55
56
57
# File 'app/models/request_raster_variable.rb', line 55

def geography_name
  RequestRasterVariable.geography_name(sample_geog_level)
end

#implied_decimal_placesObject



105
106
107
# File 'app/models/request_raster_variable.rb', line 105

def implied_decimal_places
  0
end

#is_summary?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/request_raster_variable.rb', line 65

def is_summary?
  raster_operation.nil?
end

#labelObject



115
116
117
# File 'app/models/request_raster_variable.rb', line 115

def label
  mnemonic
end

#lenObject

shouldn’t matter for CSV extracts.



100
101
102
# File 'app/models/request_raster_variable.rb', line 100

def len
  10
end

#long_mnemonicObject



84
85
86
# File 'app/models/request_raster_variable.rb', line 84

def long_mnemonic
  raster_variable.long_mnemonic
end

#mnemonicObject



10
11
12
# File 'app/models/request_raster_variable.rb', line 10

def mnemonic
  RequestRasterVariable.mnemonic(raster_variable, raster_operation, raster_dataset, sample_geog_level)
end

#mnemonic_symObject



60
61
62
# File 'app/models/request_raster_variable.rb', line 60

def mnemonic_sym
  mnemonic.to_sym
end

#operationObject

raster_operation might be nil if this is a raster-only extract.



71
72
73
# File 'app/models/request_raster_variable.rb', line 71

def operation
  raster_operation.nil? ? "" : "#{raster_operation.opcode}"
end

#raster_categoriesObject



89
90
91
# File 'app/models/request_raster_variable.rb', line 89

def raster_categories
  raster_variable.raster_categories
end

#to_sObject



120
121
122
# File 'app/models/request_raster_variable.rb', line 120

def to_s
  mnemonic
end