FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make commercial dashboards configurable · devhttps/frontend@1c397ed · GitHub

Commit 1c397ed

Browse files
Make commercial dashboards configurable
So that will work for any A/B test.
1 parent 9c383cc commit 1c397ed

6 files changed

Lines changed: 59 additions & 49 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package controllers.admin.commercial
2+
3+
import java.util.Locale
4+
5+
import jobs.CommercialDfpReporting
6+
import jobs.CommercialDfpReporting.DfpReportRow
7+
import model.{ApplicationContext, NoCache}
8+
import play.api.mvc._
9+
10+
object DashboardRenderer extends Results {
11+
12+
def renderDashboard(testName: String)(implicit request: RequestHeader, context: ApplicationContext): Result = {
13+
val maybeData = for {
14+
reportId <- CommercialDfpReporting.reportMappings.get(CommercialDfpReporting.teamKPIReport)
15+
report: Seq[DfpReportRow] <- CommercialDfpReporting.getReport(reportId)
16+
} yield {
17+
val keyValueRows: Seq[KeyValueRevenueRow] = report.flatMap { row =>
18+
val fields = row.value.split(",").toSeq
19+
for {
20+
customCriteria: String <- fields.lift(0)
21+
customTargetingId: String <- fields.lift(1)
22+
totalImpressions: Int <- fields.lift(2).map(_.toInt)
23+
totalAverageECPM: Double <- fields.lift(3).map(_.toDouble / 1000000.0d) // convert DFP micropounds to pounds
24+
} yield KeyValueRevenueRow(customCriteria, customTargetingId, totalImpressions, totalAverageECPM)
25+
}
26+
27+
keyValueRows
28+
}
29+
30+
val abTestRows = maybeData.getOrElse(Seq.empty)
31+
32+
val controlDataRow = abTestRows.find(_.customCriteria.startsWith(s"ab=${testName}Control"))
33+
val variantDataRow = abTestRows.find(_.customCriteria.startsWith(s"ab=${testName}Variant"))
34+
35+
val integerFormatter = java.text.NumberFormat.getIntegerInstance
36+
val currencyFormatter = java.text.NumberFormat.getCurrencyInstance(Locale.UK)
37+
38+
NoCache(
39+
Ok(views.html.commercial.revenueDashboard(controlDataRow, variantDataRow, integerFormatter, currencyFormatter)))
40+
}
41+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package controllers.admin.commercial
2+
3+
case class KeyValueRevenueRow(
4+
customCriteria: String,
5+
customTargetingId: String,
6+
totalImpressions: Int,
7+
totalAverageECPM: Double
8+
)
Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,17 @@
11
package controllers.admin.commercial
22

3-
import java.util.Locale
4-
53
import common.Logging
6-
import jobs.CommercialDfpReporting
7-
import jobs.CommercialDfpReporting.DfpReportRow
8-
import model.{ApplicationContext, NoCache}
4+
import model.ApplicationContext
95
import play.api.i18n.I18nSupport
106
import play.api.mvc._
117

12-
case class KeyValueRevenueRow(
13-
customCriteria: String,
14-
customTargetingId: String,
15-
totalImpressions: Int,
16-
totalAverageECPM: Double
17-
)
18-
198
class TeamKPIController(val controllerComponents: ControllerComponents)(implicit context: ApplicationContext)
20-
extends BaseController with I18nSupport with Logging {
21-
22-
def renderDashboard(): Action[AnyContent] = Action { implicit request =>
23-
val maybeData = for {
24-
reportId <- CommercialDfpReporting.reportMappings.get(CommercialDfpReporting.teamKPIReport)
25-
report: Seq[DfpReportRow] <- CommercialDfpReporting.getReport(reportId)
26-
} yield {
27-
val keyValueRows: Seq[KeyValueRevenueRow] = report.flatMap { row =>
28-
val fields = row.value.split(",").toSeq
29-
for {
30-
customCriteria: String <- fields.lift(0)
31-
customTargetingId: String <- fields.lift(1)
32-
totalImpressions: Int <- fields.lift(2).map(_.toInt)
33-
totalAverageECPM: Double <- fields.lift(3).map(_.toDouble / 1000000.0d) // convert DFP micropounds to pounds
34-
} yield KeyValueRevenueRow(
35-
customCriteria,
36-
customTargetingId,
37-
totalImpressions,
38-
totalAverageECPM)
39-
}
40-
41-
keyValueRows
42-
}
9+
extends BaseController
10+
with I18nSupport
11+
with Logging {
4312

13+
def renderBaselineDashboard(): Action[AnyContent] = Action { implicit request =>
4414
// The test variants for the team KPIs are commercialBaselineControl-control and commercialBaselineVariant-variant.
45-
val abTestRows = maybeData.getOrElse(Seq.empty)
46-
47-
val controlDataRow = abTestRows.find(_.customCriteria.startsWith("ab=commercialBaselineControl"))
48-
val variantDataRow = abTestRows.find(_.customCriteria.startsWith("ab=commercialBaselineVariant"))
49-
50-
val integerFormatter = java.text.NumberFormat.getIntegerInstance
51-
val currencyFormatter = java.text.NumberFormat.getCurrencyInstance(Locale.UK)
52-
53-
NoCache(Ok(views.html.commercial.revenueDashboard(controlDataRow, variantDataRow, integerFormatter, currencyFormatter)))
15+
DashboardRenderer.renderDashboard("commercialBaseline")
5416
}
55-
56-
}
17+
}

‎admin/app/views/commercial/commercialMenu.scala.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h3>Performance</h3>
1515
<div class="panel-heading">Performance metrics.</div>
1616
<div class="panel-body">
1717
<ul>
18-
<li><a href="@controllers.admin.commercial.routes.TeamKPIController.renderDashboard()">Commercial Team Revenue Dashboard</a></li>
18+
<li><a href="@controllers.admin.commercial.routes.TeamKPIController.renderBaselineDashboard()">Commercial Team Revenue Dashboard</a></li>
1919
<li><a href="@controllers.admin.routes.CommercialController.renderCommercialRadiator()">Commercial Radiator</a></li>
2020
<li><a href="@controllers.admin.routes.CommercialController.renderBrowserPerformanceDashboard()">Real-user advert performance</a></li>
2121
<li><a href="http://dashboards.gu-web.net/s3?list=dotcom-commercial/health/queries">Commercial Health</a></li>

‎admin/app/views/commercial/revenueDashboard.scala.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ <h3 class="test__heading">Variant</h3>
3636
<p class="test__criteria">key value: @{row.customCriteria}</p>
3737
</div>
3838
}
39-
}
39+
}

‎admin/conf/routes‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ GET /commercial/adgrabber/order/:orderId
9393
GET /commercial/adgrabber/previewUrls/:lineItemId/:section controllers.admin.CommercialController.getCreativesListing(lineItemId: String, section: String)
9494
GET /commercial/adops/ads-txt controllers.admin.commercial.AdsDotTextEditController.renderAdsDotText()
9595
POST /commercial/adops/ads-txt controllers.admin.commercial.AdsDotTextEditController.postAdsDotText()
96-
GET /commercial/kpi/revenue controllers.admin.commercial.TeamKPIController.renderDashboard()
96+
GET /commercial/kpi/revenue controllers.admin.commercial.TeamKPIController.renderBaselineDashboard()
9797

9898
# Config
9999

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL