patient_zero 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03269ba3e5c9a827db9b792e661a832ae788e935
4
- data.tar.gz: b132a2af9830d3916c4d6fe1bad35b226387fdbf
3
+ metadata.gz: e8c596e88ae22ea81ab58ec1e429803dbeef9fc9
4
+ data.tar.gz: 6a95d5e7301c2d817dc372ae5c885c2ae2e7b4c3
5
5
  SHA512:
6
- metadata.gz: 9ca2d5e5f070ac5055f6bfc71d0e0cb35a0da384a2bb67b5bceb9d055c1ddf2d0f69ddf76e754969e6dc01c4e948c8cea006a353df691341c7b9fd8a67be93ef
7
- data.tar.gz: 8eeed15f2a9325b4db810528e896646e1fbe7d064d43728d2accb6238d39e5308ee0458a2580d2457ef504e3c0b9a7aa49ef9f0284fca9c1a464be58f9077423
6
+ metadata.gz: cab0fb75293cb27e2fe330ceb30782cee6648a1247521f4b89d1ace340942db2e189fdc7f1e90d5906804c38f7807cdd5a8e3cea630158ab684251412ce7e8b9
7
+ data.tar.gz: 99c069e546181406352010c78efdc8a1eb116d5a03a7d4d8cbc0dc93f6fe53d8ea6101113e1b5e14e91fea1392a718f8b7a338c820506fec8d1ff70360fd192b
@@ -32,6 +32,25 @@ module PatientZero
32
32
  unknown: gender_stats.fetch('U', 0) }
33
33
  end
34
34
 
35
+ def page_likes_by_age_and_gender
36
+ data = analytical_data.fetch('likes_by_age_group',[])
37
+ female = data.find { |datum| datum.values.include? 'Females Users' }
38
+ male = data.find { |datum| datum.values.include? 'Males Users' }
39
+ { female: female.to_h.fetch('values',{}),
40
+ male: male.to_h.fetch('values',{}) }
41
+ end
42
+
43
+ def page_likes_by_gender
44
+ gender_stats = analytical_data['likes_by_gender']
45
+ { female: gender_stats.fetch('F', 0),
46
+ male: gender_stats.fetch('M', 0),
47
+ unknown: gender_stats.fetch('U', 0) }
48
+ end
49
+
50
+ def total_page_likes
51
+ page_likes_by_gender.values.reduce(:+)
52
+ end
53
+
35
54
  def organic_impressions
36
55
  find_impressions 'Organic'
37
56
  end
@@ -1,3 +1,3 @@
1
1
  module PatientZero
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
@@ -25,13 +25,21 @@ module PatientZero
25
25
  let(:impressions_by_gender) { {"F"=>100_000, "M"=>70_000, "U"=>10_000} }
26
26
  let(:age_data) { {"13-17"=>14_000, "18-24"=>240_000, "25-34"=>650_000, "35-44"=>660_000, "45-54"=>380_000, "55-64"=>170_000, "65+"=>93_000} }
27
27
  let(:total_reach) { [ { 'key'=>'Total Reach', 'values'=> { '2010-10-10'=> 4567 } } ] }
28
+ let(:likes_by_age_group) do
29
+ [{"key"=>"Females Users", "values"=> {"13-17"=>4000, "18-24"=>60000, "25-34"=>152000, "35-44"=>199000, "45-54"=>115000, "55-64"=>32000, "65+"=>1424000}},
30
+ {"key"=>"Males Users", "values"=> {"13-17"=>2000, "18-24"=>40000, "25-34"=>58000, "35-44"=>68000, "45-54"=>46000, "55-64"=>14000, "65+"=>7000}}]
31
+ end
32
+ let(:likes_by_gender) { {"F"=>570000, "M"=>230000, "U"=>5000} }
28
33
  let(:analytical_data) do
29
34
  { 'messages' => messages,
30
35
  'page_impressions' => page_impressions,
31
36
  'impressions_by_cities' => impressions_by_city,
32
37
  'impressions_by_ages' => impressions_by_age,
33
38
  'impressions_by_genders' => impressions_by_gender,
34
- 'total_reach' => total_reach }
39
+ 'total_reach' => total_reach,
40
+ 'likes_by_gender' => likes_by_gender,
41
+ 'likes_by_age_group' => likes_by_age_group,
42
+ }
35
43
  end
36
44
  let(:facebook_analytics) { Facebook.new token: token, source_id: source_id }
37
45
  before{ allow(facebook_analytics).to receive(:analytical_data).and_return analytical_data }
@@ -63,6 +71,33 @@ module PatientZero
63
71
  end
64
72
  end
65
73
 
74
+ describe '#page_likes_by_age_and_gender' do
75
+ it 'formats and returns the correct results' do
76
+ age_and_gender_data = {
77
+ female: {"13-17"=>4000, "18-24"=>60000, "25-34"=>152000, "35-44"=>199000, "45-54"=>115000, "55-64"=>32000, "65+"=>1424000},
78
+ male: {"13-17"=>2000, "18-24"=>40000, "25-34"=>58000, "35-44"=>68000, "45-54"=>46000, "55-64"=>14000, "65+"=>7000}
79
+ }
80
+ expect(facebook_analytics.page_likes_by_age_and_gender).to eq age_and_gender_data
81
+ end
82
+ end
83
+
84
+ describe '#page_likes_by_gender' do
85
+ it 'returns the likes by gender' do
86
+ expected_result = {
87
+ female: likes_by_gender['F'],
88
+ male: likes_by_gender['M'],
89
+ unknown: likes_by_gender['U']
90
+ }
91
+ expect(facebook_analytics.page_likes_by_gender).to eq expected_result
92
+ end
93
+ end
94
+
95
+ describe '#total_page_likes' do
96
+ it 'calculates the total likes correctly' do
97
+ expect(facebook_analytics.total_page_likes).to eq 805000
98
+ end
99
+ end
100
+
66
101
  describe '#impressions' do
67
102
  it 'returns the total for message and page impressions' do
68
103
  expect(facebook_analytics.impressions).to eq 444
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patient_zero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Zaninovich
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.2.2
186
+ rubygems_version: 2.4.5
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: A gem to use the Viral Heat API