Attic/danube_test4.scala
changeset 463 0315d9983cd0
parent 424 daf561a83ba6
equal deleted inserted replaced
462:34feeb53c0ba 463:0315d9983cd0
       
     1 
       
     2 // first test 
       
     3 
       
     4 import M2._
       
     5 
       
     6 def urban_groupById(ratings: List[(String, String)]) = 
       
     7   ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap 
       
     8 
       
     9 def urban_get_csv_file(name: String) : List[String] = {
       
    10   import io.Source
       
    11   import scala.util._
       
    12   val csv = Source.fromFile(name)
       
    13   csv.mkString.split("\n").toList.drop(1)
       
    14 }
       
    15 
       
    16 def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
       
    17   for (cols <- lines.map(_.split(",").toList); 
       
    18        if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
       
    19 }
       
    20 
       
    21 
       
    22 val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
       
    23 
       
    24 val urban_ratings_map = urban_groupById(urban_good_ratings)
       
    25 
       
    26 assert(favourites(urban_ratings_map, "912").length  == 80)
       
    27 assert(favourites(urban_ratings_map, "858").length  == 158)
       
    28 assert(favourites(urban_ratings_map, "260").length  == 201)
       
    29