Module: Tasks::CollectingEvents::Parse::Stepwise::LatLongHelper

Defined in:
app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) make_lat_long_matching_table(*pieces, collection)

Parameters:

  • pieces (String)

    is either piece, or lat, long

  • collection (Scope)

    is a scope of CollectingEvent



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
99
100
101
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 50

def make_lat_long_matching_table(*pieces, collection)
  columns = ['CEID', 'Match', 'Verbatim Lat', 'Verbatim Long',
             'Decimal lat', 'Decimal long', 'Is georeferenced?', 'Select']

  thead = (:thead) do
    (:tr) do
      columns.collect { |column| concat (:th, column) }.join.html_safe
    end
  end

  tbody =  (:tbody) do
    collection.collect { |item|
       (:tr) do
        item_data = ''
        no_georef = false
        columns.collect.with_index { |column, dex|
          options = {align: 'center'}
          case dex
            when 0 #'CEID'
              item_data = link_to(item.id, item)
            when 1 #'Match'
              item_data      = pieces.join(' ')
              options[:data] = {help: item.verbatim_label}
            when 2 #'Verbatim Lat'
              item_data = item.verbatim_latitude
            when 3 #'Verbatim Long'
              item_data = item.verbatim_longitude
            when 4 #'Decimal lat'
              item_data = item.latitude
            when 5 #'Decimal long'
              item_data = item.longitude
            when 6 #'Is georeferenced?'
              if item.georeferences.any?
                item_data = 'yes'
                no_georef = true
              else
                item_data = 'no'
              end
            when 7 #'Select'
              # check_box_tag(name, value = "1", checked = false, options = {}) public
              options_for         = {disabled: no_georef}
              options_for[:class] = 'selectable_select' unless no_georef
              item_data           = check_box_tag('selected[]', item.id, false, options_for)
          end
          concat (:td, item_data, options)
        }.to_s.html_safe
      end
    }.join().html_safe
  end

  (:table, thead.concat(tbody), {id: 'matching_table', border: '1', align: 'center'}).html_safe
end

- (Object) make_method_headers



8
9
10
11
12
13
14
15
16
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 8

def make_method_headers
  list         = Utilities::Geo::REGEXP_COORD
  selector_row = ""
  list.keys.each { |kee|
    selector_row += (:th, kee.to_s.upcase,
                                data: {help: Utilities::Geo::REGEXP_COORD[kee][:hlp]})
  }
  selector_row.html_safe
end

- (Object) make_rows(label, filters)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 30

def make_rows(label, filters)
  return nil if label.nil?
  tests = Utilities::Geo.hunt_wrapper(label, filters)
  tests.keys.collect.with_index do |kee, dex|
    trial  = tests[kee]
    method = trial.delete(:method)
    next if trial.blank?
    (:tr, class: :extract_row) do
      (:td, method, align: 'center') +
        # content_tag(:td, kee == method ? '' : kee) +
        (:td, trial[:piece], class: :piece_value, align: 'center') +
        (:td, trial[:lat], class: :latitude_value, align: 'center') +
        (:td, trial[:long], class: :longitude_value, align: 'center') +
        (:td, radio_button_tag('select', dex, false, class: :select_lat_long), align: 'center')
    end
  end.join.html_safe
end

- (Object) make_selected_method_boxes(filters = Utilities::Geo::REGEXP_COORD.keys)

Parameters:

  • must (Array)

    be array of symbols from Utilities::Geo::REGEXP_COORD



20
21
22
23
24
25
26
27
28
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 20

def make_selected_method_boxes(filters = Utilities::Geo::REGEXP_COORD.keys)
  list    = Utilities::Geo::REGEXP_COORD
  box_row = ""
  list.keys.each { |kee|
    checked = filters.include?(kee)
    box_row += (:td, check_box_tag("filters[]", kee.to_s, checked), align: 'center')
  }
  box_row.html_safe
end

- (Object) parse_label(label)



3
4
5
6
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 3

def parse_label(label)
  retval = Utilities::Geo.hunt_wrapper(label)
  retval
end

- (Object) parse_lat_long_skip(current_collecting_event_id, filters)



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 119

def parse_lat_long_skip(current_collecting_event_id, filters)
  # TODO: Now this has to be bound to next hit
  # filters = Utilities::Geo::REGEXP_COORD.keys
  next_id = Queries::CollectingEventLatLongExtractorQuery.new(
    collecting_event_id: current_collecting_event_id,
    filters:             filters).all.with_project_id(sessions_current_project_id).first.try(:id)
  if next_id
    button_tag('Skip to next record',
               {value: 'skip', id: 'skip'})
    # link_to('Skip to next record', collecting_event_lat_long_task_path(collecting_event_id: next_id))
  else
    (:span, 'no more matches')
  end + button_tag('Re-evaluate',
                   {value: 're_eval', id: 're_eval'})
end

- (Object) scan_c_e



135
136
137
138
139
140
141
142
143
144
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 135

def scan_c_e
  pile = Queries::CollectingEventLatLongExtractorQuery.new(
    collecting_event_id: 0,
    filters:             DEFAULT_SQL_REGEXS).all.with_project_id(sessions_current_project_id).order(:id)
  pile.each { |c_e|
    trials = Utilities::Geo.hunt_lat_long_full(c_e.verbatim_label)
    puts(c_e.id)
  }
  pile
end

- (Object) show_ce_vl(collecting_event)



111
112
113
114
115
116
117
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 111

def show_ce_vl(collecting_event)
  message = 'No collecting event available.'
  unless collecting_event.nil?
    message = collecting_event.verbatim_label
  end
  collecting_event_label_tag(message)
end

- (Object) test_lat



103
104
105
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 103

def test_lat
  @collecting_event.verbatim_latitude unless @collecting_event.nil?
end

- (Object) test_long



107
108
109
# File 'app/helpers/tasks/collecting_events/parse/stepwise/lat_long_helper.rb', line 107

def test_long
  @collecting_event.verbatim_longitude unless @collecting_event.nil?
end