import csv import random import math def t_number_to_letter(number): letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] return letters[number-1] def t_part_id_to_position_in_part_order(part_id, part_order): position_in_part_order = -1 # print("This is the part order " + str(part_order)) # print("This is the part id w are looking for " + str(part_id)) for i in range(len(part_order)): if part_order[i] == part_id: position_in_part_order = i+1 break return position_in_part_order def get_part_set(): path = 'data/parts_bm_scm.csv' capacity = 0 parts = [] 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 take only the capacity from line 1 capacity = float(f'{row[9]}') line_count += 1 else: parts.insert(line_count-1,[int(f'{row[0]}'), int(f'{row[1]}'), int(f'{row[2]}'), float(f'{row[3]}'), int(f'{row[4]}')]) line_count += 1 return parts, capacity def build_table(part_order, treatment, deactivated, show_selection_checkboxes): # path = 'data/parts_bm_scm.csv' parts, capacity = get_part_set() if(len(part_order) != len(parts)): print("ERROR: The length of the part list csv is not euqal to the part order array!") print("Part Order") print(part_order) decision_table = '' total_weight_opt = 0 total_value_opt = 0 round_selection_opt = '' #Style Settings color = 'black' selection_checkbox = '' if deactivated: #Style color = 'grey' sort_link = '' selection_checkbox = 'disabled="true"' #CSS Style decision_table += '' # 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 show_selection_checkboxes: decision_table += '' decision_table += '' decision_table += '' part_counter = 0 for position in part_order: part_counter += 1 #if parts[position-1][4] == 1: # total_weight_opt += parts[position-1][1] # total_value_opt += parts[position-1][2] if parts[part_counter-1][4] == 1: total_weight_opt += parts[part_counter-1][1] total_value_opt += parts[part_counter-1][2] round_selection_opt += 'true,' else: round_selection_opt += 'false,' decision_table += '' decision_table += '' #Part ID decision_table += '' #Weight decision_table += '' #Value rec_presel = '' rec = '' if parts[position-1][4] == 1: rec = 'checked=true' decision_table += '' if show_selection_checkboxes: decision_table += '' decision_table += '' decision_table += '' decision_table += '' #Total Weight decision_table += '' decision_table += '' decision_table += '' if show_selection_checkboxes: decision_table += '' #Total Value decision_table += '' decision_table += '' decision_table += '' if show_selection_checkboxes: decision_table += '' decision_table += '
Ersatzteil
Gewicht
Häufigkeit
des Defekts
Vorschlag des
Algorithmus

Ihre Auswahl
' + t_number_to_letter(part_counter) + '' + str(parts[position-1][1]) + '' + str(parts[position-1][2]) + '' + str(parts[position-1][0]) + '
Summe Gewicht: ' + str(round(total_weight_opt)) + ' 0
Summe Häufigkeit:' + str(round(total_value_opt)) + '0
' return decision_table, int(capacity), int(total_weight_opt), int(total_value_opt), round_selection_opt def build_feedback_table(part_order, treatment, deactivated, decision_str, part_drawn): # path = 'data/parts_bm_scm.csv' parts, capacity = get_part_set() # print(decision_str) decision = decision_str.split(",") print(decision) if(len(part_order) != len(parts)): print("ERROR: The length of the part list csv is not euqal to the part order array!") # print("Part Order") # print(part_order) decision_table = '' total_weight_opt = 0 total_value_opt = 0 round_selection_opt = '' right_part_selected = False #Style Settings color = 'black' selection_checkbox = '' if deactivated: #Style color = 'black' sort_link = '' selection_checkbox = 'disabled="true"' #CSS Style decision_table += '' # 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 += '' decision_table += '' decision_table += '' decision_table += '' part_counter = 0 for position in part_order: part_counter += 1 bold_start = '' bold_end = '' feedback_table_tr_tag = '' if parts[position-1][0] == part_drawn: feedback_table_tr_tag = '' # bold_start = '' # bold_end = '' if decision[position-1] == 'true': right_part_selected = True if parts[position-1][4] == 1: total_weight_opt += parts[position-1][1] total_value_opt += parts[position-1][2] round_selection_opt += 'true,' else: round_selection_opt += 'false,' decision_table += feedback_table_tr_tag decision_table += '' #Part ID decision_table += '' #Weight decision_table += '' #Value rec = '' if parts[position-1][4] == 1: rec = 'checked=true' decision_table += '' dec = '' #print('Decision for part ' + str(current_part) + ' is ' + str(decision[current_part-1])) if decision[position-1] == 'true': dec = 'checked = true' decision_table += '' decision_table += '' decision_table += '' decision_table += '' #Total Weight decision_table += '' decision_table += '' decision_table += '' decision_table += '' #Total Value decision_table += '' decision_table += '' decision_table += '' decision_table += '' decision_table += '
Ersatzteil
Gewicht
Häufigkeit
des Defekts
Vorschlag des
Algorithmus

