Skip to content

Commit

Permalink
Top 5 referrers displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Tackley committed Oct 21, 2011
1 parent 136590a commit 4f583c8
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 15 deletions.
9 changes: 5 additions & 4 deletions dashboard/src/main/scala/dashboard/comet/TopTenServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ class TopTen extends CometActor with CometListener {
}

def render = {
"tr" #> topTen.l.map { hit =>
".toplink *" #> <a href={ "http://www.guardian.co.uk" + hit.url }>{hit.url}</a> &
"tr" #> (topTen.l.map { hit: HitReport =>
".toplink" #> <a href={ "http://www.guardian.co.uk" + hit.url }>{hit.url}</a> &
".percent *" #> "%.1f%%".format(hit.percent) &
".mover *" #> hit.movement.imgTag
}
".mover *" #> hit.movement.imgTag &
"li" #> hit.referrerPercents.take(5).map { case (host, percent) => "* *" #> "%.0f%% from %s".format(percent, host) }
})
}

}
7 changes: 4 additions & 3 deletions dashboard/src/main/scala/dashboard/lib/Calculator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ object Calculator {
def calcTopTenPaths(clickStream: ClickStream) = {
val totalClicks = clickStream.clicks.size
val clicksPerPath = clickStream.clicks.groupBy(_.path).map {
case (k, v) => (k, v.size)
case (k, v) => (k, v, v.size)
}.toList
val topTen = clicksPerPath.sortBy(_._2).reverse.take(10)
val topTen = clicksPerPath.sortBy(_._3).reverse.take(10)

topTen map {
case (url, hitCount) => HitReport(url, hitCount.toDouble * 100 / totalClicks, hitCount)
case (url, hits, hitCount) =>
HitReport(url, hitCount.toDouble * 100 / totalClicks, hitCount, hits flatMap { _.referrer } toList)
}
}

Expand Down
8 changes: 6 additions & 2 deletions dashboard/src/main/scala/dashboard/lib/MqReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ class MqReader(actor: ActorRef) {
// remove failures
.filter { _.responseCode == 200 }
// remove "self refreshes"
.filterNot { e => e.referrer == Some(e.path) }
.filterNot { isSelfRefresh }
// remove common filter
.filterNot { e =>
e.path.endsWith(".ico") || e.path.endsWith(".xml") || e.path.endsWith(".swf") || e.path.endsWith(".html") || e.path.endsWith("/json")
e.path.endsWith(".ico") || e.path.endsWith(".xml") || e.path.endsWith(".swf") ||
e.path.endsWith(".html") || e.path.endsWith("/json") || e.path == "/_"
}


Expand All @@ -46,4 +47,7 @@ class MqReader(actor: ActorRef) {
println("Stopped!")
}


def isSelfRefresh(e: Event) = e.referrer.exists(_.startsWith("http://www.guardian.co.uk" + e.path))

}
12 changes: 11 additions & 1 deletion dashboard/src/main/scala/dashboard/lib/TheTopTen.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
package dashboard.lib

import xml.NodeSeq
import java.net.URL
import net.liftweb.util.Helpers._

sealed abstract class Movement { def imgTag: NodeSeq }
case class Unchanged() extends Movement { val imgTag = NodeSeq.Empty }
case class Up() extends Movement { val imgTag = <img src="up_arrow_icon.png" alt="Up"/> }
case class Down() extends Movement { val imgTag = <img src="down_arrow_icon.png" alt="Down"/> }


case class HitReport(url: String, percent: Double, hits: Int, movement: Movement = Unchanged()) {
case class HitReport(url: String, percent: Double, hits: Int, referrers: List[String], movement: Movement = Unchanged()) {
def summary = "%s %.1f%% (%d hits)" format(url, percent, hits)

lazy val referrerHostCounts = referrers.flatMap(url => tryo { new URL(url).getHost })
.groupBy(identity).mapValues(_.size)

lazy val referrerPercents: List[(String, Double)] = referrerHostCounts.toList.sortBy(_._2).reverse.map { case (host, count) =>
host -> (count * 100.0 / hits)
}

}


Expand Down
19 changes: 14 additions & 5 deletions dashboard/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
}

a {
font-size: 24pt !important;
line-height: 140%;
font-size: 24pt;
text-decoration: none;
}

Expand Down Expand Up @@ -52,6 +53,15 @@
}


ol {
list-style-type: disc;
}
li {
font-size: 14pt;
float: left;
margin-left: 40px;
}

</style>
</head>
<body>
Expand All @@ -68,11 +78,10 @@ <h1>Top 10
<table class="top-of-the-pops lift:comet?type=TopTen">
<tr>
<td class="mover"><img src="up_arrow_icon.png" alt="Up"></td>
<td class="toplink">
<a href="#">/world/middle-east-live/2011/oct/20/syria-libya-middle-east-unrest-live</a>
<td>
<a class="toplink" href="#">/world/middle-east-live/2011/oct/20/syria-libya-middle-east-unrest-live</a>
<ol>
<li>10% from http://twitter.com</li>
<li>5% from http://twitter.com</li>
<li>10% from twitter.com</li>
</ol>
</td>
<td class="percent">54%</td>
Expand Down

0 comments on commit 4f583c8

Please sign in to comment.