Skip to content

Commit

Permalink
Merge branch 'master' into kc-masterclasses-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvin-chappell committed May 3, 2016
2 parents d05b73e + 72a0464 commit 908a403
Show file tree
Hide file tree
Showing 103 changed files with 1,577 additions and 892 deletions.
9 changes: 7 additions & 2 deletions admin/app/controllers/admin/CommercialController.scala
Expand Up @@ -31,8 +31,8 @@ object CommercialController extends Controller with Logging with AuthLogging wit
NoCache(Ok(views.html.commercial.commercialMenu(environment.stage)))
}

def renderCommercial = AuthActions.AuthActionTest { implicit request =>
NoCache(Ok(views.html.commercial.commercial(environment.stage)))
def renderCommercialRenderTimes = AuthActions.AuthActionTest { implicit request =>
NoCache(Ok(views.html.commercial.commercialRenderTimes(environment.stage)))
}

def renderFluidAds = AuthActions.AuthActionTest { implicit request =>
Expand Down Expand Up @@ -64,6 +64,11 @@ object CommercialController extends Controller with Logging with AuthLogging wit
NoCache(Ok(views.html.commercial.inlineMerchandisingTargetedTags(environment.stage, report)))
}

def renderHighMerchandisingTargetedTags = AuthActions.AuthActionTest { implicit request =>
val report = Store.getDfpHighMerchandisingTargetedTagsReport()
NoCache(Ok(views.html.commercial.highMerchandisingTargetedTags(environment.stage, report)))
}

def renderCreativeTemplates = AuthActions.AuthActionTest { implicit request =>
val emptyTemplates = CreativeTemplateAgent.get
val creatives = Store.getDfpTemplateCreatives
Expand Down
4 changes: 4 additions & 0 deletions admin/app/dfp/DfpDataCacheJob.scala
Expand Up @@ -165,6 +165,10 @@ object DfpDataCacheJob extends ExecutionContexts with Logging {
Store.putInlineMerchandisingSponsorships(stringify(toJson(
InlineMerchandisingTargetedTagsReport(now, inlineMerchandisingTargetedTags))))

val highMerchandisingTargetedTags = data.highMerchandisingTargetedTags
Store.putHighMerchandisingSponsorships(stringify(toJson(
HighMerchandisingTargetedTagsReport(now, highMerchandisingTargetedTags))))

val pageSkinSponsorships = data.pageSkinSponsorships
Store.putDfpPageSkinAdUnits(stringify(toJson(PageSkinSponsorshipReport(now,
pageSkinSponsorships))))
Expand Down
14 changes: 13 additions & 1 deletion admin/app/dfp/DfpDataExtractor.scala
@@ -1,7 +1,7 @@
package dfp

import common.Edition
import common.dfp.{GeoTarget, GuLineItem, InlineMerchandisingTagSet, PageSkinSponsorship}
import common.dfp._

case class DfpDataExtractor(lineItems: Seq[GuLineItem]) {

Expand All @@ -15,6 +15,18 @@ case class DfpDataExtractor(lineItems: Seq[GuLineItem]) {
}
}

val highMerchandisingTargetedTags: HighMerchandisingLineItems = {

lineItems.foldLeft(HighMerchandisingLineItems(items = List.empty)) { (soFar, lineItem) =>
if (lineItem.highMerchandisingTargets.isEmpty) {
soFar
} else {
soFar.copy(items = soFar.items :+ HighMerchandisingLineItem(
lineItem.name, lineItem.id, lineItem.highMerchandisingTargets))
}
}
}

val pageSkinSponsorships: Seq[PageSkinSponsorship] = {
lineItems withFilter { lineItem =>
lineItem.isPageSkin && lineItem.isCurrent
Expand Down
42 changes: 15 additions & 27 deletions admin/app/jobs/RefreshFrontsJob.scala
@@ -1,10 +1,9 @@
package jobs

import common.Logging
import services.{S3FrontsApi, FrontPressNotification}
import play.api.libs.json.{JsString, JsObject, JsValue, Json}
import conf.switches.Switches._
import com.gu.facia.api.models.{CommercialPriority, EditorialPriority, TrainingPriority}
import common.{ExecutionContexts, Logging}
import conf.Configuration
import services.{ConfigAgent, FrontPressNotification}

sealed trait FrontType

Expand All @@ -17,37 +16,27 @@ object HighFrequency extends FrontType {

case class CronUpdate(path: String, frontType: FrontType)

object RefreshFrontsJob extends Logging {
def getAllCronUpdates: Option[Seq[CronUpdate]] = {
val masterConfigJson: Option[JsValue] = S3FrontsApi.getMasterConfig.map(Json.parse)
for (json <- masterConfigJson)
yield
(for {
path <- (json \ "fronts").asOpt[Map[String, JsValue]].getOrElse(Map.empty).keys
} yield {
CronUpdate(path, getFrontType(json, path))
}).toSeq
object RefreshFrontsJob extends Logging with ExecutionContexts {
def getAllCronUpdates: Seq[CronUpdate] = {
ConfigAgent.getPathIds.map(path => CronUpdate(path, getFrontType(path)))
}

def getFrontType(json: JsValue, path: String): FrontType = {
lazy val isCommercial: Boolean = (json \ "fronts" \ path \ "priority") == JsString("commercial")
lazy val isTraining: Boolean = (json \ "fronts" \ path \ "priority") == JsString("training")
def getFrontType(path: String): FrontType = {
if (HighFrequency.highFrequencyPaths.contains(path))
HighFrequency
else if (isCommercial || isTraining)
LowFrequency
else
StandardFrequency
ConfigAgent.getFrontPriorityFromConfig(path) match {
case Some(EditorialPriority) => StandardFrequency
case Some(CommercialPriority) => LowFrequency
case Some(TrainingPriority) => LowFrequency
case None => LowFrequency
}
}

def runFrequency(frontType: FrontType): Boolean = {
if (Configuration.aws.frontPressSns.filter(_.nonEmpty).isDefined) {
log.info(s"Putting press jobs on Facia Cron $frontType")

for {
updates <- getAllCronUpdates
update <- updates.filter(_.frontType == frontType)
} {
for (update <- getAllCronUpdates.filter(_.frontType == frontType)) {
log.info(s"Pressing $update")
FrontPressNotification.sendWithoutSubject(update.path)
}
Expand All @@ -63,8 +52,7 @@ object RefreshFrontsJob extends Logging {
def runAll(): Option[Seq[Unit]] = {
Configuration.aws.frontPressSns.map(Function.const {
log.info("Putting press jobs on Facia Cron (MANUAL REQUEST)")

for {update <- getAllCronUpdates.getOrElse(Nil)}
for (update <- getAllCronUpdates)
yield {
log.info(s"Pressing $update")
FrontPressNotification.sendWithoutSubject(update.path)}})
Expand Down
7 changes: 7 additions & 0 deletions admin/app/tools/Store.scala
Expand Up @@ -30,6 +30,9 @@ trait Store extends Logging with Dates {
def putInlineMerchandisingSponsorships(keywordsJson: String) {
S3.putPublic(dfpInlineMerchandisingTagsDataKey, keywordsJson, defaultJsonEncoding)
}
def putHighMerchandisingSponsorships(keywordsJson: String) {
S3.putPublic(dfpHighMerchandisingTagsDataKey, keywordsJson, defaultJsonEncoding)
}
def putDfpPageSkinAdUnits(adUnitJson: String) {
S3.putPublic(dfpPageSkinnedAdUnitsKey, adUnitJson, defaultJsonEncoding )
}
Expand Down Expand Up @@ -66,6 +69,10 @@ trait Store extends Logging with Dates {
S3.get(dfpInlineMerchandisingTagsDataKey) flatMap (InlineMerchandisingTargetedTagsReportParser(_))
} getOrElse InlineMerchandisingTargetedTagsReport(now, InlineMerchandisingTagSet())

def getDfpHighMerchandisingTargetedTagsReport(): HighMerchandisingTargetedTagsReport = {
S3.get(dfpHighMerchandisingTagsDataKey) flatMap (HighMerchandisingTargetedTagsReportParser(_))
} getOrElse HighMerchandisingTargetedTagsReport(now, HighMerchandisingLineItems(items = List.empty))

def getDfpLineItemsReport(): Option[String] = S3.get(dfpLineItemsKey)

def getSlotTakeoversReport(slotName: String): Option[String] = slotName match {
Expand Down
7 changes: 0 additions & 7 deletions admin/app/views/commercial/commercialMain.scala.html

This file was deleted.

3 changes: 2 additions & 1 deletion admin/app/views/commercial/commercialMenu.scala.html
Expand Up @@ -16,7 +16,7 @@ <h3>Performance</h3>
<div class="panel-body">
<ul>
<li><a href="@controllers.admin.routes.CommercialController.renderCommercialRadiator()">Commercial Radiator</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderCommercial()">Slot Load Times</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderCommercialRenderTimes()">Slot Load Times</a></li>
<li><a href="https://dashboard.ophan.co.uk/ads">Ophan: Slot Load Times</a></li>
<li><a href="http://tableau-dev.gutools.co.uk:8099/views/ViewabilityABTest/KPIAB">Viewability: A/B Tests</a></li>
<li><a href="http://tableau-dev.gutools.co.uk:8099/views/ViewabilityDashSecondDraft/Health-SlotSizeBrowser">Viewability: Slot Performance</a></li>
Expand All @@ -36,6 +36,7 @@ <h3>Targeting</h3>
<li><a href="@controllers.admin.routes.CommercialController.renderSpecialAdUnits()">Special Ad Units</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderPaidForTags()">Paid-For Tags</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderInlineMerchandisingTargetedTags()">Inline Merchandising Slot</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderHighMerchandisingTargetedTags()">High Merchandising Slot</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderPageskins()">Pageskins</a></li>
<li><a href="@controllers.admin.routes.CommercialController.renderSurgingContent()">Surging Content</a></li>
<li><a href="@controllers.admin.routes.CommercialAdUnitController.renderToApprove()">Ad Units for approval</a></li>
Expand Down
@@ -0,0 +1,33 @@
@(env: String, report: dfp.HighMerchandisingTargetedTagsReport)(implicit request: RequestHeader)
@import tools.DfpLink

@admin_main("Commercial High Slot", env, isAuthed = true, hasCharts = false) {

<link rel="stylesheet" type="text/css" href="@controllers.admin.routes.UncachedAssets.at(" css/commercial.css")">

<h1>High Merchandising Line Items</h1>

<em style="float: right">Last updated: @report.updatedTimeStamp</em>

@if(report.lineItems.items.isEmpty) {<p>None</p>} else {
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th>Line Item Name</th>
<th>DFP link</th>
<th>Keywords</th>
</tr>
</thead>
<tbody>
@for(lineItem <- report.lineItems.sortedItems) {
<tr>
<td>@{lineItem.name}</td>
<td><a href="@DfpLink.lineItem(lineItem.id)">@{lineItem.id}</a></td>
<td>@{lineItem.tags.mkString(", ")}</td>
</tr>
}
</tbody>
</table>
}

}
5 changes: 4 additions & 1 deletion admin/app/views/commercial/slotTop.scala.html
@@ -1,7 +1,10 @@
@import common.dfp.LineItemReport
@(env: String, slotReport: LineItemReport)(implicit request: RequestHeader)

@views.html.commercial.commercialMain(env, "Mobile Top Slot") {
@admin_main("Commercial: Mobile Top Slot", env, isAuthed = true) {
<link rel="stylesheet" type="text/css" href="@controllers.admin.routes.UncachedAssets.at("css/commercial.css")">
<h2>Mobile Top Slot</h2>

<h4>Rules:</h4>
<p>This slot will only open if there is an ad that:</p>
<ul>
Expand Down
5 changes: 4 additions & 1 deletion admin/app/views/commercial/slotTopAboveNav.scala.html
@@ -1,7 +1,10 @@
@import common.dfp.LineItemReport
@(env: String, slotReport: LineItemReport)(implicit request: RequestHeader)

@views.html.commercial.commercialMain(env, "Desktop Top-Above-Nav Slot") {
@admin_main("Commercial: Desktop Top-Above-Nav Slot", env, isAuthed = true) {
<link rel="stylesheet" type="text/css" href="@controllers.admin.routes.UncachedAssets.at("css/commercial.css")">
<h2>Desktop Top-Above-Nav Slot</h2>

<h4>Rules:</h4>
<p>This slot will by default accommodate an ad of height 250px on business fronts unless there is an ad that:</p>
<ul>
Expand Down
5 changes: 4 additions & 1 deletion admin/app/views/commercial/slotTopBelowNav.scala.html
@@ -1,7 +1,10 @@
@import common.dfp.LineItemReport
@(env: String, slotReport: LineItemReport)(implicit request: RequestHeader)

@views.html.commercial.commercialMain(env, "Desktop Top-Below-Nav Slot") {
@admin_main("Commercial: Desktop Top-Below-Nav Slot", env, isAuthed = true) {
<link rel="stylesheet" type="text/css" href="@controllers.admin.routes.UncachedAssets.at("css/commercial.css")">
<h2>Desktop Top-Below-Nav Slot</h2>

<h4>Rules:</h4>
<p>This slot will only open if there is an ad that:</p>
<ul>
Expand Down

0 comments on commit 908a403

Please sign in to comment.