From 0821b16eb84cede7cea4e1aee0bb3bdda2e60088 Mon Sep 17 00:00:00 2001 From: David Fischer Date: Mon, 19 Feb 2024 16:35:36 -0800 Subject: [PATCH] Add publisher eCPM to report table --- adserver/reports.py | 6 ++++++ .../adserver/reports/includes/publisher-report-table.html | 7 +++++-- adserver/tests/test_reports.py | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/adserver/reports.py b/adserver/reports.py index f5d19991..35ff0a25 100644 --- a/adserver/reports.py +++ b/adserver/reports.py @@ -264,6 +264,9 @@ def generate(self): results[index]["revenue_share"] = results[index]["revenue"] * ( applied_rev_share / 100.0 ) + results[index]["revenue_share_ecpm"] = calculate_ecpm( + results[index]["revenue_share"], results[index]["views"] + ) results[index]["our_revenue"] = ( results[index]["revenue"] - results[index]["revenue_share"] ) @@ -301,6 +304,9 @@ def calculate_totals(self): self.total["revenue_share"] = sum( result["revenue_share"] for result in self.results ) + self.total["revenue_share_ecpm"] = calculate_ecpm( + self.total["revenue_share"], self.total["views"] + ) self.total["our_revenue"] = self.total["revenue"] - self.total["revenue_share"] self.total["ctr"] = calculate_ctr(self.total["clicks"], self.total["views"]) self.total["ecpm"] = calculate_ecpm(self.total["revenue"], self.total["views"]) diff --git a/adserver/templates/adserver/reports/includes/publisher-report-table.html b/adserver/templates/adserver/reports/includes/publisher-report-table.html index 07657074..e4785164 100644 --- a/adserver/templates/adserver/reports/includes/publisher-report-table.html +++ b/adserver/templates/adserver/reports/includes/publisher-report-table.html @@ -10,9 +10,10 @@ {% blocktrans %}CTR{% endblocktrans %} {% blocktrans %}View Rate{% endblocktrans %} {% if publisher.saas %} - {% blocktrans %}API Requests{% endblocktrans %} + {% blocktrans %}API Requests{% endblocktrans %} {% else %} - {% trans 'Revenue' %} + {% blocktrans %}eCPM{% endblocktrans %} + {% trans 'Revenue' %} {% endif %} {% if "adserver.staff_publisher_fields" in perms %} {% trans 'Our Rev' %} @@ -34,6 +35,7 @@ {% if publisher.saas %} {{ result.decisions|intcomma }} {% else %} + ${{ result.revenue_share_ecpm|floatformat:2|intcomma }} ${{ result.revenue_share|floatformat:2|intcomma }} {% endif %} {% if "adserver.staff_publisher_fields" in perms %} @@ -54,6 +56,7 @@ {% if publisher.saas %} {{ report.total.decisions|intcomma }} {% else %} + ${{ report.total.revenue_share_ecpm|floatformat:2|intcomma }} ${{ report.total.revenue_share|floatformat:2|intcomma }} {% endif %} {% if "adserver.staff_publisher_fields" in perms %} diff --git a/adserver/tests/test_reports.py b/adserver/tests/test_reports.py index cb427eeb..fad93de4 100644 --- a/adserver/tests/test_reports.py +++ b/adserver/tests/test_reports.py @@ -557,7 +557,7 @@ def test_publisher_report_contents(self): self.assertContains(response, "CSV Export") # Check staff fields not present since the permission wasn't configured - self.assertNotContains(response, "eCPM") + self.assertNotContains(response, "Fill Rate") # Add the permission self.staff_user.user_permissions.add( @@ -567,7 +567,7 @@ def test_publisher_report_contents(self): ) ) response = self.client.get(url) - self.assertContains(response, "eCPM") + self.assertContains(response, "Fill Rate") def test_publisher_placement_report_contents(self): self.client.force_login(self.staff_user)