Class: ExtractRequest

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::Validations, ExtractEngine::FileManagement
Defined in:
app/models/extract_request.rb

Defined Under Namespace

Classes: ExtractTypeConst, NewuiExtractValidator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump_allObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
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
# File 'app/models/extract_request.rb', line 114

def self.dump_all
  {
    self.to_s.underscore.pluralize => self.where.not(user: nil).find_each.map { |extract|
      micro_variable_mnemonics  = extract.variables.select(:mnemonic).map(&:mnemonic)
      area_variable_mnemonics   = extract.area_data_variables.select(:mnemonic).map(&:mnemonic)
      raster_dataset_mnemonics  = extract.raster_datasets.select(:mnemonic).map(&:mnemonic)
      terrapop_sample_mnemonics = extract.terrapop_samples.select(:label).map(&:label)
      sample_names              = extract.samples.select(:name).map(&:name)
      {
        'variable_ids'           => micro_variable_mnemonics,
        'area_data_variable_ids' => area_variable_mnemonics,
        'raster_dataset_ids'     => raster_dataset_mnemonics,
        'terrapop_sample_ids'    => terrapop_sample_mnemonics,
        'sample_ids'             => sample_names,
        'boundary_files'         => extract.boundary_files,
        'title'                  => extract.title,
        'notes'                  => extract.notes,
        'user_id'                => extract.user.email,
        'uuid'                   => extract.uuid,
        'submitted'              => extract.,
        'created_at'             => extract.created_at,
        'updated_at'             => extract.updated_at,
       #'derivative'             => extract.uuid,
        'file_type'              => extract.file_type,
        'raster_only'            => extract.raster_only,
        'send_to_irods'          => extract.send_to_irods,
        'extract_url'            => extract.extract_url,
        'request_url'            => extract.request_url,
        'begin_extract_time'     => extract.begin_extract_time,
        'finish_extract_time'    => extract.finish_extract_time,
        'total_time'             => extract.total_time
      }
    },
    'request_raster_variables' => RequestRasterVariable.find_each.map { |request_variable|
      unless request_variable.raster_operation.nil?
        unless request_variable.extract_request.user.nil?
          {
            'extract_request_id'  => request_variable.extract_request.uuid,
            'raster_variable_id'  => request_variable.raster_variable.mnemonic,
            'raster_operation_id' => request_variable.raster_operation.name
          }
        end
      end
    }.compact
  }
end

.duplicate(id_or_extract) ⇒ Object



574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
# File 'app/models/extract_request.rb', line 574

def self.duplicate(id_or_extract)
  if extract = ExtractRequest.find(id_or_extract)
    new_extract = ExtractRequest.create
    new_extract.area_data_variables = extract.area_data_variables
    new_extract.terrapop_samples = extract.terrapop_samples
    new_extract.variables = extract.variables.where(preselect_status: 0)
    new_extract.samples = extract.samples
    extract.request_raster_variables.each do |variable|
      new_extract.request_raster_variables.create({raster_variable: variable.raster_variable, raster_operation: variable.raster_operation, raster_dataset: variable.raster_dataset})
    end
    new_extract.raster_datasets = extract.raster_datasets
    new_extract.geog_units = extract.geog_units
    new_extract.sample_geog_levels = extract.sample_geog_levels #quickfix that may have complications!
    new_extract.boundary_files = extract.boundary_files
    new_extract.send_to_irods = extract.send_to_irods
    new_extract.file_type = extract.file_type
    new_extract.raster_only = extract.raster_only
    new_extract.title = "Revision of Extract #{extract.id}" + ((!extract.title.blank? && " - #{extract.title}") || '')
    new_extract.revision_of_id = extract.id
    new_extract.user_id = extract.user_id
    new_extract.save
    new_extract.reload
  end
end

.enqueuedObject

This is efficient for getting the current statuses where that status is “enqueued”. Otherwise we’d have to use includes(:extract_status) on lots of extract_requests and filter. If this is slow check for indexing on extract_statuses.



