Skip to content

Commit

Permalink
include network front referral indicator on recent content
Browse files Browse the repository at this point in the history
highlight content where we've seen a referral from the
network front on the recent content list
  • Loading branch information
tackley committed Feb 22, 2012
1 parent 7034439 commit 60e25b7
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 16 deletions.
11 changes: 5 additions & 6 deletions app/controllers/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ object Api extends Controller {
Ok(callback map { _ + "(" + block + ")" } getOrElse block).as("application/javascript")
}

def countsData = Backend.currentHits
.map{ hit => hit.fullUrl -> tidy("%.1f".format(hit.hitsPerSec)) }.toMap
def fullData = Backend.currentHits.map { hit => hit.fullUrl -> hit }.toMap

def countsData = fullData.mapValues(_.tidyHitsPerSec)


def counts(callback: Option[String]) = Action {
withCallback(callback) {
Expand Down Expand Up @@ -48,9 +50,6 @@ object Api extends Controller {
}
}

private def tidy(s: String) = s match {
case "0.0" => "<0.1"
case other => other
}


}
25 changes: 19 additions & 6 deletions app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package controllers

import play.api._
import play.api.mvc._
import lib.Backend
import org.joda.time.DateTime
import com.gu.openplatform.contentapi.model.Tag
import lib.{HitReport, Backend}

object Application extends Controller {

Expand All @@ -21,14 +21,15 @@ object Application extends Controller {
def search = Action { Ok(views.html.search()) }

private def publishedContent = {
val currentHits = Api.countsData
val currentHits = Api.fullData
Backend.publishedContent.map { c =>
PublishedContent(
c.webPublicationDate, c.webUrl, c.webTitle,
currentHits.get(c.webUrl).map(_.toString).getOrElse("0"),
currentHits.get(c.webUrl).map(_.tidyHitsPerSec).getOrElse("0"),
c.sectionName.getOrElse(""),
c.safeFields.get("trailText"),
c.tags
c.tags,
currentHits.get(c.webUrl)
)
}
}
Expand All @@ -51,13 +52,25 @@ case class PublishedContent(
hitsPerSec: String,
section: String,
trailText: Option[String],
tags: List[Tag]
tags: List[Tag],
hitReport: Option[HitReport]
) {
lazy val cssClass = hitsPerSec match {
lazy val cpsCssClass = hitsPerSec match {
case "0" => "zero"
case s if s.startsWith("0") => ""
case "<0.1" => ""
case "trace" => ""
case _ => "high"
}

lazy val rowCssClass = if (hasNetworkFrontReferrer) "front-referral" else ""

lazy val networkFrontTooltip =
if (hasNetworkFrontReferrer) "Have seen referrals from the UK network front"
else "No clicks to this page from the UK network front have been seen"

lazy val networkFrontText = if (hasNetworkFrontReferrer) "NF" else ""

lazy val hasNetworkFrontReferrer =
hitReport map { _.referrers contains "http://www.guardian.co.uk/" } getOrElse false
}
4 changes: 2 additions & 2 deletions app/lib/MqReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class MqReader(consumers: List[ActorRef]) {
val context = ZMQ.context(1)
val sub = context.socket(ZMQ.SUB)

sub.connect("tcp://localhost:5100")
sub.connect("tcp://localhost:5200")
sub.connect("tcp://gnmfasteragain.int.gnl:5100")
sub.connect("tcp://gnmfasteragain.int.gnl:5200")
sub.subscribe(Array.empty)
sub.setHWM(50)

Expand Down
6 changes: 6 additions & 0 deletions app/lib/TopHits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ case class HitReport(url: String, percent: Double, hits: Int, hitsPerSec: Double

lazy val cssClass = if (hitsPerSec >= 1.0) "high" else ""

lazy val tidyHitsPerSec = tidy("%.1f".format(hitsPerSec))

private def tidy(s: String) = s match {
case "0.0" => "<0.1"
case other => other
}
}


Expand Down
9 changes: 7 additions & 2 deletions app/views/snippets/contentChart.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
@datawarning()
<table class="published-content table table-striped">
@for(c <- content) {
<tr>
<tr class="@c.rowCssClass">
<td class="pub-date">@c.publicationDate.toString("d MMM HH:mm:ss")</td>
<td class="cps"><span class="label percent-cps @c.cssClass">@c.hitsPerSec</span></td>
<td class="cps"><span class="label percent-cps @c.cpsCssClass">@c.hitsPerSec</span></td>
<td class="front-referral-status" title="@c.networkFrontTooltip">
@if(c.hasNetworkFrontReferrer) {
NF
}
</td>
<td>
@Html(c.section) <a href="@c.url" target="_blank">@Html(c.title)</a>
<div class="trail-text">@Html(c.trailText getOrElse "")</div>
Expand Down

0 comments on commit 60e25b7

Please sign in to comment.