Module: Adminpanel::AnalyticsHelper

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

Instance Method Summary collapse

Instance Method Details

#days_to_substractObject



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
# File 'app/helpers/adminpanel/analytics_helper.rb', line 26

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

#exist_instagram_account?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
55
# File 'app/helpers/adminpanel/analytics_helper.rb', line 49

def exist_instagram_account?
  if @instagram_token.nil?
    false
  else
    true
  end
end

#exist_twitter_account?Boolean

Returns:

  • (Boolean)


57
58
59
60
61
62
63
# File 'app/helpers/adminpanel/analytics_helper.rb', line 57

def exist_twitter_account?
  if @twitter_token.nil? || @twitter_secret.nil?
    false
  else
    true
  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'].last['value'].to_f
end

#insightObject



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

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



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

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


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

def tweet_link(tweet)
  "http://www.twitter.com/#{tweet.user.screen_name}/status/#{tweet.id}"
end