-
Notifications
You must be signed in to change notification settings - Fork 17
/
custom_otree_config.py
131 lines (122 loc) · 5.98 KB
/
custom_otree_config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import logging
import sys
import yaml
import random
class CustomOtreeConfig:
otree_default_required = {'app_sequence': ['Consent', 'hft', 'AnonPay']}
def __init__(self, configs:dict, filename:str):
self.base_configs = configs
self.filename = filename
self.environment = configs['session']['environment']
@classmethod
def from_yaml(cls, path_to_file) -> dict:
with open(path_to_file, 'r') as f:
try:
configs = yaml.load(f)
except yaml.YAMLError as e:
raise e
return cls(configs, path_to_file)
def get_otree_config(self) -> dict:
otree_configs = {}
yaml_to_otree_map = config_maps[self.environment]
for otree_config_key, yaml_key in yaml_to_otree_map.items():
parent_key, child_key = yaml_key
try:
value = self.base_configs[parent_key][child_key]
otree_configs[otree_config_key] = value
except KeyError:
otree_configs[otree_config_key] = None
sys.stdout.write('%s:%s is missing in %s, set to none.\n' % (
parent_key, child_key, self.filename))
otree_configs.update(self.otree_default_required)
return otree_configs
@classmethod
def initialize_many_from_folder(cls, directory):
"""
reads all files in config folder
"""
all_yaml_filenames = os.listdir(directory)
yaml_config_filenames = [os.path.join(directory, f) for f in all_yaml_filenames
if f.endswith('.yaml')]
custom_configs = []
for f in yaml_config_filenames:
try:
config = cls.from_yaml(f)
except Exception as e:
sys.stdout.write('failed to read file %s:%s\n', f, e)
else:
custom_configs.append(config)
return custom_configs
config_maps = {
'BCS': {
'name': ('session', 'session-name'),
'auction_format': ('market', 'auction-format'),
'num_demo_participants': ('demo', 'number-of-participants'),
'environment': ('session', 'environment'),
'trial': ('session', 'trial'),
'trial_length': ('session', 'trial-length'),
'num_rounds': ('session', 'num-rounds'),
'exchange_host': ('market', 'matching-engine-host'),
'num_markets': ('market', 'number-of-markets'),
'number_of_traders': ('traders', 'number-of-traders'),
'allow_underbooking': ('traders', 'allow-underbooking'),
'technology_unit_cost': ('parameters', 'technology-unit-cost'),
'fundamental_price': ('parameters', 'fundamental-price'),
'initial_spread': ('parameters', 'initial-spread'),
'max_spread': ('parameters', 'max-spread'),
'initial_endowment': ('parameters', 'initial-endowment'),
'period_length': ('parameters', 'period-length'),
'batch_length': ('parameters', 'batch-length'),
'random_round_payment': ('session', 'random-round-payment'),
'participation_fee': ('session', 'participation-fee'),
'real_world_currency_per_point': ('session', 'exchange-rate'),
'exogenous_event_directory': ('session', 'exogenous-event-directory'),
'investor_arrivals': ('exogenous-events', 'investor-arrivals'),
'fundamental_value_jumps': ('exogenous-events', 'fundamental-value-jumps'),
'auto_advance': ('session', 'auto-advance'),
'next_button_timeout': ('session', 'next-button-timeout'),
'random_payoff': ('session', 'random-payoff'),
'max_payment': ('session', 'max-payment'),
'instructions_next_button_timeout': ('session', 'instructions-next-button-timeout'),
'feedback_next_button_timeout': ('session', 'feedback-next-button-timeout'),
'trial_rounds': ('session', 'trial-rounds'),
'run_survey': ('session', 'run-survey'),
},
'elo': {
'name': ('session', 'session-name'),
'display_name': ('session', 'display-name'),
'real_world_currency_per_point': ('session', 'exchange-rate'),
'auction_format': ('market', 'auction-format'),
'participation_fee': ('session', 'participation-fee'),
'num_demo_participants': ('demo', 'number-of-participants'),
'environment': ('session', 'environment'),
'num_rounds': ('session', 'num-rounds'),
'matching_engine_host': ('market', 'matching-engine-host'),
'number_of_traders': ('traders', 'number-of-traders'),
'allow_underbooking': ('traders', 'allow-underbooking'),
'k_reference_price': ('parameters', 'k-reference-price'),
'k_signed_volume': ('parameters', 'k-signed-volume'),
'tax_rate': ('parameters', 'deduction-rate'),
'include_signed_volume_widgets': ('parameters', 'include-signed-volume-widgets'),
'include_manual_role': ('parameters', 'include-manual-role'),
'speed_unit_cost': ('parameters', 'technology-unit-cost'),
'initial_endowment': ('parameters', 'initial-endowment'),
'session_duration': ('parameters', 'session-duration'),
'batch_length': ('parameters', 'batch-length'),
'investor_arrivals': ('exogenous-events', 'investor-arrivals'),
'external_feed': ('exogenous-events', 'external-feed'),
'default_role': ('parameters', 'default-role'),
'test_input_file': ('tests', 'test_input_file'),
'peg_proportion': ('parameters', 'peg-proportion'),
'post_session_delay': ('session', 'post-session-delay'),
'auto_advance': ('session', 'auto-advance'),
'next_button_timeout': ('session', 'next-button-timeout'),
'random_payoff': ('session', 'random-payoff'),
'max_payment': ('session', 'max-payment'),
'instructions_next_button_timeout': ('session', 'instructions-next-button-timeout'),
'feedback_next_button_timeout': ('session', 'feedback-next-button-timeout'),
'trial_rounds': ('session', 'trial-rounds'),
'run_survey': ('session', 'run-survey'),
}
}