526
527
528
# File 'app/models/extract_request.rb', line 526

def self.enqueued
  ExtractStatus.current.enqueued.extracts.map { |status| status.extract_request }
end

.extract_group_count(group_str) ⇒ Object



530
531
532
# File 'app/models/extract_request.rb', line 530

def self.extract_group_count(group_str)
  ExtractStatus.current.enqueued.extracts.joins("INNER JOIN extract_requests er ON er.id = extract_statuses.extract_request_id").where("extract_requests.extract_grouping" => group_str).count
end

.get_next_in_queueObject



534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'app/models/extract_request.rb', line 534

def self.get_next_in_queue
  ActiveRecord::Base.transaction {
    extract_ids = ExtractStatus.current.enqueued.extracts.map { |status| status.extract_request_id }
    found = false
    e = nil
    while extract_ids.count > 0 and found == false
      extract_id = extract_ids.shift

      sql = "SELECT id FROM extract_requests WHERE id = #{extract_id} AND processing = false FOR UPDATE"
      results = ActiveRecord::Base.connection.execute(sql).first
      unless results.nil?
        extract_id = results['id']
        sql = "UPDATE extract_requests SET processing = true WHERE id = #{extract_id}"
        ActiveRecord::Base.connection.execute(sql)
        found = true
        e = ExtractRequest.find(extract_id)
      end

    end

    e
  }
end

.new_extract_groupingObject



699
700
701
702
703
704
705
# File 'app/models/extract_request.rb', line 699

def self.new_extract_grouping
  str = SecureRandom::hex(8)
  while ExtractRequest.where(extract_grouping: str).count > 0
    str = SecureRandom::hex(8)
  end
  str
end

.num_extracts_in_queueObject



558
559
560
# File 'app/models/extract_request.rb', line 558

def self.num_extracts_in_queue
  ExtractStatus.current.enqueued.extracts.count
end

Instance Method Details

#add_preselected_variablesObject



684
685
686
687
688
689
690
691
692
693
694
695
696
# File 'app/models/extract_request.rb', line 684

def add_preselected_variables
  if !self.raster_only && self.variables.count > 0
    preselected_variables = Variable.where(preselect_status: 1).map{ |v| {v => false} }.reduce({}, :merge)
    self.samples.each do |s|
      preselected_variables.each do |var, v|
        if v == false and var.included_in?(s)
          preselected_variables[var] = true
        end
      end
    end
    self.variables.concat preselected_variables.reject{ |k, v| v == false }.keys
  end
end

#begin_processingObject



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'app/models/extract_request.rb', line 423

def begin_processing
  ### This method usually only gets called by the extract engine.
  
  add_status(ExtractStatus::PROCESSING)
  
  begin
    tp_xtr_build = Rails.configuration.build_number
    
    unless tp_xtr_build.to_s.is_i?
      tp_xtr_build = -1
    end
    
  rescue 
    tp_xtr_build = -1
  end
  
  update_attribute(:tp_xtr_build_number, tp_xtr_build)
  
end

#boundary_file_bundleObject



213
214
215
# File 'app/models/extract_request.rb', line 213

def boundary_file_bundle
  "#{boundary_file_stub}.zip"
end

#boundary_file_bundle_pathObject



218
219
220
# File 'app/models/extract_request.rb', line 218

def boundary_file_bundle_path
  File.join(location, boundary_file_bundle)
end

#boundary_file_name(sample_geog_level) ⇒ Object



203
204
205
# File 'app/models/extract_request.rb', line 203

def boundary_file_name(sample_geog_level)
  "#{boundary_file_stub}_#{sample_geog_level.internal_code.to_s}"
end

#boundary_file_namesObject



208
209
210
# File 'app/models/extract_request.rb', line 208

def boundary_file_names
  sample_geog_levels.map{ |sgl| boundary_file_name(sgl) }
end

