Created
June 19, 2013 15:53
-
-
Save emaxerrno/5815427 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| object TopURLHelper { | |
| // expects a list of aggregates of type 'only' URL or RR | |
| // def combine(l: List[Aggregate]): Aggregate = { | |
| // val builder = Aggregate.newBuilder() | |
| // } | |
| def combine(l: List[Event]): List[Aggregate] = { | |
| val map = new HashMap[ByteString, Aggregate.Builder]() | |
| l.map { x => | |
| // add either rr, or url or both | |
| // I think this will throw an exception when not set | |
| if (!x.getRr.isEmpty) { | |
| // get it from map | |
| val b = map.get(x.getRrHash()).getOrElse{ | |
| Aggregate | |
| .newBuilder | |
| .setType(Aggregate.Type.RR) | |
| .setUrl(x.getRr) | |
| } | |
| bookKeeping b | |
| map.set(x.getRrHash, b) | |
| } | |
| if (!x.getUrl.isEmpty) { | |
| val b = map.get(x.getUrlHash()).getOrElse{ | |
| Aggregate | |
| .newBuilder | |
| .setType(Aggregate.Type.URL) | |
| .setUrl(x.getUrl) | |
| } | |
| bookKeeping b | |
| map.set(x.getUrlHash, b) | |
| } | |
| def bookKeeping(builder: Aggregate.Builder) = { | |
| x.getType match { | |
| case Event.Type.IMPRESSION => | |
| builder.setImps(builder.getImps + 1) | |
| case Event.Type.CLICK => | |
| builder.setClks(builder.getClks + 1) | |
| } | |
| builder.setSpend(x.getCost) | |
| } | |
| } | |
| map.values.map(_.build).toList | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment