284
|
1 |
|
|
2 |
// first test
|
|
3 |
|
403
|
4 |
import M2._
|
284
|
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._
|
379
|
12 |
val csv = Source.fromFile(name)("ISO-8859-1")
|
284
|
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);
|
379
|
18 |
if (cols(2).toInt >= 4)) yield (cols(0), cols(1))
|
284
|
19 |
}
|
|
20 |
|
|
21 |
|
379
|
22 |
val urban_good_ratings = urban_process_ratings(urban_get_csv_file("ratings.csv"))
|
284
|
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 |
|