#boundary_file_stubObject



198
199
200
# File 'app/models/extract_request.rb', line 198

def boundary_file_stub
  "boundaryfiles_#{id.to_s}"
end

#building_requestObject



459
460
461
# File 'app/models/extract_request.rb', line 459

def building_request
  add_status(ExtractStatus::BUILDING_REQUEST)
end

#can_be_resubmitted?Boolean

Returns:

  • (Boolean)


519
520
521
# File 'app/models/extract_request.rb', line 519

def can_be_resubmitted?
  (is_completed? || is_failed? || is_stopped? || is_email_sent?) || false
end

#can_be_revised?Boolean

Returns:

  • (Boolean)


775
776
777
# File 'app/models/extract_request.rb', line 775

def can_be_revised?
  origin != 'newui'
end

#category_code(request_variable, category) ⇒ Object



570
571
572
# File 'app/models/extract_request.rb', line 570

def category_code(request_variable, category)
  request_variable.general? ? category.code[0..request_variable.width - 1] : category.code
end

#completedObject



402
403
404
# File 'app/models/extract_request.rb', line 402

def completed
  add_status(ExtractStatus::COMPLETED)
end

#countriesObject

helper method to get all the countries covered by the extract request



674
675
676
677
678
679
680
681
# File 'app/models/extract_request.rb', line 674

def countries
  cntries = terrapop_samples.pluck(:short_country_name)
  cntries += samples.find_each.map { |sample| sample.short_country_name }
  cntries.uniq!
  countries = Hash[ cntries.map { |country| [country, true] } ]
  countries[:count] = cntries.length
  countries
end

#current_statusObject



469
470
471
# File 'app/models/extract_request.rb', line 469

def current_status
  extract_statuses.order(:updated_at).last
end

#data_dictionariesObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
# File 'app/models/extract_request.rb', line 242

def data_dictionaries
  str = []
  unless extract_data_artifacts.count == 0
    extract_data_artifacts.each do |eda|
      str << "Data File: " + eda.variables_description[:filename] 
      eda.variables_description[:columns].each do |column|
        adrvml = AreaDataRasterVariableMnemonicLookup.where(composite_mnemonic: column).first
        str << column.to_s + ": " + (adrvml.nil? ? "N/A" : adrvml.description)
      end
      str << ""
    end
  end
  str.join("\n")
end

#data_file_summariesObject



222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'app/models/extract_request.rb', line 222

def data_file_summaries
  str = []
  unless extract_data_artifacts.count == 0
    
    extract_data_artifacts.each do |eda|
      str << "Data File: " + eda.variables_description[:filename] 
      if boundary_files
        str << "Boundary Shapefile: " + eda.variables_description[:boundary_filename] 
      end
      str << "Country: " + eda.variables_description[:country]
      str << "Data Year(s): " + eda.variables_description[:years]
      str << "Geographic Level: " + eda.variables_description[:geog_unit] + ": " + eda.variables_description[:country_level]
      str << ""
    end
    
  end
  str.join("\n")
  
end

#datasets_countObject



324
325
326
# File 'app/models/extract_request.rb', line 324

def datasets_count
  terrapop_samples.count + samples.count + raster_datasets.count
end

#download_pathObject

Public path in URL, can’t get from Terrapop.yml



192
193
194
195
# File 'app/models/extract_request.rb', line 192

def download_path
  #"/extracts/#{user_directory()}/#{extract_directory()}"
  File.join('/extracts', user_directory, extract_directory)
end

#email_sentObject



454
455
456
# File 'app/models/extract_request.rb', line 454

def email_sent
  add_status(ExtractStatus::EMAIL_SENT)
end

#enqueueObject



412
413
414
415
416
417
418
419
420
# File 'app/models/extract_request.rb', line 412

def enqueue
  ers = ExtractRequestSubmission.new
  ers. = Time.new
  ers.save
  self.extract_request_submissions << ers
  #update_attribute(:processing, false)
    
  add_status(ExtractStatus::ENQUEUED, {processing: false})
end

#expanded_request_area_data_variablesObject

Need an area data variable for every sample_geog_level+ area data variable combination.



258
259
260
261
262
263
264
265
266
267
268
# File 'app/models/extract_request.rb', line 258

def expanded_request_area_data_variables
  request_area_data_variables.map { |variable|
    sample_geog_levels.map do |sg|
      request_variable = RequestAreaDataVariable.new
      request_variable.area_data_variable = variable.area_data_variable
      request_variable.extract_request = variable.extract_request
      request_variable.sample_geog_level = sg
      request_variable
    end
  }.flatten
end

#expanded_request_raster_variablesObject



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# File 'app/models/extract_request.rb', line 271

def expanded_request_raster_variables
  # .reject{|v| v.raster_operation_id.nil? or v.raster_dataset_id.nil? }
  request_raster_variables.map { |variable|
    sample_geog_levels.map do |sg|
      request_variable = RequestRasterVariable.new
      #request_variable.raster_variable_id   = variable.raster_variable.id
      #request_variable.raster_operation_id  = variable.raster_operation.id
      #request_variable.extract_request_id   = variable.extract_request.id
      #request_variable.raster_dataset_id    = variable.raster_dataset.id
      #request_variable.sample_geog_level_id = sg.id
      request_variable.raster_variable   = variable.raster_variable
      request_variable.raster_operation  = variable.raster_operation
      request_variable.extract_request   = variable.extract_request
      request_variable.raster_dataset    = variable.raster_dataset
      request_variable.sample_geog_level = sg
      request_variable
    end
  }.flatten
  #puts "\n\nexpanded_request_raster_variables: \n"
  #puts "#{rrvs.map{|rrv| rrv.inspect}.join("\n")}"
  #rrvs
end

#exportObject



743
744
745
# File 'app/models/extract_request.rb', line 743

def export
  {}
end

#extract_file_path(ext = nil) ⇒ Object

Public path in URL, can’t get from terrapop.yml



184
185
186
187
188
# File 'app/models/extract_request.rb', line 184

def extract_file_path(ext = nil)
  path = File.join(location, name)
  path += ".#{ext}" unless ext.nil?
  path
end

#extract_typeObject



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'app/models/extract_request.rb', line 358

def extract_type
  if (has_raster_variables? || has_area_data_variables?) && has_microdata_variables?
    ExtractTypeConst::AGGREGATE_ATTACHED_TO_MICRODATA
  elsif has_microdata_variables?
    ExtractTypeConst::MICRODATA
  elsif has_area_data_variables? && !raster_only
    ExtractTypeConst::AGGREGATE
  elsif has_area_data_variables? && raster_only
    ExtractTypeConst::RASTER
  elsif has_raster_variables? && !raster_only
    ExtractTypeConst::AGGREGATE
  elsif has_raster_variables? && raster_only
    ExtractTypeConst::RASTER
  else
    ExtractTypeConst::NO_DATA
  end
end

#extract_type_human_readableObject



767
768
769
770
771
772
773
# File 'app/models/extract_request.rb', line 767

def extract_type_human_readable
  if extract_type == 'aggregate'
    'AREA-LEVEL'
  else
    extract_type.upcase
  end
end

#extract_zip_exists?Boolean

Returns:

  • (Boolean)


634
635
636
637
# File 'app/models/extract_request.rb', line 634

def extract_zip_exists?
  file = self.extract_zip_file
  file.nil? ? false : File.exist?(file)
end

#extract_zip_fileObject



621
622
623
624
625
626
627
628
629
630
631
# File 'app/models/extract_request.rb', line 621

def extract_zip_file
  file = nil
  if !self.extract_url.nil? && is_completed?
    begin
      file = File.join(Rails.root.to_s, "public", URI(self.extract_url).request_uri)
    rescue Exception => e
      Rails.logger.debug e
    end
  end
  file
