main_marking2/danube_test7b.scala
changeset 389 4113d4d8cf62
equal deleted inserted replaced
388:ed63dca8068a 389:4113d4d8cf62
       
     1 
       
     2 import CW7b._
       
     3 
       
     4 def urban_groupById(ratings: List[(String, String)]) = 
       
     5   ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap 
       
     6 
       
     7 def urban_get_csv_file(name: String) : List[String] = {
       
     8   import io.Source
       
     9   import scala.util._
       
    10   val csv = Source.fromFile(name)
       
    11   csv.mkString.split("\n").toList.drop(1)
       
    12 }
       
    13 
       
    14 def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
       
    15   for (cols <- lines.map(_.split(",").toList); 
       
    16        if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
       
    17 }
       
    18 
       
    19 def urban_process_movies(lines: List[String]) : List[(String, String)] = {
       
    20   for (cols <- lines.map(_.split(",").toList)) yield (cols(0), cols(1))  
       
    21 }
       
    22 
       
    23 
       
    24 val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
       
    25 val urban_movie_names = process_movies(urban_get_csv_file("movies.csv")).toMap
       
    26 
       
    27 val urban_ratings_map = urban_groupById(urban_good_ratings)
       
    28 
       
    29 def urban_test() = 
       
    30   { most_recommended(urban_ratings_map, urban_movie_names) ; true }
       
    31 
       
    32 assert(urban_test())
       
    33 
       
    34