Module: Tasks::FieldOccurrences::InaturalistImportHelper
- Defined in:
- app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb
Instance Method Summary collapse
- #inaturalist_find_summary(results, existing_fo_by_uuid, fo_data:, use_community_taxon: true) ⇒ Object
- #inaturalist_import_summary(results, existing_fo_by_uuid, fo_data:, use_community_taxon:, import_images:, import_sounds:, taxon_determination: nil) ⇒ Object
- #serialize_inat_field_occurrence(fo) ⇒ Object
Instance Method Details
#inaturalist_find_summary(results, existing_fo_by_uuid, fo_data:, use_community_taxon: true) ⇒ Object
3 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 |
# File 'app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb', line 3 def inaturalist_find_summary( results, existing_fo_by_uuid, fo_data:, use_community_taxon: true ) results.map do |r| uuid = r['uuid'] existing_fo_id = existing_fo_by_uuid[uuid] fo = fo_data[existing_fo_id] if fo image_count = fo.dig(:image_count) sound_count = fo.dig(:sound_count) else image_count = ::Vendor::Nasturtium.permitted_photos(r).size sound_count = ::Vendor::Nasturtium.permitted_sounds(r).size end { observation_id: r['id'].to_s, uuid:, taxon_name: ::Vendor::Nasturtium.taxon_name(r, use_community_taxon:), determination_label: fo&.dig(:determination_label), observer: r.dig('user', 'name').presence || r.dig('user', 'login'), observed_on: r['observed_on'], place_guess: r['place_guess'], status: existing_fo_id ? 'found' : 'not_imported', field_occurrence_id: existing_fo_id, global_id: fo&.dig(:global_id), image_count:, sound_count: } end end |
#inaturalist_import_summary(results, existing_fo_by_uuid, fo_data:, use_community_taxon:, import_images:, import_sounds:, taxon_determination: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb', line 35 def inaturalist_import_summary( results, existing_fo_by_uuid, fo_data:, use_community_taxon:, import_images:, import_sounds:, taxon_determination: nil ) results.map do |r| uuid = r['uuid'] existing_fo_id = existing_fo_by_uuid[uuid] fo = fo_data[existing_fo_id] taxon_name = ::Vendor::Nasturtium.taxon_name(r, use_community_taxon:) status = if existing_fo_id 'already_imported' elsif taxon_name.blank? && taxon_determination.nil? 'no_taxon' else 'queued' end { observation_id: r['id'].to_s, uuid:, taxon_name:, observer: r.dig('user', 'name').presence || r.dig('user', 'login'), observed_on: r['observed_on'], place_guess: r['place_guess'], status:, field_occurrence_id: existing_fo_id, global_id: fo&.dig(:global_id), determination_label: fo&.dig(:determination_label), image_count: import_images ? ::Vendor::Nasturtium.permitted_photos(r).size : nil, sound_count: import_sounds ? ::Vendor::Nasturtium.permitted_sounds(r).size : nil } end end |
#serialize_inat_field_occurrence(fo) ⇒ Object
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 |
# File 'app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb', line 71 def serialize_inat_field_occurrence(fo) # current determination (lowest position; the preloaded association is # unordered) otu = fo.taxon_determinations.min_by(&:position).otu inat_identifier = fo.identifiers.find { |i| i.is_a?(Identifier::Global::Uuid::InaturalistObservation) } inat_url = inat_identifier ? "https://www.inaturalist.org/observations/#{inat_identifier.identifier}" : nil { id: fo.id, taxon_name: otu_tag(otu), otu_global_id: otu.to_global_id.to_s, otu_id: otu.id, global_id: fo.to_global_id.to_s, verbatim_locality: fo.collecting_event.verbatim_locality, created_at: fo.created_at.strftime('%Y-%m-%d %H:%M'), browse_url: browse_field_occurrence_task_path(field_occurrence_id: fo.id), inat_url:, image_count: fo.depictions.size, sound_count: fo.conveyances.size } end |