import csv import random def build_table(table_id, treatment): path = 'data/parts_' + str(table_id) + '.csv' decision_table = '' capacity = 0 with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 decision_table += '
Item ID | '
decision_table += 'Weight [lb] | '
decision_table += 'Value [¢] | '
decision_table += 'Ratio [¢/lb] | '
if treatment != 'no_sol':
decision_table += 'Recommendation | ' #We do not set a recommendation column for treatment 'no_sol'
decision_table += 'Your Selection | '
decision_table += '' for row in csv_reader: if line_count == 0: # We take only the capacity from line 1 capacity = float(f'{row[7]}') line_count += 1 else: decision_table += ' | |
---|---|---|---|---|---|---|---|
' + (f'{row[0]}') + ' | ' #Part ID decision_table += '' + (f'{row[1]}') + ' | ' #Weight decision_table += '' + (f'{row[2]}') + ' | ' #Value #decision_table += '' + str(round(float(f'{row[3]}'),2)) + ' | ' #Ratio decision_table += '' + (f'{row[3]}') + ' | ' #Ratio #Recommendation is only given in treatments 'opt_sol' and 'heur_sol' if treatment == 'opt_sol': rec = '' if int((f'{row[4]}')) == 1: rec = 'checked=true' decision_table += '' elif treatment == 'heur_sol': rec = '' if int((f'{row[5]}')) == 1: rec = 'checked=true' decision_table += ' | ' decision_table += ' | ' line_count += 1 decision_table += ' |
' #Total Weight decision_table += ' | |||||||
' if treatment != 'no_sol': decision_table += ' | ' decision_table += ' | Total Weight: 0lb | ' #Total Value decision_table += '|||||
' if treatment != 'no_sol': decision_table += ' | ' decision_table += ' | Total Value: 0¢ | ' decision_table += '
Item ID | '
feedback_table += 'Weight [lb] | '
feedback_table += 'Value [USD] | '
feedback_table += 'Ratio [USD/lb] | '
if treatment != 'no_sol':
feedback_table += 'Recommendation | ' #We do not set a recommendation column for treatment 'no_sol'
feedback_table += 'Your Selection | '
feedback_table += '' for row in csv_reader: if line_count == 0: # We take only the capacity from line 1 capacity = float(f'{row[7]}') line_count += 1 else: bold_start = '' bold_end = '' if current_part == part_drawn: feedback_table += ' |
---|---|---|---|---|---|---|
' + bold_start + (f'{row[0]}') + bold_end + ' | ' #Item ID feedback_table += '' + bold_start + (f'{row[1]}') + bold_end + ' | ' #Weight feedback_table += '' + bold_start + (f'{row[2]}') + bold_end + ' | ' #Value feedback_table += '' + bold_start + (f'{row[3]}') + bold_end + ' | ' #Ratio #Recommendation is only given in treatments 'opt_sol' and 'heur_sol' if treatment == 'opt_sol': rec = '' if int((f'{row[4]}')) == 1: rec = 'checked=true' feedback_table += '' + bold_start + '' + bold_end + ' | ' elif treatment == 'heur_sol': rec = '' if int((f'{row[5]}')) == 1: rec = 'checked=true' feedback_table += '' + bold_start + '' + bold_end + ' | ' #Own Selection from previous round dec = '' #print('Decision for part ' + str(current_part) + ' is ' + str(decision[current_part-1])) if decision[current_part-1] == 'true': dec = 'checked = true' feedback_table += '' + bold_start + '' + bold_end + ' | ' line_count += 1 current_part += 1 feedback_table += '
' feedback_table += ' | ||||||
Total Weight: | 0 | '
feedback_table += '
Round ID | '
result_table += 'Total Weight [lb] | '
result_table += 'Total Value [¢] | '
result_table += '|||
---|---|---|---|---|---|
' sumvalue = 0 for r in range(1,rounds+1): result_table += ' | |||||
' + str(r) + ' | ' result_table += '' + str(weight[r-1]) + ' | ' result_table += '' + str(value[r-1]) + ' | ' result_table += '|||
' result_table += ' | |||||
Total Value: | ' + str(sumvalue) + '¢ | ' result_table += '
Question | ' table += 'Strongly disagree | ' table += 'Disagree | ' #table += 'Somewhat disagree | ' table += 'Neither agree nor disagree | ' #table += 'Somewhat agree | ' table += 'Agree | ' table += 'Strongly agree | ' table += '' question_counter = 0 likert_scale_number = 5 for q in questions: question_counter += 1 table += ' |
---|---|---|---|---|---|---|---|
' + str(q) + ' | ' for l in range(1,likert_scale_number+1): table += '' table += ' |