Module: Heart::DashboardsHelper

Defined in:
app/helpers/heart/dashboards_helper.rb

Instance Method Summary collapse

Instance Method Details

#check_box_helper(name, value, options, checked = false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/heart/dashboards_helper.rb', line 4

def check_box_helper(name, value, options, checked=false)
  value = value.to_s
  name = name.to_s
  if params[:review].nil?
    if ["movingaverage[]","annotate[]"].include?(name) && ["0","1","note"].include?(value)
      checked = true
    end
  else
    params.each do |x,y|
      if "#{x}[]" == name && y.include?(value) || x == name
        checked = true
      end
    end
  end
  options['id'] = (options['id'].nil?) ? "#{name.gsub("[]","")}_#{value}" : options['id']
  check_box_tag name, value, checked, options
end

#flot_annotations_array(annotation_groups) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/heart/dashboards_helper.rb', line 88

def flot_annotations_array(annotation_groups)
  flotdata = ""
  markings = ""
  y_axis = 0
  colors = ["000", "0066ff"]
  annotation_groups.each do |annotations|
    flotdata += "flotDataAnnotationsHash#{y_axis} : { att_name : 'flotDataAnnotationsHash#{y_axis}', note : { lines : { show : false }, points : { show : true, symbol : 'square' }, color: '##{colors[y_axis]}', label : '', data : ["
    annotations.each do |annotation|
        flotdata = flotdata.to_s + ("["+ to_flot_time(annotation.fulldate).to_s + ", #{y_axis},'" + annotation.note.to_s + "'],").to_s
        markings += "{ color: '#000', lineWidth: 1, xaxis: { from: " + to_flot_time(annotation.fulldate).to_s + ", to: " + to_flot_time(annotation.fulldate).to_s + " } },"
    end
    flotdata += "]}},\n "
    y_axis += 1
  end
  flotdata + "markings : [ #{markings}],"
end

#flot_array(metrics) ⇒ Object

Creates javascript objects to use as hashes for flot graph data series + labels



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/heart/dashboards_helper.rb', line 31

def flot_array(metrics)
  replace = false
  hash = Hash.new
  if metrics.nil? || metrics.first.nil? || metrics.first.movingaverage.nil?
    replace = true
    metrics = Metric.aggregate_daily_moving_averages(0, "WHERE fulldate > SUBDATE((SELECT fulldate FROM heart_metrics WHERE movingaverage = 0 ORDER BY fulldate desc LIMIT 1), 3)")
  end
  if metrics.first.nil?
    return ''
  end
  movingaverage = metrics.first.movingaverage

  #TODO need to move all these options into the HEART js object, set these at runtime, make them easily customizable in the UI
  extraMeasurements = ''
  label_suffix = ''
  if replace == true
    extraMeasurements = "lines : { show : false, fill : false },"
    label_suffix = ''
  else
    if movingaverage.to_i > 0
      extraMeasurements = 'points : { show : false, symbol : "circle" }, lines : { show : true, fill : false },'
      label_suffix = " [MA:#{movingaverage}] "
    end
  end#if replace = true
  #loop through for all the standard measurements
  metrics.first.attributes.sort.each do |att, value|
    next unless value.respond_to? :to_f
    next if value.is_a? Time
    extraSettings = extraMeasurements
    label = t(att) + label_suffix
    hash[att] = "#{att} : {#{extraSettings} label : '#{label}', data : ["
  end
  #
  # Now start creating the data arrays for flot. [date_converted_to_integer, value_of_metric_for_date]
  #
  metrics.each do |metric|
    metric.attributes.sort.each do |att, value|
      next unless value.respond_to? :to_f
      next if value.is_a? Time
      hash[att] = "#{hash[att]} [#{to_flot_time(metric.fulldate)}, #{value}],"
    end
  end
  #
  # Finished creating data arrays
  #
  metrics.first.attributes.sort.each do |att, value|
    next unless value.respond_to? :to_f
    next if value.is_a? Time
    hash[att] = "#{hash[att]} ], att_name : \"#{att}\",},"
  end

  flotdata = "flotData_#{movingaverage} : {"
  hash.each { |key, value| flotdata += value + "\n" }
  flotdata += "},"
  flotdata
end

#to_flot_time(date) ⇒ Object



26
27
28
# File 'app/helpers/heart/dashboards_helper.rb', line 26

def to_flot_time(date)
  date.to_time.to_i * 1000
end

#tool_tip(options) ⇒ Object



22
23
24
# File 'app/helpers/heart/dashboards_helper.rb', line 22

def tool_tip(options)
  "#{options[:content]}"
end