Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Problem 1: Futures
## Setup
Use the following commands to make a fresh clone of your repository:
```
git clone -b concpar21final01 git@gitlab.epfl.ch:lamp/student-repositories-s22/cs206-GASPAR.git concpar21final01
```
If you have issues with the IDE, try [reimporting the
build](https://gitlab.epfl.ch/lamp/cs206/-/blob/master/labs/example-lab.md#troubleshooting),
if you still have problems, use `compile` in sbt instead.
## Useful links
* [The API documentation of the Scala standard library](https://www.scala-lang.org/files/archive/api/2.13.4)
* [The API documentation of the Java standard library](https://docs.oracle.com/en/java/javase/15/docs/api/index.html)
* [The API documentation of the Play framework](https://www.playframework.com/documentation/2.8.x/api/scala/index.html)
## Exercise
In this exercise, your task is to implement a leaderboard webpage for a GitLab-based exam. This leaderboard is live in the sense that it is constructed on the fly by extracting grades directly from GitLab pipelines: it is always up to date.
This exercise uses the Play framework, a popular web application framework.
Play is entirely asynchronous and uses futures for concurrency.
In `src/main/scala/f1/MyComponents.scala`, we define a minimal Play application to display the leaderboard (you do not need to modify this file).
You can start this application using `sbt run` and open the leaderboard in a web browser at [http://localhost:9000/](http://localhost:9000/). After having completed this exercise, you should see a populated leaderboard as shown in this screenshot:

In this exercise, your task is to implement the `leaderboard()` method in `src/main/scala/f1/F1.scala` which asynchronously retrieves and sorts student grades.
Grades should be sorted such that maximum grades appear at the head of the list, like in the screenshot above.
Your implementation should use the following two methods to get the list of students and the grade of a particular student:
```scala
/** Retrieve a student's grade using GitLab's API */
def getGrade(sciper: Int): Future[Option[Grade]]
/** Retrieve the list of enrolled students from IS-academia */
def getScipers(): Future[List[Int]]
```
These methods have mock implementations that return made-up values after a short delay (simulating a network call).
Your implementation should be asynchronous (it is forbidden to use the `Await.result` method).
Furthermore, given the large number of students, calls to the GitLab API should be made in parallel such that the overall request is completed in about 1 second.
*Hint:* this exercise can be solved without writing any recursive functions! You are allowed to use every function defined on [Future][1] and [List][2], as well as functions defined on their companion objects ([Future][3], [List][4]).
[1]: https://www.scala-lang.org/api/2.13.4/scala/concurrent/Future.html
[2]: https://www.scala-lang.org/api/2.13.4/scala/collection/immutable/List.html
[3]: https://www.scala-lang.org/api/2.13.4/scala/concurrent/Future$.html
[4]: https://www.scala-lang.org/api/2.13.4/scala/collection/immutable/List$.html