# The following statement allows you to use the names of the variable
# as Python variable.
globals().update(database.variables)

#Parameters
ASC_CAR = 0.137
ASC_TRAIN = -0.402
ASC_SM = 0
B_TIME = -2.26
B_TIME_S = 1.66
B_COST = -1.29

# Define a random parameter, normally distributed,
# designed to be used for integration
omega = RandomVariable('omega')
density = dist.normalpdf(omega)
B_TIME_RND = B_TIME + B_TIME_S * omega

# Definition of new variables
SM_COST = SM_CO * (GA == 0)
TRAIN_COST = TRAIN_CO * (GA == 0)
CAR_AV_SP = CAR_AV * (SP != 0)
TRAIN_AV_SP = TRAIN_AV * (SP != 0)
TRAIN_TT_SCALED = TRAIN_TT / 100.0
TRAIN_COST_SCALED = TRAIN_COST / 100
SM_TT_SCALED = SM_TT / 100.0
SM_COST_SCALED = SM_COST / 100
CAR_TT_SCALED = CAR_TT / 100
CAR_CO_SCALED = CAR_CO / 100

# Definition of the utility functions
choiceResults = res.bioResults(
    pickleFile='Latent_Choice_seq_biodraws~00.pickle')
choiceBetas = choiceResults.getBetaValues()
#choiceBetas = {}
## Latent variable: structural equation
random_variable = {}
modes_list = ['PT', 'RH', 'AV', 'Drive']
for mode in modes_list:
    random_variable[mode] = {}
    var_name = 'omega_' + mode
    # biodraws
    # random_variable[att]['omega'] = bioDraws(var_name,'NORMAL')
    # integral
    random_variable[mode]['omega'] = RandomVariable(var_name)
    random_variable[mode]['omega_name'] = var_name
    random_variable[mode]['density'] = dist.normalpdf(
        random_variable[mode]['omega'])
    #----
    var_name = 'sigma_s_tidle_' + mode
    if var_name in choiceBetas:
        random_variable[mode]['sigma_s'] = Beta(var_name,
                                                choiceBetas[var_name], None,
                                                None, 0)
    else:
        random_variable[mode]['sigma_s'] = Beta(var_name, 0.0001, None, None,
                                                0)

if len(choiceBetas) > 0:
    ASC_WALK = Beta('ASC_WALK', 0, None, None, 1)  #fixed
    ASC_PT = Beta('ASC_PT', choiceBetas['ASC_PT'], None, None, 0)
    ASC_RIDEHAIL = Beta('ASC_RIDEHAIL', choiceBetas['ASC_RIDEHAIL'], None,
                        None, 0)