Module: Vendor::SimpleMapprHelper

Defined in:
app/helpers/vendor/simple_mappr_helper.rb

Instance Method Summary collapse

Instance Method Details

#simple_mappr_data(params) ⇒ Object

Returns CSV.

Returns:

  • CSV



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/helpers/vendor/simple_mappr_helper.rb', line 4

def simple_mappr_data(params)
  # TODO: Add support for FieldOccurrence, or by Otu Filter

  if params[:collection_object_query]
    a = ::Queries::DwcOccurrence::Filter.new(collection_object_query: params[:collection_object_query]).all.select(:id, :scientificName, :decimalLatitude, :decimalLongitude)

    return nil if a.size > 10_000

    d = {}

    a.find_each do |i|
      k = i.scientificName
      d[k] ||= []
      d[k].push [i.decimalLatitude, i.decimalLongitude].compact.join(',').presence
    end

    h = d.keys.dup
    z =  CSV::Row.new(h,h,true)

    x = d.values
    y = x.shift

    t = y.zip(*x)

    tbl = CSV::Table.new([z], headers: true ) # , col_sep: "\t", encoding: Encoding::UTF_8)

    t.each do |row|
      tbl << CSV::Row.new(h, row, true)
    end

    tbl
  end
end