Ihre Auswahl
' + bold_start + t_number_to_letter(part_counter) + bold_end + '' + bold_start + str(parts[position-1][1]) + bold_end + '' + bold_start + str(parts[position-1][2]) + bold_end + '' + str(parts[position-1][0]) + '
Summe Gewicht: ' + str(round(total_weight_opt)) + ' 0
Summe Häufigkeit:' + str(round(total_value_opt)) + '0
' return decision_table, right_part_selected def build_table_old(part_order, treatment, deactivated, own_decision, show_value_and_weight_recommendation, preselected): path = 'data/parts_bm_scm.csv' decision_table = '' capacity = 0 total_weight_sug = 0 total_value_sug = 0 round_selection_sug = '' #Style Settings color = 'black' sort_link = 'href="#"' selection_checkbox = '' if deactivated: #Style color = 'grey' sort_link = '' selection_checkbox = 'disabled="true"' #CSS Style decision_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 += '
StatementStrongly 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 getSelectionPageTreatmentText(key, recommendation_decision, next_button, treatment): color_deactivated = 'black' color_no = '' color_yes = '' disabled = '' btn_class = '' buttons = '' if key == 'disabled': disabled = 'disabled' color_deactivated = 'grey' if recommendation_decision == 'opt': color_no = 'style="background-color: ' + color_deactivated + '; border-color: ' + color_deactivated + '"' if recommendation_decision == 'none': color_yes = 'style="background-color: ' + color_deactivated + '; border-color: ' + color_deactivated + '"' if next_button == False: btn_class = 'type="button" name="offer_accepted" value="False" class="btn btn-primary btn-large"' treatment_text = '' if treatment == 'decide_opt_sol' or treatment == 'decide_opt_sol_v': treatment_text += '' treatment_text += 'Do you want to see the recommendation of the algorithm?' treatment_text += '
' treatment_text += 'Please note that you can make this choice only once per round and cannot change your decision!' treatment_text += '
' treatment_text += '
' treatment_text += '
' treatment_text += '  ' treatment_text += '' treatment_text += '
' elif treatment == 'opt_heur_dec' or treatment == 'opt_heur_dec_c': treatment_text += '' treatment_text += 'Which recommendation would you like to see?' treatment_text += '
' if treatment == 'opt_heur_dec': treatment_text += 'Please note that you can make this choice only once per round and cannot change your decision!' treatment_text += '
' treatment_text += '
' treatment_text += '
' treatment_text += '  ' treatment_text += '' treatment_text += '
' elif treatment == 'decide_three_sol_c': buttons = ["opt", "second", "third"] random.shuffle(buttons) print("Shuffled button sequence: " + str(buttons)) treatment_text += '' treatment_text += 'Which recommendation would you like to see?' treatment_text += '
' # if treatment == 'opt_heur_dec': # treatment_text += 'Please note that you can make this choice only once per round and cannot change your decision!' treatment_text += '
' treatment_text += '
' treatment_text += '
' treatment_text += '  ' treatment_text += '  ' treatment_text += '  ' treatment_text += '
' return treatment_text, str(buttons) def getSelectionPageButton(own_decision_button, next_button): color_deactivated = 'black' color_own_decision = '' color_next = '' disabled_own_decision = '' disabled_next = '' btn_class = 'type="button" name="offer_accepted" value="False" class="btn btn-primary btn-large"' button_text = '' if own_decision_button == True: disabled_next = 'disabled' else: disabled_own_decision = 'disabled' if next_button == False: disabled_next = 'disabled' # color_deactivated = 'grey' # if recommendation_decision == 'opt': # color_no = 'style="background-color: ' + color_deactivated + '; border-color: ' + color_deactivated + '"' # if recommendation_decision == 'none': # color_yes = 'style="background-color: ' + color_deactivated + '; border-color: ' + color_deactivated + '"' # if next_button == False: # btn_class = 'type="button" name="offer_accepted" value="False" class="btn btn-primary btn-large"' button_text += '  ' if own_decision_button == True: button_text += '  ' # button_text += '' # button_text = '' return button_text