forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hedy_content.py
74 lines (55 loc) · 2 KB
/
hedy_content.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import copy
import attr
from website.yaml_file import YamlFile
class LevelDefaults:
def __init__(self, language):
self.language = language
self.levels = YamlFile.for_file(f'coursedata/level-defaults/{self.language}.yaml')
def max_level(self):
all_levels = self.levels.keys()
max_consecutive_level = 1
previous_level = 0
for level in all_levels:
if level == previous_level + 1:
previous_level = level
max_consecutive_level = level
else:
return previous_level
return max_consecutive_level
def get_defaults_for_level(self, level):
#grabs level defaults from yaml and converts to DefaultValues type
default_values = self.levels[level]
default_type = {
"level": str(level),
}
default_type.update(**default_values)
return DefaultValues(**default_type)
def get_defaults(self, level):
"""Return the level defaults for a given level number."""
return copy.deepcopy(self.levels.get(int(level), {}))
class NoSuchDefaults:
def get_defaults(self, level):
return {}
class Adventures:
def __init__(self, language):
self.language = language
self.adventures_file = YamlFile.for_file(f'coursedata/adventures/{self.language}.yaml')
# When customizing classes we only want to retrieve the name, (id) and level of each adventure
def get_adventure_keyname_name_levels(self):
adventures = self.adventures_file['adventures']
adventures_dict = {}
for adventure in adventures.items():
adventures_dict[adventure[0]] = {adventure[1]['name']: list(adventure[1]['levels'].keys())}
return adventures_dict
def has_adventures(self):
return self.adventures_file.exists() and self.adventures_file.get('adventures')
class NoSuchAdventure:
def get_defaults(self, level):
return {}
@attr.s(slots=True, frozen=True)
class DefaultValues:
"""Default texts for a level"""
level = attr.ib()
intro_text = attr.ib(default=None)
start_code = attr.ib(default=None)
commands = attr.ib(default=None)