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.
Defined Under Namespace
Classes: Continuous, Media, PresenceAbsence, Qualitative, Sample, Working
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
#reject_confidences
#reject_tags, #tag_with, #tagged?, #tagged_with?
#concatenated_notes_string, #reject_notes
#has_depictions?, #image_array=, #reject_depictions, #reject_images
#identified?, #next_by_identifier, #previous_by_identifier, #reject_identifiers
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
#cited?, #mark_citations_for_destruction, #nomenclature_date, #origin_citation_source_id, #reject_citations, #requires_citation?, #sources_by_topic_id
#has_polymorphic_relationship?
transaction_with_retry
Instance Attribute Details
#observation_object_global_id ⇒ String
TODO: this is not memoized correctly ?!
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
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_name ⇒ Object
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
40
41
42
|
# File 'app/models/observation.rb', line 40
def continuous?
type == 'Observation::Continuous'
end
|
#convert_observation_object_global_id ⇒ Object
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_object ⇒ Object
71
72
73
|
# File 'app/models/observation.rb', line 71
def observation_object
[otu, collection_object].compact.first
end
|
#otu_or_collection_object_set ⇒ Object
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
36
37
38
|
# File 'app/models/observation.rb', line 36
def presence_absence?
type == 'Observation::PresenceAbsence'
end
|
#qualitative? ⇒ 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_descriptor ⇒ Object
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_descriptor ⇒ Object
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
|