import array import math import random try: import xlrd except: import os os.system('pip install xlrd') import xlrd import math import numpy as np def integer_random(upper_number): return int(random.random() * upper_number) # utility function for consumption in market A def ua(x): beta = 2.6563 eta = 0.37851 return beta * (pow(x, 1 - eta) / (1 - eta)) # utility function for consumption in market B def ub(x): v0 = 8 return v0 + x # cost function for producer in both Market A and Market B def cost(x): return -x def read_sequence_random_number(file_path): work_book = xlrd.open_workbook(filename=file_path) float_rows = work_book.sheet_by_index(0).col_values(1)[1:] int_rows = [] for d in float_rows: int_rows.append(int(d)) return int_rows def get_participant(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(2)[1]) def get_experiment_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(3)[1]) def get_block_length(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(4)[1]) def get_conversion_rate(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return round(sheet.col_values(5)[1], 2) def get_show_up_fee(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(6)[1] def get_critical_period_value(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(7)[1]) def get_critical_period_timeout_lower(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(8)[1]) def get_critical_period_timeout_upper(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(9)[1]) def get_block_check_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(10)[1]) def get_introduction_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(11)[1]) def get_decision_timeout(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return int(sheet.col_values(12)[1]) def get_starting_red_tokens(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(13)[1] def get_starting_green_tokens(file_path): work_book = xlrd.open_workbook(filename=file_path) sheet = work_book.sheet_by_index(0) return sheet.col_values(14)[1] # Display the first 2 digits of a value def display2(x): if x is not np.NaN: y = math.floor(x * 100.00) / 100.00 else: y = np.NaN return y def block_end_dice(DiceMax, Delta): dice_list = list(range(1, DiceMax + 1)) dice = [] for d in dice_list: if d > DiceMax * Delta: dice.append(d) return dice