Created
October 21, 2020 06:18
-
-
Save yves-chevallier/89216a3f5e1d825ec4db71c6daf363b2 to your computer and use it in GitHub Desktop.
Score file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import yaml | |
def note(got, total): | |
return round(got / total * 5. + 1., 1) | |
def get_points(u): | |
got = 0 | |
total = 0 | |
for k, v in u.items(): | |
if isinstance(v, dict): | |
_got, _total = get_points(v) | |
got += _got | |
total += _total | |
elif isinstance(v, list) and k == '$points': | |
_got, _total = v | |
got += float(_got) | |
total += float(_total) if float(_total) > 0 else 0 | |
elif isinstance(v, list) and k == '$bonus': | |
_got, _total = v | |
got += float(_got) | |
return (got, total) | |
print(note(*get_points(yaml.load(open('criteria.yml'), Loader=yaml.FullLoader)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment