Skip to content

Instantly share code, notes, and snippets.

@mgandin
Created December 30, 2016 11:53
Show Gist options
  • Save mgandin/5f139551053970482ca117a0fa459f8e to your computer and use it in GitHub Desktop.
Save mgandin/5f139551053970482ca117a0fa459f8e to your computer and use it in GitHub Desktop.
Moulinette en scala pour calculer le top des lecteurs de Popnews
object PopNews {
def main (args: Array[String]) {
val bests = Seq("radiohead",
"Whitney",
"Cowtown",
"Car seat headrest",
"Woods",
"Leonard Cohen",
"Kevin Morby",
"Diiv",
"Hyperculte",
"Teenage Fanclub",
"Troy Von Balthazar",
"keruda panter",
"The Tyde",
"Gloria",
"Okkervil River",
"Kevin Morby",
"Nick Cave",
"The Magnetic North",
"Gloria",
"The Trashcan Sinatras",
"Lawrence Arabia",
"Hildebrandt",
"pj harvey",
"Laish",
"David Bowie",
"Cabane",
"ANGEL OLSEN",
"Agnes Obel",
"The Radio Dept",
"Woods",
"John Cunningham",
"parquet courts",
"Ultimate Painting",
"The radio dept",
"The Magnetic North",
"Frustration",
"Troy Von Balthazar",
"Sophia",
"David Bowie",
"And Also The Trees",
"Radiohead",
"Radiohead",
"Omar Rodriguez Lopez",
"angel olsen",
"John CUNNINGHAM",
"Wild Nothing",
"Sky Girl",
"Naive New Beaters",
"Big Thief",
"The lemon twigs",
"old mountain station")
val seconds = Seq("on dead waves",
"Radiohead",
"Cass Mccombs",
"whitney",
"Emma Pollock",
"David Bowie",
"Whitney",
"Andy shauf",
"Romain Marsault",
"Metronomy",
"Radiohead",
"diiv",
"Teenage Fanclub",
"The Divine Comedy",
"Suede",
"The Wedding Present",
"Danny Brown",
"Woods",
"The Handsome Familt",
"The Divine Comedy",
"John Cunningham",
"Leonard Cohen",
"nick cave",
"John Cunningham",
"Nada Surf",
"David Thomas Broughton",
"CAR SEAT HEADREST",
"M.I.A",
"Teenage Fanclub",
"Pete Astor",
"The Tyde",
"PJ Harvey",
"The Magnetic North",
"Warpaint",
"Kate Bush",
"Total Victory",
"Françoiz Breut",
"Richard Pinhas",
"Christophe",
"Nick Cave",
"David Bowie",
"Iggy Pop",
"Omar Rodriguez Lopez",
"Daughter",
"ANDY SHAUF",
"Christophe",
"Weyes Blood",
"Fakear",
"Stranded Horse",
"The lemon twigs",
"Pj harvey")
val hopes = Seq("exploded view",
"Whitney",
"Yachtclub",
"Whitney",
"Andy Shauf",
"The Goon Sax",
"Chevalrex",
"Manuel Adnot",
"Bantam Lyons",
"sulk",
"The Goon Sax",
"Gloria",
"Car Seat Headrest",
"Britta Phillips",
"Delroy Edwards",
"Quilt",
"Gloria",
"Whyte Horses",
"The Lemon Twigs",
"Hildebrandt",
"michael kiwanuka",
"Oscar",
"Reignwolf",
"Chevalrex",
"THE GOON SAX",
"Paradis",
"Féroces",
"Alex Cameron",
"chevalrex ",
"Meilyr Jones",
"La Femme",
"The Goon Sax ",
"Fews",
"Suuns",
"Oren Ambarchi",
"O",
"Dear Deer",
"Grand Blanc",
"Essaie Pas",
"Abbath",
"Julia Jacklin",
"THE LEMON TWIGS",
"Jóhann Jóhannsson",
"Josin",
"Whitney",
"The lemon twigs",
"Le Flegmatic")
val map1 = calculate(bests, 3)
val map2 = calculate(seconds, 2)
val merged = map1 ++ map2.map{ case (k,v) => k -> (v + map1.getOrElse(k,0)) }
println(merged.toSeq.sortBy(_._2))
println(calculate(hopes).toSeq.sortBy(_._2))
}
def calculate(artists: Seq[String], coeff: Integer = 1): Map[String, Int] = {
artists.map(s => s.toLowerCase())
.groupBy(identity)
.mapValues(_.size)
.mapValues(v => v*coeff)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment