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, use_community_taxon:, import_images:, import_sounds:) ⇒ 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 |
# 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] { observation_id: r['id'].to_s, uuid:, taxon_name: fo&.dig(:taxon_name) || ::Vendor::Nasturtium.taxon_name(r, use_community_taxon:), 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, browse_url: existing_fo_id ? browse_field_occurrence_task_path(field_occurrence_id: existing_fo_id) : nil, image_count: fo ? fo.dig(:image_count) : ::Vendor::Nasturtium.permitted_photos(r).size, sound_count: fo ? fo.dig(:sound_count) : ::Vendor::Nasturtium.permitted_sounds(r).size } end end |
#inaturalist_import_summary(results, existing_fo_by_uuid, use_community_taxon:, import_images:, import_sounds:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb', line 24 def inaturalist_import_summary(results, existing_fo_by_uuid, use_community_taxon:, import_images:, import_sounds:) results.map do |r| uuid = r['uuid'] existing_fo_id = existing_fo_by_uuid[uuid] taxon_name = ::Vendor::Nasturtium.taxon_name(r, use_community_taxon:) status = if existing_fo_id 'already_imported' elsif taxon_name.blank? '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, browse_url: existing_fo_id ? browse_field_occurrence_task_path(field_occurrence_id: existing_fo_id) : nil, 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/tasks/field_occurrences/inaturalist_import_helper.rb', line 52 def serialize_inat_field_occurrence(fo) otu = fo.taxon_determinations.first.otu inat_identifier = fo.identifiers.find { |i| i.is_a?(Identifier::Global::Uuid::InaturalistObservation) } { id: fo.taxon_determinations.first.otu.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: inat_identifier ? "https://www.inaturalist.org/observations/#{inat_identifier.identifier}" : nil, image_count: fo.depictions.size, sound_count: fo.conveyances.size } end |