-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_ui.py
146 lines (113 loc) · 4.35 KB
/
utils_ui.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import ccc
import git
import inquirer
import json
import os
def ask_targetmode():
questions = [inquirer.List('targetmode',
message="Target Mode?",
choices=[
"1: Flash",
"2: Flash windowed sum",
"3: Flash windowed max",
]
)
]
answers = inquirer.prompt(questions)
return int(answers["targetmode"][0])
def ask_modeldir(target_mode):
tmsubdir = f'targetmode_{target_mode}'
model_root_tm_path = os.path.join(ccc.MODEL_ROOT_PATH, tmsubdir)
modeldirs = os.listdir(model_root_tm_path)
modeldirs.sort(reverse=True)
questions = [inquirer.List('modeldir',
message="Which model should be tested?",
choices=modeldirs)
]
answers = inquirer.prompt(questions)
return [os.path.join(tmsubdir, answers["modeldir"]), os.path.join(model_root_tm_path, answers["modeldir"])]
def ask_model_cfg():
questions = [
inquirer.Text(
'hiddenlayers',
message="Give a list of nodes per hiddenlayers separated by comma. E.g.: 512,512,3",
),
inquirer.Text(
'dropoutp',
message="Choose a dropout value. E.g. 0.1",
),
inquirer.Text(
'earlystoppingpatience',
message="Choose early stopping patience. E.g. 5",
),
inquirer.List(
'normfun',
message="Choose a normalization method",
choices=["minmax", "meanstd", "disabled"],
),
]
answers = inquirer.prompt(questions)
dropoutp = float(answers["dropoutp"])
norm_fun = answers["normfun"]
esp = int(answers["earlystoppingpatience"])
hiddenlayers = [int(val) for val in answers["hiddenlayers"].split(',')]
target_mode = ask_targetmode()
if target_mode in {1, 3}:
outputdim = 1
elif target_mode == 2:
outputdim = 3
else:
raise Exception(f"Target mode {target_mode} unknown")
config_model = dict()
config_model["dropoutp"] = dropoutp
config_model["earlystoppingpatience"] = esp
config_model["hiddenlayers"] = hiddenlayers
config_model["inputdim"] = 671
config_model["outputdim"] = outputdim
config_model["target_mode"] = target_mode
config_model["norm_fun"] = norm_fun
return config_model
'''
User UI for building data config. In case store_settings_path is given, git diff and data_cfg is stored in that path
'''
def ask_datacfg(store_settings_path=""):
data_cfg = dict()
data_cfg['datamode'] = 3 # hardcoded right now, because i don't see why we should use others
dmsubdir = f"datamode_{data_cfg['datamode']}"
data_root_dm_path = os.path.join(ccc.DATA_ROOT_PATH, dmsubdir)
datadirs = os.listdir(data_root_dm_path)
datadirs.sort(reverse=True)
question_datadir = [
inquirer.List(
'datasource',
message="Choose a data source",
choices=datadirs,
),
]
data_cfg['datasource'] = inquirer.prompt(question_datadir)['datasource']
if data_cfg['datamode'] in {2, 3}:
train_data_path = os.path.join(data_root_dm_path, data_cfg['datasource'], 'train')
yeardirs = os.listdir(train_data_path)
yeardirs = [dir.split("=")[1] for dir in yeardirs if dir.startswith("year=")]
yeardirs.sort(reverse=True)
question_testdir = [
inquirer.List(
'test_year',
message="Choose a test year",
choices=yeardirs,
),
]
data_cfg['test_year'] = inquirer.prompt(question_testdir)['test_year']
# get and store git hash
repo = git.Repo(search_parent_directories=True)
data_cfg['git_hash'] = repo.head.object.hexsha
diffs = repo.git.diff('HEAD')
if diffs != "":
data_cfg['git_hash'] += "_dirty"
if store_settings_path != "":
with open(os.path.join(store_settings_path, 'gitdiff.txt'), 'w') as f:
f.write(diffs)
if store_settings_path != "":
with open(os.path.join(store_settings_path, "data_cfg.json"), 'w') as f:
json.dump(data_cfg, f)
return [data_cfg, os.path.join(data_root_dm_path, data_cfg['datasource'])]