end

#extract_zip_readable_sizeObject



645
646
647
# File 'app/models/extract_request.rb', line 645

def extract_zip_readable_size
  self.extract_zip_exists? ? "#{('%.2f' % ((self.extract_zip_size).to_f / 2**20)).to_f} MB" : ''
end

#extract_zip_sizeObject



640
641
642
# File 'app/models/extract_request.rb', line 640

def extract_zip_size
  self.extract_zip_exists? ? File.size(self.extract_zip_file) : nil
end

#failedObject



407
408
409
# File 'app/models/extract_request.rb', line 407

def failed
  add_status(ExtractStatus::FAILED)
end

#from_newui?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'app/models/extract_request.rb', line 162

def from_newui?
  self.origin == 'newui'
end

#has_area_data_variable?Boolean

Returns:

  • (Boolean)


329
330
331
# File 'app/models/extract_request.rb', line 329

def has_area_data_variable?
  area_data_variables.exists?(mnemonic: mnemonic)
end

#has_area_data_variables?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'app/models/extract_request.rb', line 294

def has_area_data_variables?
  area_data_variables.count > 0
end

#has_microdata_variable?(mnemonic) ⇒ Boolean

Returns:

  • (Boolean)


334
335
336
# File 'app/models/extract_request.rb', line 334

def has_microdata_variable?(mnemonic)
  variables.exists?(mnemonic: mnemonic)
end

#has_microdata_variables?Boolean

Returns:

  • (Boolean)


299
300
301
# File 'app/models/extract_request.rb', line 299

def has_microdata_variables?
  variables.count > 0
end

#has_raster_variable?(mnemonic) ⇒ Boolean

Returns:

  • (Boolean)


339
340
341
# File 'app/models/extract_request.rb', line 339

def has_raster_variable?(mnemonic)
  raster_variables.exists?(mnemonic: mnemonic)
end

#has_raster_variables?Boolean

Returns:

  • (Boolean)


304
305
306
# File 'app/models/extract_request.rb', line 304

def has_raster_variables?
  raster_variables.count > 0
end

#has_variable?(mnemonic, type) ⇒ Boolean

Returns:

  • (Boolean)


344
345
346
347
348
349
350
351
352
353
354
355
# File 'app/models/extract_request.rb', line 344

def has_variable?(mnemonic, type)
  case type
  when ExtractTypeConst::AGGREGATE
    has_area_data_variable?(mnemonic)
  when ExtractTypeConst::MICRODATA
    has_microdata_variable?(mnemonic)
  when ExtractTypeConst::RASTER
    has_raster_variable?(mnemonic)
  else
    false
  end
end

#has_variables?Boolean

Returns:

  • (Boolean)


309
310
311
# File 'app/models/extract_request.rb', line 309

def has_variables?
  has_area_data_variables? || has_microdata_variables? || has_raster_variables?
end

#hierarchical?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'app/models/extract_request.rb', line 173

def hierarchical?
  self.file_type == "hierarchical"
end

#importObject



708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'app/models/extract_request.rb', line 708

