Skip to content

Instantly share code, notes, and snippets.

@Arakaki
Created October 18, 2013 08:12
Show Gist options
  • Save Arakaki/7038163 to your computer and use it in GitHub Desktop.
Save Arakaki/7038163 to your computer and use it in GitHub Desktop.
Scalaでサマリ
object App {
def main(args : Array[String]) {
case class Structure(campaign:String,creative:String,imp:Int,click:Int,conv:Int,cost:Int)
val structures = List(
Structure("testcampaign001","testcreative001",1,1,1,1),
Structure("testcampaign002","testcreative004",1,1,1,1),
Structure("testcampaign003","testcreative005",1,1,1,1),
Structure("testcampaign004","testcreative003",1,1,1,1),
Structure("testcampaign004","testcreative001",1,1,1,1),
Structure("testcampaign004","testcreative002",1,1,1,1)
)
val result = structures.groupBy(s => (s.campaign, s.creative)).map {
case (key, ss) =>
ss.reduce((a,b) => a.copy(
imp = a.imp + b.imp,
click = a.click + b.click,
conv = a.conv + b.conv,
cost = a.cost + b.cost))
}.toList.sortBy (s => (s.campaign,s.creative))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment