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 += '
| Ersatzteil | '
decision_table += 'Gewicht | '
decision_table += 'Häufigkeit des Defekts | '
decision_table += 'Vorschlag des Algorithmus | '
if show_selection_checkboxes:
decision_table += 'Ihre Auswahl | '
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 += ' |
|---|---|---|---|---|
| ' + t_number_to_letter(part_counter) + ' | ' #Part ID decision_table += '' + str(parts[position-1][1]) + ' | ' #Weight decision_table += '' + str(parts[position-1][2]) + ' | ' #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 += ' |
| ' #Total Weight decision_table += ' | ||||
| ' decision_table += ' | Summe Gewicht: | ' decision_table += '' + str(round(total_weight_opt)) + ' | ' if show_selection_checkboxes: decision_table += '0 | ' #Total Value decision_table += '|
| ' decision_table += ' | Summe Häufigkeit: | ' decision_table += '' + str(round(total_value_opt)) + ' | ' if show_selection_checkboxes: decision_table += '0 | ' decision_table += '|
| Ersatzteil | '
decision_table += 'Gewicht | '
decision_table += 'Häufigkeit des Defekts | '
decision_table += 'Vorschlag des Algorithmus | '
decision_table += 'Ihre Auswahl | '
decision_table += '' part_counter = 0 for position in part_order: part_counter += 1 bold_start = '' bold_end = '' feedback_table_tr_tag = ' |
|---|---|---|---|---|
| ' + bold_start + t_number_to_letter(part_counter) + bold_end + ' | ' #Part ID decision_table += '' + bold_start + str(parts[position-1][1]) + bold_end + ' | ' #Weight decision_table += '' + bold_start + str(parts[position-1][2]) + bold_end + ' | ' #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 += ' |
| ' #Total Weight decision_table += ' | ||||
| ' decision_table += ' | Summe Gewicht: | ' decision_table += '' + str(round(total_weight_opt)) + ' | ' decision_table += '0 | ' #Total Value decision_table += '|
| ' decision_table += ' | Summe Häufigkeit: | ' decision_table += '' + str(round(total_value_opt)) + ' | ' decision_table += '0 | ' decision_table += '|
| Statement | ' #table += 'Strongly disagree | ' #table += 'Disagree | ' #table += 'Somewhat disagree | ' #table += 'Neither agree nor disagree | ' #table += 'Somewhat agree | ' #table += 'Agree | ' #table += 'Strongly agree | ' table += 'Aussage | ' table += 'Trifft überhaupt nicht zu | ' table += 'Trifft nicht zu | ' table += 'Trifft eher nicht zu | ' table += 'Teils-teils | ' table += 'Trifft eher zu | ' table += 'Trifft zu | ' table += 'Trifft voll zu | ' table += '' question_counter = 0 likert_scale_number = 7 for q in question_order: question_counter += 1 table += ' |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ' + str(questions[q-1]) + ' | ' for l in range(1,likert_scale_number+1): table += '' table += ' | ' table += ' |