Class: Observation

Overview

Observations are of various types, e.g. Qualitative, Quantitative, Statistical. Made on an Otu or CollectionObject. They are where you store the data for concepts like traits, phenotypes, measurements, character matrices, descriptive matrices etc.

Direct Known Subclasses

Continuous, Media, PresenceAbsence, Qualitative, Sample, Working

Defined Under Namespace

Classes: Continuous, Media, PresenceAbsence, Qualitative, Sample, Working

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared::IsData

#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar

Methods included from Shared::Confidences

#reject_confidences

Methods included from Shared::Tags

#reject_tags, #tag_with, #tagged?, #tagged_with?

Methods included from Shared::Notes

#concatenated_notes_string, #reject_notes

Methods included from Shared::Depictions

#has_depictions?, #image_array=, #reject_depictions, #reject_images

Methods included from Shared::Identifiers

#identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers

Methods included from Shared::DataAttributes

#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes

Methods included from Shared::Citations

#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id

Methods included from Housekeeping

#has_polymorphic_relationship?

Methods inherited from ApplicationRecord

transaction_with_retry

Instance Attribute Details

#observation_object_global_idString

TODO: this is not memoized correctly ?!

Returns:

  • (String)


18
19
20
# File 'app/models/observation.rb', line 18

def observation_object_global_id
  @observation_object_global_id
end

Class Method Details

.by_descriptors_and_rows(descriptor_ids, row_object_global_ids) ⇒ Object



52
53
54
55
56
57
58
# File 'app/models/observation.rb', line 52

def self.by_descriptors_and_rows(descriptor_ids, row_object_global_ids)
  collection_object_ids = ::GlobalIdHelper.ids_by_class_name(row_object_global_ids, 'CollectionObject')
  otu_ids = ::GlobalIdHelper.ids_by_class_name(row_object_global_ids, 'Otu')

  where(descriptor_id: descriptor_ids, otu_id: otu_ids).or(
    where(descriptor_id: descriptor_ids, collection_object_id: collection_object_ids))
end

.copy(old_global_id, new_global_id) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/models/observation.rb', line 108

def self.copy(old_global_id, new_global_id)
  begin
    old = GlobalID::Locator.locate(old_global_id)

    Observation.transaction do
      old.observations.each do |o|
        d = o.dup
        d.update(observation_object_global_id: new_global_id) 
      end
    end
    true
  rescue
    return false
  end
  true
end

.destroy_row(observation_matrix_row_id) ⇒ Object

Remove all observations for the set of descriptors in a given row



126
127
128
129
130
131
132
133
134
135
136
# File 'app/models/observation.rb', line 126

def self.destroy_row(observation_matrix_row_id)
  r = ObservationMatrixRow.find(observation_matrix_row_id)
  begin
    Observation.transaction do
      r.observations.destroy_all
    end
  rescue
    raise
  end
  true
end

.human_nameObject



67
68
69
# File 'app/models/observation.rb', line 67

def self.human_name
  'YAY'
end

.in_observation_matrix(observation_matrix_id) ⇒ Object



44
45
46
47
48
49
# File 'app/models/observation.rb', line 44

def self.in_observation_matrix(observation_matrix_id)
  om = ObservationMatrix.find(observation_matrix_id)

  where(descriptor: om.descriptors, otu: om.otus).or(
  where(descriptor: om.descriptors, collection_object: om.collection_objects))
end

.object_scope(object) ⇒ Object



60
61
62
63
64
65
# File 'app/models/observation.rb', line 60

def self.object_scope(object)
  return Observation.none if object.nil?
  return Observation.where(otu_id: object.id) if object.class.name == 'Otu'
  return Observation.where(collection_object_id: object.id) if object.metamorphosize.class.name == 'CollectionObject'
  Observation.none 
end

Instance Method Details

#continuous?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/observation.rb', line 40

def continuous?
  type == 'Observation::Continuous'
end

#convert_observation_object_global_idObject (protected)



152
153
154
# File 'app/models/observation.rb', line 152

def convert_observation_object_global_id
  set_observation_object_id(GlobalID::Locator.locate(observation_object_global_id)) if observation_object_global_id 
end

#observation_objectObject



71
72
73
# File 'app/models/observation.rb', line 71

def observation_object
  [otu, collection_object].compact.first
end

#otu_or_collection_object_setObject (protected)



156
157
158
159
160
# File 'app/models/observation.rb', line 156

def otu_or_collection_object_set
  if otu_id.blank? && collection_object_id.blank? && otu.blank? && collection_object.blank?
    errors.add(:base, 'observations must reference an Otu or collection object')
  end
end

#presence_absence?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/observation.rb', line 36

def presence_absence?
  type == 'Observation::PresenceAbsence'
end

#qualitative?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/observation.rb', line 32

def qualitative?
  type == 'Observation::Qualitative'
end

#set_observation_object_id(object) ⇒ Object



80
81
82
83
84
85
86
87
88
89
# File 'app/models/observation.rb', line 80

def set_observation_object_id(object)
  case object.metamorphosize.class.name
  when 'Otu'
    write_attribute(:otu_id, object.id)
  when 'CollectionObject'
    write_attribute(:collection_object_id, object.id)
  else
    return false
  end 
end

#set_type_from_descriptorObject (protected)



140
141
142
143
144
# File 'app/models/observation.rb', line 140

def set_type_from_descriptor
  if type.blank? && descriptor&.type
    write_attribute(:type, 'Observation::' + descriptor.type.split('::').last)
  end
end

#type_matches_descriptorObject (protected)



146
147
148
149
150
# File 'app/models/observation.rb', line 146

def type_matches_descriptor
  a = type&.split('::')&.last
  b = descriptor&.type&.split('::')&.last
  errors.add(:type, 'type of Observation does not match type of Descriptor') if a && b && a != b
end