Class: FacebookApp::ConversionSummary

Inherits:
Object
  • Object
show all
Defined in:
app/models/facebook_app/conversion_summary.rb

Instance Method Summary collapse

Instance Method Details

#denied_state_count(marketing_mode) ⇒ Object



33
34
35
# File 'app/models/facebook_app/conversion_summary.rb', line 33

def denied_state_count(marketing_mode)
  state_count(:denied_permissions, marketing_mode).to_s
end

#funnel(from_state, to_state, marketing_type = :all) ⇒ Object



15
16
17
18
19
# File 'app/models/facebook_app/conversion_summary.rb', line 15

def funnel(from_state, to_state, marketing_type=:all)
  state_count(to_state, marketing_type).fdiv(state_count(from_state, marketing_type)) * 100
rescue ZeroDivisionError
  "Cannot compute yet"
end

#infographic_state_count(marketing_mode) ⇒ Object



37
38
39
# File 'app/models/facebook_app/conversion_summary.rb', line 37

def infographic_state_count(marketing_mode)
  state_count(:generated_infographic, marketing_mode).to_s
end

#installed_state_count(marketing_mode) ⇒ Object



29
30
31
# File 'app/models/facebook_app/conversion_summary.rb', line 29

def installed_state_count(marketing_mode)
  state_count(:installed, marketing_mode).to_s
end

#percentage_of_total(state, marketing_mode) ⇒ Object



9
10
11
12
13
# File 'app/models/facebook_app/conversion_summary.rb', line 9

def percentage_of_total(state, marketing_mode)
  (send(state, marketing_mode).to_i / splash_page_state_count(marketing_mode).to_i).to_s
  rescue
    "Cannot compute yet"
end

#permissions_state_count(marketing_mode) ⇒ Object



25
26
27
# File 'app/models/facebook_app/conversion_summary.rb', line 25

def permissions_state_count(marketing_mode)
  state_count(:permissions_dialogue, marketing_mode).to_s
end

#signed_up_identified_state_count(marketing_mode) ⇒ Object



45
46
47
# File 'app/models/facebook_app/conversion_summary.rb', line 45

def signed_up_identified_state_count(marketing_mode)
  state_count(:signed_up_identified, marketing_mode).to_s
end

#splash_page_state_count(marketing_mode) ⇒ Object



21
22
23
# File 'app/models/facebook_app/conversion_summary.rb', line 21

def splash_page_state_count(marketing_mode)
  state_count(:splash_page, marketing_mode).to_s
end

#state_count(state_to_calculate, marketing_mode) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'app/models/facebook_app/conversion_summary.rb', line 49

def state_count(state_to_calculate, marketing_mode)
  case marketing_mode
  when :all
    Conversion.count(:conditions => state_fragment(state_to_calculate))
  when nil
    Conversion.count(:conditions => "marketing_mode is null AND #{state_fragment(state_to_calculate)}")
  else
    Conversion.count(:conditions => "marketing_mode='#{marketing_mode.to_s}' AND #{state_fragment(state_to_calculate)}") 
  end
end

#state_fragment(state_to_calculate) ⇒ Object

reasoning behind this method is that stats are accumulative. somethign in the infographic state had previously been installed as per state machine



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/facebook_app/conversion_summary.rb', line 63

def state_fragment(state_to_calculate)
  case state_to_calculate 
  when :splash_page
    "state in ('splash_page', 'generated_infographic', 'denied_permissions', 'denied_extended_permissions', 'installed', 'signed_up_for_identified', 'permissions_dialogue', 'subscribed')"
  when :permissions_dialogue
    "state in ('generated_infographic', 'denied_permissions', 'denied_extended_permissions', 'installed', 'signed_up_for_identified', 'permissions_dialogue', 'subscribed')"
  when :installed
    "state in ('installed', 'generated_infographic', 'signed_up_for_identified', 'subscribed')"
  when :generated_infographic
    "state in ('generated_infographic', 'signed_up_for_identified', 'subscribed')"
  else
    "state = '#{state_to_calculate.to_s}'"
  end
end

#subscribed_state_count(marketing_mode) ⇒ Object



41
42
43
# File 'app/models/facebook_app/conversion_summary.rb', line 41

def subscribed_state_count(marketing_mode)
  state_count(:subscribed, marketing_mode).to_s
end

#virality_coefficient(state) ⇒ Object



4
5
6
7
# File 'app/models/facebook_app/conversion_summary.rb', line 4

def virality_coefficient(state)
  all_known = send(state, :viral).to_i + send(state, :advertising).to_i
  (send(state, :viral).to_i.fdiv(all_known.to_i)*100).to_s
end