def import
  # this method is very cusomized for arealevel extract worflow, more to come
  self.title = self.data["title"]
  self.notes = self.data["notes"]
  self.boundary_files = self.data["boundary"]
  self.send_to_irods = self.data["datagrid"]
  self.raster_only = self.data["type"] == "raster"
  self.file_type = 'csv' #maybe a case on the self.data["type"]
  #self.variables = coming soon
  #self.samples = coming soon
  self.area_data_variables = AreaDataVariable.where(mnemonic: self.data["arealevel_variables"])
  self.terrapop_samples = TerrapopSample.where(id: self.data["arealevel_datasets"])
  geographic_level_ids = self.data["arealevel_geographic_levels"].empty? ? (self.data["raster_geographic_levels"].empty? ? [] : self.data["raster_geographic_levels"]) : self.data["arealevel_geographic_levels"]
  unless geographic_level_ids.empty?
    self.sample_geog_levels = SampleGeogLevel.where(id: geographic_level_ids)
    self.geog_units = self.sample_geog_levels.map{ |sgl| sgl.geog_unit }.uniq
  end
  self.raster_datasets = RasterDataset.where(mnemonic: self.data["raster_datasets"])
  self.data["raster_operations"].each do |variable_mnemonic, operation_opcodes|
    raster_variable = RasterVariable.find_by(mnemonic: variable_mnemonic)
    unless raster_variable.nil?
      raster_variable.raster_datasets.where(mnemonic: data["raster_datasets"]).each do |raster_dataset|
        RasterOperation.where(opcode: operation_opcodes).each do |operation|
          raster_operations = []
          raster_operations.push(operation.children.size > 0 ? (operation.children & raster_variable.raster_data_type.raster_operations).first : operation).flatten.uniq!
          raster_operations.each do |raster_operation|
            self.request_raster_variables.create({raster_variable: raster_variable, raster_operation: raster_operation, raster_dataset: raster_dataset})
          end
        end
      end
    end
  end
end

#include_boundary_files_human_readableObject



780
781
782
# File 'app/models/extract_request.rb', line 780

def include_boundary_files_human_readable
  boundary_files ? "Yes" : "No"
end

#is_building_request?Boolean

Returns:

  • (Boolean)


509
510
511
# File 'app/models/extract_request.rb', line 509

def is_building_request?
  current_status.status == ExtractStatus::BUILDING_REQUEST
end

#is_completed?Boolean

Returns:

  • (Boolean)


474
475
476
# File 'app/models/extract_request.rb', line 474

def is_completed?
  current_status.status == ExtractStatus::COMPLETED
end

#is_email_sent?Boolean

Returns:

  • (Boolean)


504
505
506
# File 'app/models/extract_request.rb', line 504

def is_email_sent?
  current_status.status == ExtractStatus::EMAIL_SENT
end

#is_empty?Boolean

Returns:

  • (Boolean)


314
315
316
# File 'app/models/extract_request.rb', line 314

def is_empty?
  !has_variables?
end

#is_enqueued?Boolean

Returns:

  • (Boolean)


484
485
486
# File 'app/models/extract_request.rb', line 484

def is_enqueued?
  current_status.status == ExtractStatus::ENQUEUED
end

#is_failed?Boolean

Returns:

  • (Boolean)


479
480
481
# File 'app/models/extract_request.rb', line 479

def is_failed?
  current_status.status == ExtractStatus::FAILED
end

#is_processing?Boolean

Returns:

  • (Boolean)


489
490
491
# File 'app/models/extract_request.rb', line 489

def is_processing?
  current_status.status == ExtractStatus::PROCESSING
end

#is_stopped?Boolean

Returns:

  • (Boolean)


499
500
501
# File 'app/models/extract_request.rb', line 499

def is_stopped?
  current_status.status == ExtractStatus::STOPPED
end

#is_waiting?Boolean

Returns:

  • (Boolean)


494
495
496
# File 'app/models/extract_request.rb', line 494

def is_waiting?
  current_status.status == ExtractStatus::WAITING
end

#microdata_size_in_bytesObject



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'app/models/extract_request.rb', line 600

def microdata_size_in_bytes
  total = 0
  samples.each do |sample|
    h_records = sample.h_records
    p_records = sample.p_records
    t_h = 0
    t_p = 0
    variables.each do |variable|
      size = variable.column_width
      if variable.record_type == 'H'
        t_h += (size * h_records)
      elsif variable.record_type == 'P'
        t_p += (size * p_records)
      end
    end
    total += t_h + t_p
  end
  total
end

#mnemonic(request_variable) ⇒ Object



562
563
564
# File 'app/models/extract_request.rb', line 562

def mnemonic(request_variable)
  use_long_svar_mnemonic?(request_variable.variable) ? request_variable.long_mnemonic : request_variable.mnemonic
