Skip to content

Commit

Permalink
Merge pull request #1487 from glogiotatidis/issue-1486
Browse files Browse the repository at this point in the history
[Fix #1486] Fix Fundraising ETL for clicks.
  • Loading branch information
glogiotatidis committed Dec 7, 2020
2 parents 9592370 + b50a0c3 commit 16fc02b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion snippets/base/admin/adminmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ class JobDailyPerformanceAdmin(admin.ModelAdmin):
'adj_client_percentage',
'data_fetched_on',
]
search_fields = ['job']
search_fields = ['id', 'job__id', 'job__snippet__id']
fieldsets = [
('Metrics', {
'fields': (
Expand Down
7 changes: 6 additions & 1 deletion snippets/base/etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def process_rows(rows, date, key='message_id'):
# place the event context. Extract information from both
# places to identify the event.
properties = json.loads(row.get('additional_properties', '{}'))
event = row['event_context'] or properties.get('value', '') or row['event']

# Fundraising metrics need special treatment.
if row['event_context'] == 'EOYSnippetForm' and row['event'] == 'CLICK_BUTTON':
event = 'CLICK'
else:
event = row['event_context'] or properties.get('value', '') or row['event']

if event in ['CLICK_BUTTON', 'CLICK']:
event = 'click'
Expand Down
17 changes: 15 additions & 2 deletions snippets/base/tests/test_etl.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,19 @@ def test_base(self):
'no_clients': 50,
'no_clients_total': 0,
},
{
'message_id': '1000',
'event_context': 'EOYSnippetForm',
'event': 'CLICK_BUTTON',
'additional_properties': (
'{"source":"NEWTAB_FOOTER_BAR_CONTENT","id":"NEWTAB_FOOTER_BAR_CONTENT"}'
),
'channel': 'release',
'country_code': 'IT',
'counts': 10,
'no_clients': 4,
'no_clients_total': 0,
},
# To be discarded
{
'message_id': '500',
Expand Down Expand Up @@ -216,14 +229,14 @@ def test_base(self):
jdp1 = JobDailyPerformance.objects.filter(job_id=1000).order_by('-id')[0]
self.assertEqual(jdp1.impression, 80)
self.assertEqual(jdp1.impression_no_clients_total, 653)
self.assertEqual(jdp1.click, 11)
self.assertEqual(jdp1.click, 21)
self.assertEqual(jdp1.block, 50)
self.assertEqual(jdp1.dismiss, 0)
self.assertEqual(jdp1.go_to_scene2, 0)
self.assertEqual(jdp1.subscribe_error, 0)
self.assertEqual(jdp1.subscribe_success, 0)
self.assertEqual(jdp1.other_click, 0)
self.assertEqual(len(jdp1.details), 5)
self.assertEqual(len(jdp1.details), 6)
for detail in [
{'event': 'click', 'counts': 11, 'channel': 'release',
'country': 'GR', 'no_clients': 12, 'no_clients_total': 0},
Expand Down

0 comments on commit 16fc02b

Please sign in to comment.