Skip to content

Commit

Permalink
Add missing simplmappr helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Nov 26, 2024
1 parent e4d966f commit 40e1b14
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions app/helpers/vendor/simple_mappr_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Vendor::SimpleMapprHelper

# @return CSV
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

end

0 comments on commit 40e1b14

Please sign in to comment.