Module: MetricsHelper

Defined in:
app/helpers/metrics_helper.rb

Instance Method Summary collapse

Instance Method Details

#increase_or_decreaseObject



27
28
29
30
31
# File 'app/helpers/metrics_helper.rb', line 27

def increase_or_decrease
  types = [:increase, :decrease, :steady]
  selection = types[rand()*types.length]
  selection
end

#increase_or_decrease_chevron(direction) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'app/helpers/metrics_helper.rb', line 33

def increase_or_decrease_chevron(direction)
  if direction == :increase
    "fa-chevron-up"
  elsif direction == :decrease
    "fa-chevron-down"
  else
    "fa-chevron-down"
  end
end

#increase_or_decrease_class(direction) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'app/helpers/metrics_helper.rb', line 43

def increase_or_decrease_class(direction)
  if direction == :increase
    "text-success"
  elsif direction == :decrease
    "text-danger"
  else
    "text-danger"
  end
end

#metric_namesObject



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

def metric_names
  [{ name: 'Bounce Rate', type: :percent}, {name: 'Cancellations', type: :number}, {name: 'Refunds', type: :dollar},
    {name: 'Charges', value: :dollar}, {name: 'Time on Site', type: :time}, {name: 'Average Revenue per Customer', type: :dollar},
    {name: 'LTV', type: :dollar}, {name: 'Churn', type: :percent}, {name: 'Page Hits', type: :number}, {name: 'Support Queries', type: :number}]
end

#random_dollar_value(min = 10, max = 2000) ⇒ Object



2
3
4
5
# File 'app/helpers/metrics_helper.rb', line 2

def random_dollar_value( min=10, max=2000 )
  random_value = ((max.to_f - min.to_f) * rand() + min).round(0)
  "$#{random_value}"
end

#random_numberObject



12
13
14
15
# File 'app/helpers/metrics_helper.rb', line 12

def random_number
  random_value = ((320.0 - 0.0) * rand()).round(0)
  "#{random_value}"
end

#random_percentObject



7
8
9
10
# File 'app/helpers/metrics_helper.rb', line 7

def random_percent
  random_value = ((100.0 - 0.0) * rand()).round(0)
  "#{random_value}%"
end

#random_steady_dataObject



76
77
78
79
80
81
82
# File 'app/helpers/metrics_helper.rb', line 76

def random_steady_data
  data = []
  (0..7).each do |index|
    data << [index, 5 + rand()]
  end
  data
end


84
85
86
87
88
89
# File 'app/helpers/metrics_helper.rb', line 84

def random_trending_data(direction)
  types = [random_trending_up_data, random_steady_data, random_trending_down_data]
  selection = types[rand*types.length]

  selection
end


67
68
69
70
71
72
73
74
# File 'app/helpers/metrics_helper.rb', line 67

def random_trending_down_data
  data = []
  (0..7).each do |index|
    val = index - rand()
    data << [7-index, val < 0 ? 0 : val]
  end
  data
end


59
60
61
62
63
64
65
# File 'app/helpers/metrics_helper.rb', line 59

def random_trending_up_data
  data = []
  (0..7).each do |index|
    data << [index, index + rand()]
  end
  data
end

#random_value(type) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'app/helpers/metrics_helper.rb', line 17

def random_value(type)
  if type == :dollar
    return random_dollar_value
  elsif type == :percent
    return random_percent
  else
    return random_number
  end
end