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