Module: Export::Coldp::Files::TypeMaterial
- Defined in:
- lib/export/coldp/files/type_material.rb
Overview
ID nameID citation status referenceID locality country latitude longitude altitude host date collector institutionCode catalogNumber associatedSequences sex link remarks
Class Method Summary collapse
- .date(co) ⇒ Object
- .generate(otu, project_members, reference_csv = nil) ⇒ Object
- .locality(co) ⇒ Object
-
.type_material(otu) ⇒ Object
We need to catch types for valid and invalid names.
Class Method Details
.date(co) ⇒ Object
27 28 29 |
# File 'lib/export/coldp/files/type_material.rb', line 27 def self.date(co) co.dwc_event_date&.split('/')[0] unless co.dwc_event_date.nil? end |
.generate(otu, project_members, reference_csv = nil) ⇒ Object
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 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 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/export/coldp/files/type_material.rb', line 45 def self.generate(otu, project_members, reference_csv = nil ) tm = nil text = ::CSV.generate(col_sep: "\t") do |csv| csv << %w{ ID nameID citation status referenceID locality country latitude longitude altitude host date collector institutionCode catalogNumber associatedSequences sex link modified modifiedBy remarks } tm = type_material(otu) tm.each do |r| text = csv << [ nil, # ID: don't expose TW internal type material ID r.protonym_id, # nameID nil, # citation ?! co.buffered_collecting_event r.type_type, # status r.source_id, # referenceID r.locality, # locality r.country, # country r.decimalLatitude, # latitude r.decimalLongitude, # longitude r.verbatimElevation, # altitude nil, # host r.eventDate, # date r.recordedBy, # collector r.institutionCode, # institutionCode r.catalogNumber, # catalogNumber nil, # associatedSequences: unclear what is wanted? https://github.com/CatalogueOfLife/coldp#associatedsequences r.sex, # sex nil, # link # maybe to GBIF by occurrenceID Export::Coldp.modified(r.updated_at), # modified Export::Coldp.modified_by(r.updated_by_id, project_members), # modifiedBy nil # remarks ] end end # TODO: Many people likely don't cite TypeMaterial directly, but rather the Protonym, we could # use that proxy. sources = Source.with(name_scope: tm) .joins(:citations) .joins("JOIN name_scope ns on ns.id = citations.citation_object_id AND citations.citation_object_type = 'TypeMaterial'") .distinct Export::Coldp::Files::Reference.add_reference_rows(sources, reference_csv, project_members) if reference_csv text end |
.locality(co) ⇒ Object
23 24 25 |
# File 'lib/export/coldp/files/type_material.rb', line 23 def self.locality(co) [co.dwc_country, co.dwc_state_province, co.dwc_county, co.dwc_locality].compact.join(', ') end |
.type_material(otu) ⇒ Object
We need to catch types for valid and invalid names.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/export/coldp/files/type_material.rb', line 32 def self.type_material(otu) a = ::Export::Coldp::Files::Name.core_names(otu).unscope(:select).select(:id) b = ::Export::Coldp::Files::Name.invalid_core_names(otu).unscope(:select).select(:id) c = ::Queries.union(TaxonName, [a,b]).select(:id) TypeMaterial.with(name_scope: c) .joins(collection_object: [:dwc_occurrence]) .joins('JOIN name_scope on name_scope.id = type_materials.protonym_id') .left_joins(:source) # original only, not subsequent here, probably people are using Protonym as a proxy .select('type_materials.*, MAX(sources.id) source_id, country, locality, "decimalLatitude", "decimalLongitude", "verbatimElevation", "eventDate", "recordedBy", "institutionCode", "catalogNumber", sex') .group('type_materials.id , country, locality, "decimalLatitude", "decimalLongitude", "verbatimElevation", "eventDate", "recordedBy", "institutionCode", "catalogNumber", sex') end |