-
Notifications
You must be signed in to change notification settings - Fork 23
/
convert_wiki_configs.py
42 lines (33 loc) · 1.15 KB
/
convert_wiki_configs.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
import glob
import os.path
import re
import jinja2
import yaml
gb_defaults = {
'max_depth': 7,
'learning_rate': 0.01,
'max_features': 'log2',
'n_estimators': 700
}
env = jinja2.Environment(
loader=jinja2.FileSystemLoader("templates"),
lstrip_blocks=True,
trim_blocks=True
)
# Custom filter method
def regex_replace(s, find, replace):
"""A non-optimal implementation of a regex filter"""
return re.sub(find, replace, s)
env.filters['regex_replace'] = regex_replace
for file_name in glob.glob("old_wiki_configs/*.yaml"):
wiki_config = yaml.load(open(file_name))
if 'models' in wiki_config:
for model_name, model_config in wiki_config['models'].items():
if 'rf' not in model_config:
tuning_params = dict(gb_defaults.items())
tuning_params.update(model_config.get('tuning_params', {}))
model_config['tuning_params'] = tuning_params
template = env.from_string(open("templates/WikiConfConversion.j2").read())
new_config = template.render(wiki_config)
with open("config/wikis/" + os.path.basename(file_name), "w") as f:
f.write(new_config)