Skip to content

Instantly share code, notes, and snippets.

@yves-chevallier
Created October 21, 2020 06:18
Show Gist options
  • Save yves-chevallier/89216a3f5e1d825ec4db71c6daf363b2 to your computer and use it in GitHub Desktop.
Save yves-chevallier/89216a3f5e1d825ec4db71c6daf363b2 to your computer and use it in GitHub Desktop.
Score file
#!/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