Module: Adminpanel::AnalyticsHelper

Defined in:
app/helpers/adminpanel/analytics_helper.rb

Instance Method Summary collapse

Instance Method Details

#days_to_substract ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'app/helpers/adminpanel/analytics_helper.rb', line 14

def days_to_substract
  if params[:insight] == 'day'
    1
  elsif params[:insight] == 'week'
    7
  elsif params[:insight] == 'days_28'
    28
  else
    0
  end
end

#divide_metrics(metric_1, metric_2) ⇒ Object



26
27
28
29
30
31
32
33
# File 'app/helpers/adminpanel/analytics_helper.rb', line 26

def divide_metrics(metric_1, metric_2)
  debugger
  if first_fb_value(metric_2) != 0.0
    return first_fb_value(metric_1) / first_fb_value(metric_2)
  else
    return 0
  end
end

#first_fb_value(metric) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/helpers/adminpanel/analytics_helper.rb', line 3

def first_fb_value(metric)
  total = 0.0
  # metric.first['values'].each do |value|
  #   if value['value'] != []
  #     total = total + value['value'].to_f
  #   end
  # end
  # return total
  metric.first['values'].first['value'].to_f
end

#insight ⇒ Object



35
36
37
38
39
40
# File 'app/helpers/adminpanel/analytics_helper.rb', line 35

def insight
  return 'day' if !params[:insight].present?
  return 'day' if params[:insight] == 'day'
  return 'week' if params[:insight] == 'week'
  return 'month' if params[:insight] == 'days_28'
end

#metric(metric) ⇒ Object



42
43
44
# File 'app/helpers/adminpanel/analytics_helper.rb', line 42

def metric(metric)
  metric.first['name']
end