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 += '' decision_table += '' decision_table += '' decision_table += '' decision_table += '' decision_table += '' if treatment != 'no_sol': decision_table += '' #We do not set a recommendation column for treatment 'no_sol' decision_table += '' decision_table += '' 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 += '' decision_table += '' #Part ID decision_table += '' #Weight decision_table += '' #Value #decision_table += '' #Ratio decision_table += '' #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 += '' decision_table += '' #Total Weight decision_table += '' if treatment != 'no_sol': decision_table += '' decision_table += '' #Total Value decision_table += '' if treatment != 'no_sol': decision_table += '' decision_table += '' decision_table += '
Item
ID
Weight
[lb]
Value
[¢]
Ratio
[¢/lb]
Recommendation
Your Selection
' + (f'{row[0]}') + '' + (f'{row[1]}') + '' + (f'{row[2]}') + '' + str(round(float(f'{row[3]}'),2)) + '' + (f'{row[3]}') + '
Total Weight: 0lb
Total Value: 0¢
' return decision_table, int(capacity) def build_feedback_table(table_id, treatment, decision_str, part_drawn): path = 'data/parts_' + str(table_id) + '.csv' print(decision_str) decision = decision_str.split(",") print(decision) feedback_table = '' capacity = 0 current_part = 1 with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 feedback_table += '' feedback_table += '' feedback_table += '' feedback_table += '' feedback_table += '' feedback_table += '' if treatment != 'no_sol': feedback_table += '' #We do not set a recommendation column for treatment 'no_sol' feedback_table += '' feedback_table += '' 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 = '' bold_end = '' else: feedback_table += '' feedback_table += '' #Item ID feedback_table += '' #Weight feedback_table += '' #Value feedback_table += '' #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 += '' elif treatment == 'heur_sol': rec = '' if int((f'{row[5]}')) == 1: rec = 'checked=true' feedback_table += '' #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 += '' line_count += 1 current_part += 1 feedback_table += '' feedback_table += '' feedback_table += '' feedback_table += '
Item
ID
Weight
[lb]
Value
[USD]
Ratio
[USD/lb]
Recommendation
Your Selection
' + bold_start + (f'{row[0]}') + bold_end + '' + bold_start + (f'{row[1]}') + bold_end + '' + bold_start + (f'{row[2]}') + bold_end + '' + bold_start + (f'{row[3]}') + bold_end + '' + bold_start + '' + bold_end + '' + bold_start + '' + bold_end + '' + bold_start + '' + bold_end + '
Total Weight:

0

' return feedback_table, capacity def partDrawnWasSelected(decision_str, part_drawn): decision = decision_str.split(",") if decision[part_drawn-1] == 'true': return True else: return False def getTextFeedbackPage(decision, part_drawn): text_begin = ('According to the probabilities shown part ' + str(part_drawn) + ' was drawn.' '
') if partDrawnWasSelected(decision, part_drawn): text_begin += 'Well done! You had the required part ' + str(part_drawn) + ' in your vehicle. You reveive 1 ECU for this round.' else: text_begin += 'You did not select the required part into your vehice. You do not receive a payment for this round.' return text_begin def getTextTreatmentPage(treatment): title = '' text_begin = '' table_explanation = ('The table contains the following information' '
' '
' '' '
' 'You can order the item table by Item ID, Weight, Value or Ratio by clicking on the table headings.') return title, text_begin, table_explanation def getRandomPart(table_id): path = 'data/parts_' + str(table_id) + '.csv' prob_smaller_than_current_part = 0 part_probabilities = [] with open(path) as csv_file: csv_reader = csv.reader(csv_file, delimiter=';') line_count = 0 for row in csv_reader: if line_count == 0: # We do not need the capacity line_count += 1 else: prob_smaller_than_current_part += float(f'{row[2]}') part_probabilities.append(prob_smaller_than_current_part) line_count += 1 #DEVELOPMENT print('Probabilities: ' + str(part_probabilities)) random_nr = random.uniform(0, 1) part_id = 0 #DEVELOPMENT print('Random Numbers: ' + str(random_nr)) for part_probability in part_probabilities: part_id = part_id+1 if random_nr <= part_probability: break print('Part ID: ' + str(part_id)) return part_id def buildResultTable(rounds, weight, value): result_table = '' result_table += '' result_table += '' result_table += '' result_table += '' result_table += '' result_table += '' sumvalue = 0 for r in range(1,rounds+1): result_table += '' result_table += '' result_table += '' result_table += '' result_table += '' sumvalue = sumvalue+value[r-1] sumvalue_cent = int(sumvalue) sumvalue_dollar = sumvalue_cent/100 result_table += '' result_table += '' result_table += '' result_table += '
Round
ID
Total Weight
[lb]
Total Value
[¢]
' + str(r) + '' + str(weight[r-1]) + '' + str(value[r-1]) + '
Total Value:' + str(sumvalue) + '¢
' return sumvalue_cent, sumvalue_dollar, result_table def buildLikertScale(questions): # table = '' table = '' width = 107 table += '' table += '' table += '' table += '' #table += '' table += '' #table += '' table += '' table += '' table += '' table += '' question_counter = 0 likert_scale_number = 5 for q in questions: question_counter += 1 table += '' table += '' for l in range(1,likert_scale_number+1): table += '' table += '' table += '
QuestionStrongly disagreeDisagreeSomewhat disagreeNeither agree nor disagreeSomewhat agreeAgreeStrongly agree
' + str(q) + '
' return question_counter, table