condense external variables
This commit is contained in:
@@ -23,7 +23,13 @@ class ControllerDB:
|
||||
def __init__(self, prefix, reset_flag=0):
|
||||
with open('conf_experiment.yaml') as yaml_file:
|
||||
dct_conf_experiment = yaml.full_load(yaml_file)
|
||||
|
||||
assert prefix in ['test', 'without_exp', 'with_exp'], \
|
||||
"db name not in test, without_exp, with_exp"
|
||||
|
||||
self.is_test = prefix == 'test'
|
||||
self.is_with_exp = \
|
||||
False if prefix == 'test' or prefix == 'without_exp' else True
|
||||
self.db_name_prefix = prefix
|
||||
dct_para_in_test = dct_conf_experiment[
|
||||
'test'] if self.is_test else dct_conf_experiment['not_test']
|
||||
@@ -46,18 +52,8 @@ class ControllerDB:
|
||||
Firm.fillna(0, inplace=True)
|
||||
|
||||
# fill dct_lst_init_remove_firm_prod
|
||||
assert self.db_name_prefix in ['test', 'without_exp', 'with_exp'], \
|
||||
"db name not in test, without_exp, with_exp"
|
||||
|
||||
list_dct = []
|
||||
if self.db_name_prefix in ['test', 'without_exp']:
|
||||
for _, row in Firm.iterrows():
|
||||
code = row['Code']
|
||||
row = row['1':]
|
||||
for product_code in row.index[row == 1].to_list():
|
||||
dct = {code: [product_code]}
|
||||
list_dct.append(dct)
|
||||
elif self.db_name_prefix in ['with_exp']:
|
||||
if self.is_with_exp:
|
||||
str_sql = "select e_id, count, max_max_ts, " \
|
||||
"dct_lst_init_remove_firm_prod from " \
|
||||
"iiabmdb.without_exp_experiment as a " \
|
||||
@@ -76,13 +72,20 @@ class ControllerDB:
|
||||
lambda x: pickle.loads(x))
|
||||
list_dct = result.loc[result['count'] >= 12,
|
||||
'dct_lst_init_remove_firm_prod'].to_list()
|
||||
else:
|
||||
for _, row in Firm.iterrows():
|
||||
code = row['Code']
|
||||
row = row['1':]
|
||||
for product_code in row.index[row == 1].to_list():
|
||||
dct = {code: [product_code]}
|
||||
list_dct.append(dct)
|
||||
# list_dct = [{'140': ['1.4.5.1']}]
|
||||
# list_dct = [{'133': ['1.4.4.1']}]
|
||||
# list_dct = [{'2': ['1.1.3']}]
|
||||
# list_dct = [{'135': ['1.3.2.1']}]
|
||||
# list_dct = [{'79': ['2.1.3.4']}]
|
||||
# list_dct = [{'99': ['1.3.3']}]
|
||||
# list_dct = [{'41': ['1.4.5']}]
|
||||
list_dct = [{'41': ['1.4.5']}]
|
||||
|
||||
# fill g_bom
|
||||
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
|
||||
@@ -98,9 +101,13 @@ class ControllerDB:
|
||||
g_product_js = json.dumps(nx.adjacency_data(g_bom))
|
||||
|
||||
# insert exp
|
||||
df_xv = pd.read_csv("xv_with_exp.csv", index_col=None)
|
||||
df_xv = pd.read_csv(
|
||||
f"xv_{'with_exp' if self.is_with_exp else 'without_exp'}.csv",
|
||||
index_col=None)
|
||||
# read the OA table
|
||||
df_oa = pd.read_csv("oa_with_exp.csv", index_col=None)
|
||||
df_oa = pd.read_csv(
|
||||
f"oa_{'with_exp' if self.is_with_exp else 'without_exp'}.csv",
|
||||
index_col=None)
|
||||
df_oa = df_oa.iloc[:, 0:df_xv.shape[1]]
|
||||
for idx_scenario, row in df_oa.iterrows():
|
||||
dct_exp_para = {}
|
||||
@@ -119,13 +126,10 @@ class ControllerDB:
|
||||
|
||||
def add_experiment_1(self, idx_scenario, idx_init_removal,
|
||||
dct_lst_init_remove_firm_prod, g_bom,
|
||||
n_max_trial, crit_supplier,
|
||||
firm_req_prf_size, firm_req_prf_conn,
|
||||
firm_acc_prf_size, firm_acc_prf_conn,
|
||||
netw_sply_prf_n, netw_sply_prf_size,
|
||||
netw_cust_prf_n, netw_cust_prf_size,
|
||||
n_max_trial, prf_size, prf_conn,
|
||||
cap_limit_prob_type, cap_limit_level,
|
||||
diff_new_conn, diff_remove, proactive_ratio):
|
||||
diff_new_conn, crit_supplier, diff_remove,
|
||||
proactive_ratio, netw_prf_n):
|
||||
e = Experiment(
|
||||
idx_scenario=idx_scenario,
|
||||
idx_init_removal=idx_init_removal,
|
||||
@@ -134,20 +138,15 @@ class ControllerDB:
|
||||
dct_lst_init_remove_firm_prod=dct_lst_init_remove_firm_prod,
|
||||
g_bom=g_bom,
|
||||
n_max_trial=n_max_trial,
|
||||
crit_supplier=crit_supplier,
|
||||
firm_req_prf_size=firm_req_prf_size,
|
||||
firm_req_prf_conn=firm_req_prf_conn,
|
||||
firm_acc_prf_size=firm_acc_prf_size,
|
||||
firm_acc_prf_conn=firm_acc_prf_conn,
|
||||
netw_sply_prf_n=netw_sply_prf_n,
|
||||
netw_sply_prf_size=netw_sply_prf_size,
|
||||
netw_cust_prf_n=netw_cust_prf_n,
|
||||
netw_cust_prf_size=netw_cust_prf_size,
|
||||
prf_size=prf_size,
|
||||
prf_conn=prf_conn,
|
||||
cap_limit_prob_type=cap_limit_prob_type,
|
||||
cap_limit_level=cap_limit_level,
|
||||
diff_new_conn=diff_new_conn,
|
||||
crit_supplier=crit_supplier,
|
||||
diff_remove=diff_remove,
|
||||
proactive_ratio=proactive_ratio
|
||||
proactive_ratio=proactive_ratio,
|
||||
netw_prf_n=netw_prf_n
|
||||
)
|
||||
db_session.add(e)
|
||||
db_session.commit()
|
||||
|
||||
Reference in New Issue
Block a user