Module: ObservationsHelper
- Includes:
- RecordNavigationHelper
- Defined in:
- app/helpers/observations_helper.rb
Instance Method Summary collapse
- #continuous_observation_cell_label(observation) ⇒ Object
- #label_for_observation(observation) ⇒ Object
-
#next_records(observation) ⇒ Object
!!Array!!.
- #observation_autocomplete_tag(observation) ⇒ Object
- #observation_cell(observation, label_or_tag, verbose = false) ⇒ Object
- #observation_made_on_tag(observation) ⇒ Object
-
#observation_matrix_cell_tag(observation_object, descriptor) ⇒ Object
Joins multiple observations to concat for cells.
- #observation_tag(observation) ⇒ Object
- #observation_type_label(observation) ⇒ Object
- #presence_absence_observation_cell_label(observation) ⇒ Object
- #presence_absence_observation_cell_tag(observation) ⇒ Object
-
#previous_records(observation) ⇒ Object
!!Array!!.
- #qualitative_observation_cell_label(observation, verbose = false) ⇒ Object
- #sample_observation_cell_tag(observation) ⇒ Object
Methods included from RecordNavigationHelper
Instance Method Details
#continuous_observation_cell_label(observation) ⇒ Object
94 95 96 |
# File 'app/helpers/observations_helper.rb', line 94 def continuous_observation_cell_label(observation) [observation.continuous_value, observation.continuous_unit].compact.join(' ') end |
#label_for_observation(observation) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/observations_helper.rb', line 20 def label_for_observation(observation) return nil if observation.nil? a = observation.descriptor.name b = observation_cell(observation, 'label', true) c = send( "label_for_#{observation.observation_object_type.underscore}", observation.observation_object ) if b.empty? "#{a} on #{c}" else "#{a}: #{b} on #{c}" end end |
#next_records(observation) ⇒ Object
Returns !!Array!!.
141 142 143 144 145 146 147 148 149 150 151 |
# File 'app/helpers/observations_helper.rb', line 141 def next_records(observation) # !! Note we only return observations on Otus currently. o = ::Observation .joins("JOIN otus ON observations.observation_object_type = 'Otu' AND observations.observation_object_id = otus.id") .where(project_id: observation.project_id) .where('observations.id > ?', observation.id) .order(:id) .first [o].compact end |
#observation_autocomplete_tag(observation) ⇒ Object
16 17 18 |
# File 'app/helpers/observations_helper.rb', line 16 def observation_autocomplete_tag(observation) observation_tag(observation) end |
#observation_cell(observation, label_or_tag, verbose = false) ⇒ Object
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 |
# File 'app/helpers/observations_helper.rb', line 46 def observation_cell(observation, label_or_tag, verbose = false) case observation.type when 'Observation::Qualitative' qualitative_observation_cell_label(observation, verbose) when 'Observation::Continuous' continuous_observation_cell_label(observation) when 'Observation::Sample' if label_or_tag == 'tag' sample_observation_cell_tag(observation) else # TODO '' end when 'Observation::PresenceAbsence' if label_or_tag == 'tag' presence_absence_observation_cell_tag(observation) else presence_absence_observation_cell_label(observation) end when 'Observation::Working' # TODO: Validate in format if label_or_tag == 'tag' tag.span('X', title: observation.description) else # TODO '' end else '!! display not done !!' end end |
#observation_made_on_tag(observation) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'app/helpers/observations_helper.rb', line 77 def observation_made_on_tag(observation) return nil if observation.nil? [observation.year_made, observation.month_made, observation.day_made, observation.time_made ].compact.join('-') end |
#observation_matrix_cell_tag(observation_object, descriptor) ⇒ Object
Joins multiple observations to concat for cells
41 42 43 44 |
# File 'app/helpers/observations_helper.rb', line 41 def observation_matrix_cell_tag(observation_object, descriptor) q = Observation.object_scope(observation_object).where(descriptor: descriptor) q.collect{|o| observation_cell(o, 'tag')}.sort.join(' ').html_safe end |
#observation_tag(observation) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'app/helpers/observations_helper.rb', line 4 def observation_tag(observation) return nil if observation.nil? a = descriptor_tag(observation.descriptor) b = observation_cell(observation, 'tag', true) c = send( "#{observation.observation_object_type.underscore}_tag", observation.observation_object ) "#{a}: #{b} on #{c}".html_safe end |
#observation_type_label(observation) ⇒ Object
36 37 38 |
# File 'app/helpers/observations_helper.rb', line 36 def observation_type_label(observation) observation.type.split('::').last end |
#presence_absence_observation_cell_label(observation) ⇒ Object
103 104 105 |
# File 'app/helpers/observations_helper.rb', line 103 def presence_absence_observation_cell_label(observation) observation.presence ? 'present' : 'absent' end |
#presence_absence_observation_cell_tag(observation) ⇒ Object
98 99 100 101 |
# File 'app/helpers/observations_helper.rb', line 98 def presence_absence_observation_cell_tag(observation) # TODO: messing with visualization here, do something more clean observation.presence ? '✓' : '❌' end |
#previous_records(observation) ⇒ Object
Returns !!Array!!.
128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/helpers/observations_helper.rb', line 128 def previous_records(observation) # !! Note we only return observations on Otus currently. o = ::Observation .joins("JOIN otus ON observations.observation_object_type = 'Otu' AND observations.observation_object_id = otus.id") .where(project_id: observation.project_id) .where('observations.id < ?', observation.id) .order(id: :desc) .first [o].compact end |
#qualitative_observation_cell_label(observation, verbose = false) ⇒ Object
86 87 88 89 90 91 92 |
# File 'app/helpers/observations_helper.rb', line 86 def qualitative_observation_cell_label(observation, verbose = false) if verbose observation.character_state.label + ': ' + observation.character_state.name else observation.character_state.label end end |
#sample_observation_cell_tag(observation) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'app/helpers/observations_helper.rb', line 107 def sample_observation_cell_tag(observation) o = observation r = [] r.push [o.sample_min, o.sample_max].compact.join('-') r.push "#{o.sample_units}" if o.sample_units.present? m = [] m.push "median = #{o.sample_median}" if o.sample_median.present? m.push "μ = #{o.sample_mean}" if o.sample_mean.present? m.push ["s = #{o.sample_standard_error}", (o.sample_units.present? ? " #{o.sample_units}" : nil)].compact.join if o.sample_standard_error.present? m.push "n = #{o.sample_n}" if o.sample_n.present? m.push "σ = #{o.sample_standard_deviation}" if o.sample_standard_deviation.present? r.push '(' + m.join(', ') + ')' if m.any? r.compact.join(' ').html_safe end |