Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation changes to only count paid eligible ads #798

Merged
merged 2 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adserver/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,7 @@ class AdImpression(BaseImpression):
advertisement = models.ForeignKey(
Advertisement, related_name="impressions", on_delete=models.PROTECT, null=True
)
# This field is the sum of all the view time for each ad for this publisher each day
view_time = models.PositiveIntegerField(
_("Seconds that the ad was in view"),
null=True,
Expand Down
8 changes: 8 additions & 0 deletions adserver/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def daily_update_geos(day=None, geo=True, region=True):
}
)
queryset = Offer.objects.using(settings.REPLICA_SLUG).filter(
# For region and topic reports, we are excluding ads that were ineligible to be paid
# from the aggregations unless the publisher isn't approved for paid ads.
# This will give us more accurate KPIs on fill rates for paid publishers.
Q(paid_eligible=True) | Q(publisher__allow_paid_campaigns=False),
davidfischer marked this conversation as resolved.
Show resolved Hide resolved
date__gte=start_date,
date__lt=end_date, # Things at UTC midnight should count towards tomorrow
)
Expand Down Expand Up @@ -374,6 +378,10 @@ def daily_update_regiontopic(day=None):
}
)
queryset = Offer.objects.using(settings.REPLICA_SLUG).filter(
# For region and topic reports, we are excluding ads that were ineligible to be paid
# from the aggregations unless the publisher isn't approved for paid ads.
# This will give us more accurate KPIs on fill rates for paid publishers.
Q(paid_eligible=True) | Q(publisher__allow_paid_campaigns=False),
date__gte=start_date,
date__lt=end_date, # Things at UTC midnight should count towards tomorrow
)
Expand Down
70 changes: 62 additions & 8 deletions adserver/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,35 @@ def test_global_keyword_report_contents(self):
self.assertNotContains(response, "CSV Export")

def test_global_geo_report_contents(self):
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="FR", viewed=True, clicked=True)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="FR",
paid_eligible=True,
viewed=True,
clicked=True,
)

# Update reporting
daily_update_geos()
Expand Down Expand Up @@ -832,10 +857,35 @@ def test_global_geo_report_contents(self):
self.assertNotContains(response, "CSV Export")

def test_global_region_report_contents(self):
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="US", viewed=True)
get(Offer, publisher=self.publisher1, country="MX", viewed=True, clicked=True)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="US",
paid_eligible=True,
viewed=True,
)
get(
Offer,
publisher=self.publisher1,
country="MX",
paid_eligible=True,
viewed=True,
clicked=True,
)

# Update reporting
daily_update_geos()
Expand Down Expand Up @@ -872,6 +922,7 @@ def test_staff_regiontopic_report_contents(self):
publisher=self.publisher1,
keywords=["javascript"],
country="US",
paid_eligible=True,
viewed=True,
)
get(
Expand All @@ -880,6 +931,7 @@ def test_staff_regiontopic_report_contents(self):
publisher=self.publisher1,
keywords=["javascript"],
country="US",
paid_eligible=True,
viewed=True,
)
get(
Expand All @@ -888,6 +940,7 @@ def test_staff_regiontopic_report_contents(self):
publisher=self.publisher1,
keywords=["javascript"],
country="US",
paid_eligible=True,
viewed=True,
)
get(
Expand All @@ -896,6 +949,7 @@ def test_staff_regiontopic_report_contents(self):
publisher=self.publisher1,
keywords=["python"],
country="MX",
paid_eligible=True,
viewed=True,
clicked=True,
)
Expand Down