Module: ObservationsHelper

Defined in:
app/helpers/observations_helper.rb

Instance Method Summary collapse

Instance Method Details

#continuous_observation_cell_tag(observation) ⇒ Object



49
50
51
# File 'app/helpers/observations_helper.rb', line 49

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

#label_for_observation(observation) ⇒ Object



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

def label_for_observation(observation)
  return nil if observation.nil?
  observation.descriptor.name # TODO: add values
end

#observation_cell_tag(observation) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/observations_helper.rb', line 18

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)

  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



36
37
38
39
40
41
42
43
# File 'app/helpers/observations_helper.rb', line 36

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



13
14
15
16
# File 'app/helpers/observations_helper.rb', line 13

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
# File 'app/helpers/observations_helper.rb', line 3

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

#presence_absence_observation_cell_tag(observation) ⇒ Object



53
54
55
56
# File 'app/helpers/observations_helper.rb', line 53

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

#qualitative_observation_cell_tag(observation) ⇒ Object



45
46
47
# File 'app/helpers/observations_helper.rb', line 45

def qualitative_observation_cell_tag(observation)
  observation.character_state.label
end

#sample_observation_cell_tag(observation) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/observations_helper.rb', line 58

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