import csv import random import math def get_demand_table(product_number): path = 'data/fc_experiment/demand_history.csv' number_periods = 10 ma10 = 0 actual_demand = 0 demand_data = [] mu = 0 sigma = 0 min_level = 0 max_level = 0 reg_a = 0 reg_b = 0 reg_p = 0 with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 demand_table = '' #First row with period numbers demand_table += '' demand_table += '' for r in range(1,number_periods+2): # demand_table += '' demand_table += '' demand_table += '' #Second row with demands demand_table += '' demand_table += '' for row in csv_reader: if line_count == product_number: mu = int(f'{row[1]}') sigma = int(f'{row[2]}') min_level = int(f'{row[3]}') max_level = int(f'{row[4]}') ma10 = int(f'{row[5]}') reg_a = int(f'{row[6]}') reg_b = int(f'{row[7]}') reg_p = float(f'{row[8]}') demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_table += '' demand_data.append(int(f'{row[9]}')) demand_data.append(int(f'{row[10]}')) demand_data.append(int(f'{row[11]}')) demand_data.append(int(f'{row[12]}')) demand_data.append(int(f'{row[13]}')) demand_data.append(int(f'{row[14]}')) demand_data.append(int(f'{row[15]}')) demand_data.append(int(f'{row[16]}')) demand_data.append(int(f'{row[17]}')) demand_data.append(int(f'{row[18]}')) actual_demand = int(f'{row[19]}') line_count += 1 else: line_count += 1 demand_table += '' demand_table += '
Period' + str(r) + '
Demand
[units]
' + f'{row[9]}' +'' + f'{row[10]}' +'' + f'{row[11]}' +'' + f'{row[12]}' +'' + f'{row[13]}' +'' + f'{row[14]}' +'' + f'{row[15]}' +'' + f'{row[16]}' +'' + f'{row[17]}' +'' + f'{row[18]}' +'' + '?' +'
' return demand_table, ma10, actual_demand, demand_data, mu, sigma, min_level, max_level, reg_a, reg_b, reg_p def build_nn_table(demand_data): #Get weights and min max demands for normalization min_demand = [] max_demand = [] weight = [] bias_weight = 0 path = 'data/fc_experiment/nn_min_max_demand_and_weights.csv' with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count == 1: #Bias weight bias_weight = float(f'{row[3]}') line_count += 1 elif line_count >= 2: min_demand.append(float(f'{row[1]}')) max_demand.append(float(f'{row[2]}')) weight.append(float(f'{row[3]}')) line_count += 1 else: line_count += 1 normed_demand = [] normed_demand.append(0) weighted_normed_demand = [] weighted_normed_demand.append(0) print(min_demand) print(max_demand) print(demand_data) #Compute normed demand and weighted normed demand total_weighted_normed_demand = 0 for i in range(1,11): print(i) print(demand_data[i-1]) print(min_demand[i]) print(max_demand[i]) normed_demand.append((demand_data[i-1] - min_demand[i])/(max_demand[i] - min_demand[i])) weighted_normed_demand.append(normed_demand[i]*weight[i]) total_weighted_normed_demand += weighted_normed_demand[i] #Compute demand forecast demand_forecast_period_11_normed = total_weighted_normed_demand + bias_weight demand_forecast_period_11 = demand_forecast_period_11_normed * (max_demand[0] - min_demand[0]) + min_demand[0] #Consturct Table nn_table = '' #First row with headlines nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' #Fill with data for periods 1 to 10 for i in range(1,11): #iterate through 10 perids nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' #Fill with data for bias nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' #Demand Forecast normalized nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' #Demand Forecast de-normalized nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '' nn_table += '
Period tDemandNormed DemandWeightWeighted Normed Demand
' + str(i) + '' + str(demand_data[i-1]) + '' + str(round(normed_demand[i],3)) + '' + str(round(weight[i],3)) + '' + str(round(weighted_normed_demand[i],3)) + '
Bias1.000' + str(round(bias_weight,3)) + '' + str(round(bias_weight,3)) + '
Demand forecast for period 11 (normed)' + str(round(demand_forecast_period_11_normed,3)) + '
Demand forecast for period 11' + str(int(round(demand_forecast_period_11,0))) + '
' return nn_table def buildLikertScale(questions, question_order, text_at_top = 'Statement'): # table = '' table = '' width = 80 table += '' table += '' table += '' table += '' table += '' table += '' table += '' table += '' table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' table += '' table += '' question_counter = 0 likert_scale_number = 7 for q in question_order: question_counter += 1 table += '' table += '' for l in range(1,likert_scale_number+1): table += '' table += '' table += '' table += '
' + text_at_top + 'Strongly disagreeDisagreeSomewhat disagreeNeither agree nor disagreeSomewhat agreeAgreeStrongly agreeAussageTrifft überhaupt nicht zuTrifft nicht zuTrifft eher nicht zuTeils-teilsTrifft eher zuTrifft zuTrifft voll zu
' + str(questions[q-1]) + '
' return question_counter, table def buildLikertScale_appropriate(questions, question_order, text_at_top = 'Statement'): #CAUTION #This liket table "appropriate" is different two the normal likert table, since it allwos to be placed next to a normal likert table. #Therefore, the id has changed to "likert_table_appropriate" and the name tag of each radio button has changed from "q_" to "q_a_" # table = '' table = '' width = 80 table += '' table += '' table += '' table += '' table += '' table += '' table += '' table += '' table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' # table += '' table += '' table += '' question_counter = 0 likert_scale_number = 7 for q in question_order: question_counter += 1 table += '' table += '' for l in range(1,likert_scale_number+1): table += '' table += '' table += '' table += '
' + text_at_top + 'Much less than appropriateLess than appropriateA bit less than appropriateAppropriateA bit more than appropriateMore than appropriateMuch more than appropriateAussageTrifft überhaupt nicht zuTrifft nicht zuTrifft eher nicht zuTeils-teilsTrifft eher zuTrifft zuTrifft voll zu
' + str(questions[q-1]) + '
' return question_counter, table def getPayoffTable(self): product_order = self.participant.vars['product_order'] payoff_table = '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' for r in range(1,len(product_order)+1): payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '' payoff_table += '
Product
Your forecast
[units]
Actual demand
[units]
Forecast error
Reward
[USD]
' + str(r) + '' + str(self.participant.vars['second_judgement_' + str(product_order[r-1])]) + '' + str(self.participant.vars['actual_demand_' + str(product_order[r-1])]) + '' + str(round(self.participant.vars['forecast_error_' + str(product_order[r-1])],3)) + '' + str(self.participant.vars['payoff_' + str(product_order[r-1])]) + '
Bonus reward:' + str( self.participant.payoff_plus_participation_fee() - self.session.config['participation_fee']) + '
Fixed reward:' + str(self.session.config['participation_fee']) + '
Total reward:' + str(self.participant.payoff_plus_participation_fee()) + '
' return payoff_table