end

#most_recent_submitted_atObject



167
168
169
170
# File 'app/models/extract_request.rb', line 167

def 
  mrsa = self.extract_request_submissions.most_recent.first
  mrsa. unless mrsa.nil?
end

#nameObject



178
179
180
# File 'app/models/extract_request.rb', line 178

def name
  "terrapop_extract_#{id.to_s}"
end

#should_stopObject



464
465
466
# File 'app/models/extract_request.rb', line 464

def should_stop
  add_status(ExtractStatus::SHOULD_STOP)
end

#should_stop?Boolean

Returns:

  • (Boolean)


514
515
516
# File 'app/models/extract_request.rb', line 514

def should_stop?
  current_status.status == ExtractStatus::SHOULD_STOP
end

#stoppedObject



449
450
451
# File 'app/models/extract_request.rb', line 449

def stopped
  add_status(ExtractStatus::STOPPED)
end

#submitObject



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'app/models/extract_request.rb', line 377

def submit
  # Changing the submitted setting first captures the idea that the extract is intended to be created and the user wants the data
  # requested. This will be set even if the documentation / syntax file step or the
  # enqueueing step fails.
  #update_attribute(:processing, false)
  update_attribute(:submitted_at, DateTime.now())
  update_attribute(:submitted, true)
  
  begin
    tp_web_build = Rails.configuration.build_number
    
    unless tp_web_build.to_s.is_i?
      tp_web_build = -1
    end
    
  rescue 
    tp_web_build = -1
  end
  
  update_attribute(:tp_web_build_number, tp_web_build)
  
  enqueue
end

#submitted_date_timeObject



748
749
750
751
752
753
754
# File 'app/models/extract_request.rb', line 748

def 
  unless .nil?
    .strftime('%D - %r')
  else
    "N/A"
  end
end

#total_time_human_readableObject



757
758
759
760
761
762
763
764
765
# File 'app/models/extract_request.rb', line 757

def total_time_human_readable
  
  if total_time.nil?
    "- minutes"
  else
    ChronicDuration.output((total_time / 1000.0), :format => :long)
  end
  
end

#use_long_svar_mnemonic?(variable) ⇒ Boolean

Returns:

  • (Boolean)


566
567
568
# File 'app/models/extract_request.rb', line 566

def use_long_svar_mnemonic?(variable)
  variable.is_svar? && !variable.long_mnemonic.blank? # && use_long_svar_names?
end

#variables_countObject



319
320
321
# File 'app/models/extract_request.rb', line 319

def variables_count
  area_data_variables.count + variables.count + raster_variables.count
end

#variables_in_extractObject

Puts all variables together in a list in the order they should appear in the extract



651
652
653
654
655
656
657
658
659
# File 'app/models/extract_request.rb', line 651

def variables_in_extract
  layout_variables = variables + expanded_request_area_data_variables + expanded_request_raster_variables
  if extract_type == ExtractRequest::ExtractTypeConst::AGGREGATE
    #$stderr.puts "======> sample_geog_levels: " + sample_geog_levels.inspect
    raise "There were no sample_geog_levels, extract FAILED!!" if sample_geog_levels.first.nil?
    layout_variables = sample_geog_levels.first.variables_for_area_data_extracts + layout_variables
  end
  layout_variables.sort{ |a,b| a.mnemonic<=>b.mnemonic }
end

#waitingObject



444
445
446
# File 'app/models/extract_request.rb', line 444

def waiting
  add_status(ExtractStatus::WAITING)
end

#yearsObject

helper method to get all the years covered by the extract request



663
664
665
666
667
668
669
670
# File 'app/models/extract_request.rb', line 663

def years
  yrs = terrapop_samples.pluck(:year)
  yrs += samples.pluck(:year)
  yrs.uniq!
  years = Hash[ yrs.map { |year| [year, true] } ]
  years[:count] = yrs.length
  years
end