128
|
1 |
// Part 2 about Alcohol-Consumption Worldwide
|
|
2 |
//============================================
|
|
3 |
|
|
4 |
object CW6b {
|
|
5 |
|
|
6 |
import io.Source
|
|
7 |
import scala.util._
|
|
8 |
|
|
9 |
val url_alcohol =
|
|
10 |
"https://raw.githubusercontent.com/fivethirtyeight/data/master/alcohol-consumption/drinks.csv"
|
|
11 |
|
|
12 |
val file_population =
|
|
13 |
"population.csv"
|
|
14 |
|
|
15 |
|
129
|
16 |
//(1) Complete the get_csv_page function below. It takes the URL-string
|
|
17 |
// as argument and generates a list of strings corresponing to each
|
|
18 |
// line in the csv list. The URL url_alcohol is one possible argument.
|
128
|
19 |
|
129
|
20 |
//def get_csv_page(url: String) : List[String] = ...
|
128
|
21 |
|
|
22 |
|
129
|
23 |
// Complete the get_csv_file function below. It takes a file-string
|
|
24 |
// as argument and reads the content of the given file. Like above
|
|
25 |
// it should generates a list of strings corresponing to each
|
|
26 |
// line in the csv-list. The filename file_population is one possible
|
|
27 |
// argument.
|
128
|
28 |
|
129
|
29 |
//def get_csv_file(file: String) : List[String] = ...
|
|
30 |
|
128
|
31 |
|
|
32 |
|
129
|
33 |
//(2) Complete the functions that process the csv-lists. For
|
|
34 |
// process_alcs extract the country name (as String) and the
|
|
35 |
// pure alcohol consumption (as Double). For process_pops
|
|
36 |
// generate a Map of Strings (country names) to Long numbers
|
|
37 |
// (population size).
|
128
|
38 |
|
129
|
39 |
//def process_alcs(lines: List[String]) : List[(String, Double)] = ...
|
128
|
40 |
|
129
|
41 |
//def process_pops(lines: List[String]) : Map[String, Long] = ...
|
|
42 |
|
128
|
43 |
|
|
44 |
|
129
|
45 |
//(3) Calculate for each country the overall alcohol_consumption using
|
|
46 |
// the data from the alcohol list and the population sizes list. You
|
|
47 |
// should only include countries on the alcohol list that are also
|
|
48 |
// (with the exact name) on the population sizes list. Note that
|
|
49 |
// the spelling of some names in the alcohol list differs from the
|
|
50 |
// population sizes list. Sort the resulting list according to the
|
|
51 |
// country with the highest alcohol consumption to the country
|
|
52 |
// with the lowest alcohol consumption.
|
|
53 |
|
|
54 |
//def sorted_country_consumption() : List[(String, Long)] = ...
|
|
55 |
|
|
56 |
|
|
57 |
// Calculate the world consumption of pure alcohol of all countries, which
|
|
58 |
// should be the first element in the tuple below. The second element is
|
|
59 |
// the overall consumption of the first n countries in the sorted list
|
|
60 |
// from above; and finally the double should be the percentage of the
|
|
61 |
// first n countries of the the world consumption of alcohol.
|
|
62 |
|
|
63 |
//def percentage(n: Int) : (Long, Long, Double) = ...
|
128
|
64 |
|
|
65 |
}
|