Module: ObservationsHelper
- Defined in:
- app/helpers/observations_helper.rb
Instance Method Summary collapse
- #continuous_observation_cell_tag(observation) ⇒ Object
- #label_for_observation(observation) ⇒ Object
- #observation_cell_tag(observation, 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_tag(observation) ⇒ Object
- #qualitative_observation_cell_tag(observation, verbose = false) ⇒ Object
- #sample_observation_cell_tag(observation) ⇒ Object
Instance Method Details
#continuous_observation_cell_tag(observation) ⇒ Object
59 60 61 |
# File 'app/helpers/observations_helper.rb', line 59 def continuous_observation_cell_tag(observation) [observation.continuous_value, observation.continuous_unit].compact.join(' ') end |
#label_for_observation(observation) ⇒ Object
9 10 11 12 |
# File 'app/helpers/observations_helper.rb', line 9 def label_for_observation(observation) return nil if observation.nil? observation.descriptor.name # TODO: add values end |
#observation_cell_tag(observation, verbose = false) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/observations_helper.rb', line 24 def observation_cell_tag(observation, verbose = false) case observation.type when 'Observation::Qualitative' qualitative_observation_cell_tag(observation, verbose) when 'Observation::Continuous' continuous_observation_cell_tag(observation) when 'Observation::Sample' sample_observation_cell_tag(observation) when 'Observation::PresenceAbsence' presence_absence_observation_cell_tag(observation) when 'Observation::Working' # TODO: Validate in format tag.span('X', title: observation.description) else '!! display not done !!' end end |
#observation_made_on_tag(observation) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'app/helpers/observations_helper.rb', line 42 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
19 20 21 22 |
# File 'app/helpers/observations_helper.rb', line 19 def observation_matrix_cell_tag(observation_object, descriptor) q = Observation.object_scope(observation_object).where(descriptor: descriptor) q.collect{|o| observation_cell_tag(o)}.sort.join(' ').html_safe end |
#observation_tag(observation) ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/observations_helper.rb', line 3 def observation_tag(observation) return nil if observation.nil? [descriptor_tag(observation.descriptor), observation_cell_tag(observation, true)].join(': ').html_safe #"#{observation.descriptor.name}: #{observation.id}" end |
#observation_type_label(observation) ⇒ Object
14 15 16 |
# File 'app/helpers/observations_helper.rb', line 14 def observation_type_label(observation) observation.type.split('::').last end |
#presence_absence_observation_cell_tag(observation) ⇒ Object
63 64 65 66 |
# File 'app/helpers/observations_helper.rb', line 63 def presence_absence_observation_cell_tag(observation) # TODO: messing with visualization here, do something more clean observation.presence ? '✓' : '❌' end |
#qualitative_observation_cell_tag(observation, verbose = false) ⇒ Object
51 52 53 54 55 56 57 |
# File 'app/helpers/observations_helper.rb', line 51 def qualitative_observation_cell_tag(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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'app/helpers/observations_helper.rb', line 68 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 |