194 lines
6.0 KiB
Python
194 lines
6.0 KiB
Python
import xml.etree.ElementTree as ET
|
|
from classes.data.posilek import Posilek
|
|
from classes.data.klient import KlientCechy
|
|
from classes.data.klient import Klient
|
|
from classes.data.kelner import Kelner
|
|
from classes.data.stolik import Stolik
|
|
from classes.data.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)
|
|
|
|
wrinkles_element = person.find('Wrinkles')
|
|
wrinkles = wrinkles_element.text if wrinkles_element is not None else ''
|
|
|
|
balding_element = person.find('Balding')
|
|
balding = balding_element.text if balding_element is not None else ''
|
|
|
|
beard_element = person.find('Beard')
|
|
beard = beard_element.text if beard_element is not None else ''
|
|
|
|
outfit_element = person.find('Outfit')
|
|
outfit = outfit_element.text if outfit_element is not None else ''
|
|
|
|
image_element = person.find('Image')
|
|
|
|
import os
|
|
import random
|
|
folder = "classes\\Jimmy_Neuron\\test"
|
|
file_list = os.listdir(folder)
|
|
image = os.path.join(folder, random.choice(file_list))
|
|
|
|
tattoo_element = person.find('Tattoo')
|
|
tattoo = tattoo_element.text if tattoo_element is not None else ''
|
|
|
|
hair_element = person.find('Hair')
|
|
hair = hair_element.text if hair_element is not None else ''
|
|
|
|
behaviour_element = person.find('Behaviour')
|
|
behaviour = behaviour_element.text if behaviour_element is not None else ''
|
|
|
|
person_data = {
|
|
'imie': name,
|
|
'nazwisko': surname,
|
|
'wiek': age,
|
|
'ulubiony_posilek': favorite_meal,
|
|
'restrykcje_dietowe': restrictions,
|
|
'zmarszczki': wrinkles,
|
|
'lysienie': balding,
|
|
'broda': beard,
|
|
'ubior': outfit,
|
|
'tatuaz': tattoo,
|
|
'wlosy': hair,
|
|
'zachowanie': behaviour,
|
|
'zdjecie': image
|
|
}
|
|
|
|
clients.append(KlientCechy(**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 classes.data.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) |