marking2/danube_test5.scala
author Christian Urban <urbanc@in.tum.de>
Tue, 29 Oct 2019 14:12:24 +0000
changeset 281 87b9e3e2c1a7
parent 259 43995ea34fe7
child 284 9a04eb6a2291
permissions -rw-r--r--
updated


// first test 


def urban_groupById(ratings: List[(String, String)]) = 
  ratings.groupBy(_._1).mapValues(_.map(_._2)) 

def urban_get_csv_file(name: String) : List[String] = {
  import io.Source
  import scala.util._
  val csv = Source.fromFile(name)
  csv.mkString.split("\n").toList.drop(1)
}

def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
  for (cols <- lines.map(_.split(",").toList); 
       if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
}


val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))

val urban_ratings_map = urban_groupById(urban_good_ratings)

assert(suggestions(urban_ratings_map, "912").length  == 4110)
assert(suggestions(urban_ratings_map, "858").length  == 4883)
assert(suggestions(urban_ratings_map, "260").length  == 4970)