diff --git a/DecisionTree/IMG_20230525_193651.jpg b/DecisionTree/IMG_20230525_193651.jpg new file mode 100644 index 0000000..b667a8b Binary files /dev/null and b/DecisionTree/IMG_20230525_193651.jpg differ diff --git a/DecisionTree/decision_based_on_table_script.py b/DecisionTree/decision_based_on_table_script.py new file mode 100644 index 0000000..9c9a42e --- /dev/null +++ b/DecisionTree/decision_based_on_table_script.py @@ -0,0 +1,84 @@ +def read_text_document(file_path): # read given amount of lines (lines of 8 integers) + string_array = [] + + try: + with open(file_path, 'r') as file: + # Read each line of the document + for line in file: + # Remove trailing newline characters and append to the array + string_array.append(line.rstrip('\n')) + except FileNotFoundError: + print("File not found.") + + return string_array # returns array of lines from the file + + +def gen_output(array, second_array): # transcribes line of integers into elemental decisions of shelf "g" and "d" + if array[0] == 0 or array[0] == 1: + second_array[0] = "g" + else: + second_array[0] = "d" + if array[1] == 1 or array[1] == 2: + second_array[1] = "d" + else: + second_array[1] = "g" + if array[2] == 0: + second_array[2] = "g" + else: + second_array[2] = "d" + if array[3] == 0: + second_array[3] = "g" + else: + second_array[3] = "d" + if array[4] == 0: + second_array[4] = "d" + else: + second_array[4] = "g" + if array[5] == 0: + second_array[5] = "g" + else: + second_array[5] = "d" + if array[6] == 0: + second_array[6] = "d" + else: + second_array[6] = "g" + if array[7] == 0: + second_array[7] = "d" + else: + second_array[7] = "g" + +def count(array): # count number of g and d and make decision, if same number return 2 instead + d = 0 + g = 0 + for digit in array: + if digit == "g": + g += 1 + else: + d += 1 + if d > g: + return 0 # lower shelf + elif g > d: + return 1 # upper shelf + else: + return 2 # optimisation of space, goes to more empty shelf overall + +file_path = 'file/path/to/input/lines/of/integers' +examples = read_text_document(file_path) # array of given number of examples from file + +for input in examples: + digit_array = [] + + for char in input: + # Convert the character to an integer and add it to the array + digit_array.append(int(char)) + + output_array = [None] * 8 + gen_output(digit_array, output_array) + + decision_output = count(output_array) + if decision_output == 2: # in case d == g, check which shelf is more empty + if output_array[7] == "g": + decision_output = 1 + elif output_array[7] == "d": + decision_output = 0 + print(decision_output) # final decision \ No newline at end of file diff --git a/etykieta.py b/etykieta.py index bec7199..ffe86da 100644 --- a/etykieta.py +++ b/etykieta.py @@ -1,10 +1,11 @@ import secrets, string class Etykieta: - def __init__(self, nadawca, adres, imie, nazwisko, telefon): + def __init__(self, nadawca, adres, imie, nazwisko, telefon, priorytet): self.nadawca = nadawca self.adres = adres self.imie = imie self.nazwisko = nazwisko self.telefon = telefon + self.priorytet = priorytet self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9)) \ No newline at end of file diff --git a/packageList.py b/packageList.py index 44915fe..7195b0f 100644 --- a/packageList.py +++ b/packageList.py @@ -11,6 +11,6 @@ class listOfPackages: def zainicjuj_liste_paczek(): from paczka import Paczka packageList = listOfPackages() - demo_paczka = Paczka('duzy', 10, any, False, any, any, any, any, any) + demo_paczka = Paczka('duzy', 10, any, False, True, False, any, any, any, any, any) packageList.add(demo_paczka) return packageList diff --git a/paczka.py b/paczka.py index f9d4af1..5d63453 100644 --- a/paczka.py +++ b/paczka.py @@ -4,7 +4,7 @@ import pygame class Paczka: - def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon): + def __init__(self, rozmiar, waga, kategoria, priorytet, ksztalt, kruchosc, nadawca, adres, imie, nazwisko, telefon): self.rozmiar = rozmiar self.image = pygame.image.load("images/paczka.png") if rozmiar == 'duzy': @@ -26,10 +26,12 @@ class Paczka: self.rozmiar = 'undefined' self.waga = waga self.kategoria = kategoria - self.czy_krucha = czy_krucha + self.priorytet = priorytet + self.ksztalt = ksztalt + self.kruchosc = kruchosc self.x = 430 self.y = 400 - self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon) + self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon, priorytet) # zmienia rozmiar obrazka w zaleznosci od rozmiaru def __dobierz_rozmiar_obrazka(self):