| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9c383cc commit 1c397ed
6 files changed
| Original file line number | Diff line number | Diff 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 | + } | ||
| Original file line number | Diff line number | Diff 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 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,56 +1,17 @@ | |||
| 1 | 1 | package controllers.admin.commercial | |
| 2 | 2 | ||
| 3 | - import java.util.Locale | ||
| 4 | - | ||
| 5 | 3 | import common.Logging | |
| 6 | - import jobs.CommercialDfpReporting | ||
| 7 | - import jobs.CommercialDfpReporting.DfpReportRow | ||
| 8 | - import model.{ApplicationContext, NoCache} | ||
| 4 | + import model.ApplicationContext | ||
| 9 | 5 | import play.api.i18n.I18nSupport | |
| 10 | 6 | import play.api.mvc._ | |
| 11 | 7 | ||
| 12 | - case class KeyValueRevenueRow( | ||
| 13 | - customCriteria: String, | ||
| 14 | - customTargetingId: String, | ||
| 15 | - totalImpressions: Int, | ||
| 16 | - totalAverageECPM: Double | ||
| 17 | - ) | ||
| 18 | - | ||
| 19 | 8 | 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 { | ||
| 43 | 12 | ||
| 13 | + def renderBaselineDashboard(): Action[AnyContent] = Action { implicit request => | ||
| 44 | 14 | // 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") | ||
| 54 | 16 | } | |
| 55 | - | ||
| 56 | - } | ||
| 17 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ <h3>Performance</h3> | |||
| 15 | 15 | <div class="panel-heading">Performance metrics.</div> | |
| 16 | 16 | <div class="panel-body"> | |
| 17 | 17 | <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> | ||
| 19 | 19 | <li><a href="@controllers.admin.routes.CommercialController.renderCommercialRadiator()">Commercial Radiator</a></li> | |
| 20 | 20 | <li><a href="@controllers.admin.routes.CommercialController.renderBrowserPerformanceDashboard()">Real-user advert performance</a></li> | |
| 21 | 21 | <li><a href="http://dashboards.gu-web.net/s3?list=dotcom-commercial/health/queries">Commercial Health</a></li> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,4 +36,4 @@ <h3 class="test__heading">Variant</h3> | |||
| 36 | 36 | <p class="test__criteria">key value: @{row.customCriteria}</p> | |
| 37 | 37 | </div> | |
| 38 | 38 | } | |
| 39 | - } | ||
| 39 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -93,7 +93,7 @@ GET /commercial/adgrabber/order/:orderId | |||
| 93 | 93 | GET /commercial/adgrabber/previewUrls/:lineItemId/:section controllers.admin.CommercialController.getCreativesListing(lineItemId: String, section: String) | |
| 94 | 94 | GET /commercial/adops/ads-txt controllers.admin.commercial.AdsDotTextEditController.renderAdsDotText() | |
| 95 | 95 | 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() | ||
| 97 | 97 | ||
| 98 | 98 | # Config | |
| 99 | 99 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments