import xml.etree.ElementTree as ET from posilek import Posilek from klient import Klient from kelner import Kelner from stolik import Stolik from zamowenie import Zamowienie with open('database\\meals.xml', 'r') as file: xml_data = file.read() tree = ET.ElementTree(ET.fromstring(xml_data)) root = tree.getroot() meals = [] for meal in root.findall('meal'): name_element = meal.find('name') name = name_element.text if name_element is not None else '' surname_element = meal.find('type') type = surname_element.text if surname_element is not None else '' age_element = meal.find('price') price = float(age_element.text) if age_element is not None and age_element.text else 0.0 alergens_element = meal.find('alergens') alergens = [alergen.text for alergen in alergens_element] if alergens_element is not None else [] vegetarian_element = meal.find('vegetarian') vegetarian = vegetarian_element.text == 'true' if vegetarian_element is not None else False vegan_element = meal.find('vegan') vegan = vegan_element.text == 'true' if vegan_element is not None else False meat_element = meal.find('meat') meat = meat_element.text == 'true' if meat_element is not None else False meal_data = { 'nazwa': name, 'typ': type, 'cena': price, 'alergeny': alergens, 'vegan_vegetarian_meat': (vegetarian, vegan, meat) } meals.append(Posilek(**meal_data)) # Use the posilek_instance as needed with open('database\\clients.xml', 'r') as file: xml_data = file.read() tree = ET.ElementTree(ET.fromstring(xml_data)) root = tree.getroot() clients = [] for person in root.findall('person'): name_element = person.find('name') name = name_element.text if name_element is not None else '' surname_element = person.find('surname') surname = surname_element.text if surname_element is not None else '' age_element = person.find('age') age = int(age_element.text) if age_element is not None and age_element.text else 0 favorite_meal_element = person.find('favoriteMeal') favorite_meal = favorite_meal_element.text if favorite_meal_element is not None else None restriction_element = person.find('restrictions') restrictions = restriction_element.text if restriction_element is not None else None if favorite_meal in [meal.nazwa for meal in meals]: favorite_meal = next((meal for meal in meals if meal.nazwa == favorite_meal), None) person_data = { 'imie': name, 'nazwisko': surname, 'wiek': age, 'ulubiony_posilek': favorite_meal, 'restrykcje_dietowe': restrictions } clients.append(Klient(**person_data)) # Use the person_instance as needed with open('database\\servers.xml', 'r') as file: xml_data = file.read() tree = ET.ElementTree(ET.fromstring(xml_data)) root = tree.getroot() servers = [] for server in root.findall('server'): name_element = server.find('name') name = name_element.text if name_element is not None else '' surname_element = server.find('surname') surname = surname_element.text if surname_element is not None else '' employee_number_element = server.find('employee_number') employee_number = int(employee_number_element.text) if employee_number_element is not None and employee_number_element.text else 0 server_data = { 'imie': name, 'nazwisko': surname, 'numer_pracowniczy': employee_number } servers.append(Kelner(**server_data)) # Prezentacja uzycia przykładowego import random stoliki = [] for i in range(3): stolik = Stolik(i+1) stoliki.append(stolik) stolik.przypisz_kelner(servers[i%len(servers)]) zamowienia = [] for i in range(6): zamowienie = [] for j in range(random.randint(1, 5)): zamowienie.append(meals[random.randint(0, len(meals)-1)]) zamowienia.append(Zamowienie(i+1, zamowienie)) i=0 for stolik in stoliki: klient = clients[i%len(clients)] i=i+1 klient.zloz_zamowienie(zamowienia[random.randint(0, len(zamowienia)-1)], stolik) for klient in [k for k in clients if k.stolik is not None]: print(f"Klient {klient.imie} {klient.nazwisko} ma następujące Zamowienia:") print(f"\t{klient.rachunek} i sumą {klient.rachunek.suma()}") print("----------------\n\n") import logic_test as logic for klient in [k for k in clients if k.stolik is not None]: for zamownienie in klient.rachunek.zamowienia: print(logic.diet_restriction(zamowienie, klient)) # for meal in meals: # print(meal) # for client in clients: # print(client) # for server in servers: # print(server)