Commit d261a8ef authored by Thibaut Lunet's avatar Thibaut Lunet
Browse files

TL: added instructions for sO2

parent 7a68be0e
......@@ -7,6 +7,7 @@ Official Gitlab repository for the course [M1432 : Programmierparadigmen](https:
[**Teams for exercises and project**](./exercises/teams.md), and current exercise series :
- [SX : First steps with Python](./exercises/sX/README.md), **:bell: updated for graphic output with WSL**
- [S8 : Rabbit Population Simulator](./exercises/s8) (evaluation [here](./exercises/s8/evals.md)) **last evaluation on 11.07.2022 at 4am**
- [SO2 : Generic wrapping](./exercises/sO2/README.md) **evaluated on Friday 08.07.2022**
---
......
# SO2 : Generic wrapping
_This exercise serie is based on an oral evaluation, and not on the automatic evaluation of your source code as usual.
Evaluation is done by the tutor during the current exercise session, and should not be longer than 5 minutes. For one particular problem :_
1. Quickly present how you investigated and solved the problem
2. The tutor checks that it works and that you understand what you did
3. You get all the points for the task
_Even if this is not mandatory, it can be a simultaneous evaluation for all team members. Eventually, you can also try to do the oral evaluation during a following exercise session of the day (with an other tutor), or ask for a zoom meeting with me (ask per email at thibaut.lunet@tuhh.de).
The last option is fully recommended for people working remotely or who are members of the online exercise group.
But in any case, **the oral evaluation must be done during the day of the exercise sessions**._
:bell: _You are free to discuss with your teammates or other teams, and eventually to ask many questions to your tutor, before trying the oral evaluation._
There is only one problem to solve here, which provides 6 points.
## Problem description
Following the theory described in [the demo for HU12](../../lectures/v12_demoHU.ipynb), we want to create a generic wrapper function, called `storePerfo`, that allow to store different call informations, represented by the following dictionnary :
```python
_infos = {
"tEval" : { # computation time for evaluations
"min" : ... # minimum value
"max" : ... # maximum value
"mean" : ... # average value
"sum" : ... # total summing every values
},
"nEval" : ... # number of function evaluation
}
```
The wrapper should work on both instance methods and standalone functions,
and there should be two ways of using this wrapper :
### First usage possibility
```python
dico = {}
@storePerfo("funA", dico)
def funA():
pass
```
This creates an key `"funA"` in the `dico` variable, which stores the `_infos` described above as value.
### Second usage possibility
```python
@storePerfo
def funA():
pass
```
In that case, this creates a `_infos` attributes for the resulting function, that stores the dictionnary as described above.
### Testing code
Here is a sample code that you could use to test your wrapper :
```python
class Relaxo(object):
perfs = {}
@storePerfo("sleepFor", perfs)
def sleepFor(self, sec):
sleep(sec)
@storePerfo("wait", perfs)
def wait(self):
sleep(1)
@storePerfo
def growl(self):
print("ZZZZZZZZZZZZZZZZ")
@storePerfo
def ronflex(arg):
sleep(0.5)
perfs = {}
@storePerfo("Snorlax", perfs)
def snorlax(arg):
sleep(1.5)
@storePerfo("Ronquilaxo", perfs)
def ronquilaxo(arg, sec):
sleep(sec)
# then call a few times those functions/methods, and compare ...
```
## Hints
- use the `ismethod` function from the `inspect` package to check if a callable object is a method (see [online doc](https://docs.python.org/3/library/inspect.html#inspect.ismethod))
- you can use the `callable` built-in function to check if an object can be callable (_i.e_ can be called as a function) or not
- read carefully [the demo for HU12](../../lectures/v12_demoHU.ipynb) if you haven't already
## To go further ...
Can you adapt your wrapper so it can be applied to a class, such that every method of the class would be wrapped ? It should also work with the two usage way (with or without arguments).
# News and announcements
# 06.07.2022
- [Instructions for the second oral exercise series](./exercises/sO2/) are online
# 05.07.2022
- Added [reference solutions for sO1](./exercises/sO1/README.md)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment