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 |
|
16 //(1) Complete the get_csv_page function below. It takes a URL-string |
|
17 // as argument and generates a list of strings corresponding to each |
|
18 // line in the downloaded csv-list. The URL url_alcohol above is one |
|
19 // possible argument. |
|
20 |
|
21 //def get_csv_page(url: String) : List[String] = ... |
|
22 |
|
23 |
|
24 // Complete the get_csv_file function below. It takes a file name |
|
25 // as argument and reads the content of the given file. Like above, |
|
26 // it should generate a list of strings corresponding to each |
|
27 // line in the csv-list. The filename file_population is one possible |
|
28 // argument. |
|
29 |
|
30 //def get_csv_file(file: String) : List[String] = ... |
|
31 |
|
32 |
|
33 |
|
34 //(2) Complete the functions that process the csv-lists. For |
|
35 // process_alcs extract the country name (as String) and the |
|
36 // pure alcohol consumption (as Double). For process_pops |
|
37 // generate a Map of Strings (country names) to Long numbers |
|
38 // (population sizes). |
|
39 |
|
40 //def process_alcs(lines: List[String]) : List[(String, Double)] = ... |
|
41 |
|
42 //def process_pops(lines: List[String]) : Map[String, Long] = ... |
|
43 |
|
44 |
|
45 |
|
46 //(3) Calculate for each country the overall alcohol_consumption using |
|
47 // the data from the alcohol list and the population sizes list. You |
|
48 // should only include countries on the alcohol list that are also |
|
49 // on the population sizes list with the exact same name. Note that |
|
50 // the spelling of some names in the alcohol list differs from the |
|
51 // population sizes list. You can ignore entries where the names differ. |
|
52 // Sort the resulting list according to the country with the highest alcohol |
|
53 // consumption to the country with the lowest alcohol consumption. |
|
54 |
|
55 //def sorted_country_consumption() : List[(String, Long)] = ... |
|
56 |
|
57 |
|
58 // Calculate the world consumption of pure alcohol of all countries, which |
|
59 // should be the first element in the tuple below. The second element is |
|
60 // the overall consumption of the first n countries in the sorted list |
|
61 // from above; and finally the double should be the percentage of the |
|
62 // first n countries drinking from the the world consumption of alcohol. |
|
63 |
|
64 //def percentage(n: Int) : (Long, Long, Double) = ... |
|
65 |
|
66 } |
|