Module: ObservationsHelper

Defined in:
app/helpers/observations_helper.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) continuous_observation_cell_tag(observation)



32
33
34
# File 'app/helpers/observations_helper.rb', line 32

def continuous_observation_cell_tag(observation)
  [observation.continuous_value, observation.continuous_unit].compact.join(' ')
end

- (Object) observation_cell_tag(observation)



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/observations_helper.rb', line 13

def observation_cell_tag(observation)
  case observation.type
  when 'Observation::Qualitative'
    qualitative_observation_cell_tag(observation)
  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)
  else 
    '!! display not done !!'
  end
end

- (Object) observation_matrix_cell_tag(row_object, descriptor)



8
9
10
11
# File 'app/helpers/observations_helper.rb', line 8

def observation_matrix_cell_tag(row_object, descriptor)
  q = Observation.object_scope(row_object).where(descriptor: descriptor)
  q.collect{|o| observation_cell_tag(o)}.sort.join(' ').html_safe
end

- (Object) observation_tag(observation)



3
4
5
6
# File 'app/helpers/observations_helper.rb', line 3

def observation_tag(observation)
  return nil if observation.nil?
  "#{observation.descriptor.name}: #{observation.id}"
end

- (Object) presence_absence_observation_cell_tag(observation)



36
37
38
39
# File 'app/helpers/observations_helper.rb', line 36

def presence_absence_observation_cell_tag(observation)
  # TODO: messing with visualization here, do something more clean
  observation.presence ? '✓' : '❌' 
end

- (Object) qualitative_observation_cell_tag(observation)



28
29
30
# File 'app/helpers/observations_helper.rb', line 28

def qualitative_observation_cell_tag(observation)
  observation.character_state.label
end

- (Object) sample_observation_cell_tag(observation)



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/observations_helper.rb', line 41

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