-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
86 lines (72 loc) · 2.39 KB
/
settings.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
74
75
76
77
78
79
80
81
82
83
84
85
86
import os.path as op
import yaml
def create_settings():
path = op.join(op.dirname(__file__), 'settings.yml')
settings = [
{
'window': {
'monitor': 'monitor',
'size': [1920, 1080],
'distance': 50,
'width': 34.5,
'fullscreen': True
}
},
{
'environment': {
'first_color': 'red',
'first_frequency': [25, 25, 25, 25],
'second_color': 'green',
'second_frequency': [50, 50]
}
},
{
'checkerboard': {
'size': 128,
'first_position': [320, 180],
'second_position': [-320, -180]
}
},
{
'experiment': {
'name': 'rl-line-01',
'probability': 70,
'slice': [1, 3],
'intro_wait': 24,
'outro_wait': 24,
'left_key': '1',
'right_key': '0',
'keypress_wait': 2000,
'checkerboard_wait': 750
}
}
]
with open(path, 'w') as file:
content = ''
for setting in settings:
content += yaml.safe_dump(setting, default_flow_style=False, sort_keys=False)
content += '\n'
file.write(content[:-1])
def load_settings():
path = op.join(op.dirname(__file__), 'settings.yml')
exists = op.exists(path)
if not exists:
create_settings()
with open(path, 'r') as file:
settings = yaml.safe_load(file)
return settings
def save_settings(settings: dict, path: str):
settings = [{key: value} for key, value in settings.items()]
with open(path, 'w') as file:
content = ''
for setting in settings:
content += yaml.safe_dump(setting, default_flow_style=False, sort_keys=False)
content += '\n'
file.write(content[:-1])
def merge_settings(file_settings: dict, args_settings: dict):
return {
'window': {**file_settings['window'], **args_settings['window']},
'environment': {**file_settings['environment'], **args_settings['environment']},
'checkerboard': {**file_settings['checkerboard'], **args_settings['checkerboard']},
'experiment': {**file_settings['experiment'], **args_settings['experiment']}
}