feat: Changed Data Representation to Frames (XML to Python Classes), fixed Added Classes.

This commit is contained in:
Jager72 2024-04-11 13:20:29 +02:00
parent 86f4cc52c0
commit 42782fdcc0
14 changed files with 353 additions and 117 deletions

View File

@ -0,0 +1,143 @@
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
person_data = {
'imie': name,
'nazwisko': surname,
'wiek': age
}
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(2):
zamowienie.append(meals[random.randint(0, len(meals)-1)])
zamowienia.append(Zamowienie(i+1, zamowienie))
for stolik in stoliki:
klient = clients[random.randint(0, len(clients)-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()}")
# for meal in meals:
# print(meal)
# for client in clients:
# print(client)
# for server in servers:
# print(server)

View File

@ -1,7 +1,9 @@
import pygame
import prefs
class Kelner:
def __init__ (self, imie, nazwisko,numer_pracowniczy):
self.imie = imie
self.nazwisko = nazwisko
self.numer_pracowniczy = numer_pracowniczy
def __str__(self):
return f"{self.imie} {self.nazwisko} ({self.numer_pracowniczy})"

View File

@ -1,17 +1,23 @@
import pygame
import prefs
from rachunek import Rachunek
import random
class Klient:
def __init__(self,imie,nazwisko,wiek):
self.imie = imie
self.nazwisko = nazwisko
self.wiek = wiek
self.stolik = None
self.rachunek = Rachunek(random.randint(1,1000))
def zloz_zamowienie(self,zamowienie,stolik):
if self.stolik is None:
self.stolik = stolik
stolik.przypisz_kelnera(stolik.kelner)
stolik.dodaj_zamowienie(zamowienie)
stolik.przypisz_kelner(stolik.kelner)
self.rachunek.dodaj_zamowienie(zamowienie)
print(f"Klinet {self.imie} {self.nazwisko} zlozyl zamowienie przy stoliku {stolik.numer_stolika} i przyjal je kelner {stolik.kelner.numer_pracowniczy}.")
else:
print("Klient ma juz przypisany stolik.")
def __str__(self):
return f"Klient: {self.imie} {self.nazwisko} {self.wiek}"

12
classes/data/posilek.py Normal file
View File

@ -0,0 +1,12 @@
import pygame
class Posilek:
def __init__(self,nazwa,typ,cena,alergeny,vegan_vegetarian_meat):
self.nazwa = nazwa
self.typ = typ
self.cena = cena
self.alergeny = alergeny
self.vegan_vegetarian_meat = vegan_vegetarian_meat
def __str__(self):
return f"Posilek: {self.nazwa}, Typ: {self.typ}, Cena: {self.cena}, Alergeny: {self.alergeny}, Vegan/Vegetarian/Meat: {self.vegan_vegetarian_meat}"

21
classes/data/rachunek.py Normal file
View File

@ -0,0 +1,21 @@
import pygame
from zamowenie import Zamowienie
class Rachunek:
def __init__(self,numer_zamowienia):
self.numer_zamowienia = numer_zamowienia
self.zamowienia = []
def dodaj_zamowienie(self,zamowienie):
self.zamowienia.append(zamowienie)
def suma(self):
suma_rachunek = 0
for zamowienie in self.zamowienia:
suma_rachunek += sum(zamowienie.sum() for zamowienie in self.zamowienia)
return suma_rachunek
def __str__(self):
print(self.zamowienia)
return f"Rachunek nr {self.numer_zamowienia}:\n\tSuma: {self.suma()}\n\tZamówienia:\n\t\t{''.join([str(zamowienie) for zamowienie in self.zamowienia])}"

View File

@ -1,5 +1,4 @@
import pygame
import prefs
class Stolik:
def __init__(self,numer_stolika):
self.numer_stolika = numer_stolika

15
classes/data/zamowenie.py Normal file
View File

@ -0,0 +1,15 @@
import pygame
from stolik import Stolik
from kelner import Kelner
from posilek import Posilek
class Zamowienie:
def __init__(self,numer_zamowienia,posilek):
self.numer_zamowienia = numer_zamowienia
print(type(posilek))
assert all(isinstance(p, Posilek) for p in posilek), "Zamowienie: posilek nie jest listą tylko typu Posilek"
self.posilek = posilek
def __str__(self):
return f"Zamowienie numer {self.numer_zamowienia} z posiłkami {[p.nazwa for p in self.posilek]}"
def sum(self):
return sum(p.cena for p in self.posilek)

View File

@ -1,10 +0,0 @@
import pygame
import prefs
class Posilek:
def __init__(self,nazwa,typ,cena,alergeny,czy_wege):
self.nazwa = nazwa
self.typ = typ
self.cena = cena
self.alergeny = alergeny
self.czy_wege = czy_wege

View File

@ -1,16 +0,0 @@
import pygame
import prefs
class Rachunek:
def __init__(self,numer_zamowienia):
self.numer_zamowienia = numer_zamowienia
self.zamowienia = []
def dodaj_zamowienie(self,zamowienie):
if zamowienie.numer_zamowienia == self.numer_zamowienia:
self.zamowienia.append(zamowienie)
def suma(self):
suma_rachunek = 0
for zamowienie in self.zamowienia:
suma_rachunek += zamowienie.posilek.cena
return suma_rachunek

View File

@ -1,8 +0,0 @@
import pygame
import prefs
class Zamowienie:
def __init__(self,numer_zamowienia,stolik,kelner,posilek):
self.numer_zamowienia = numer_zamowienia
self.stolik = stolik
self.kelner = kelner
self.posilek = posilek

22
database/clients.xml Normal file
View File

@ -0,0 +1,22 @@
<people>
<person>
<name>David</name>
<surname>Bowie</surname>
<age>21</age>
</person>
<person>
<name>Kamil</name>
<surname>Stop</surname>
<age>17</age>
</person>
<person>
<name>Jon</name>
<surname>Snow</surname>
<age>23</age>
</person>
<person>
<name>Andrzej</name>
<surname>Kowalski</surname>
<age>44</age>
</person>
</people>

115
database/meals.xml Normal file
View File

@ -0,0 +1,115 @@
<meals>
<meal>
<name>Spaghetti Bolognese</name>
<type>Main</type>
<price>12.99</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>false</vegan>
<meat>true</meat>
</meal>
<meal>
<name>Schabowy</name>
<type>Main</type>
<price>36.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>false</vegan>
<meat>true</meat>
</meal>
<meal>
<name>Grochówka</name>
<type>Soup</type>
<price>20.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>true</vegetarian>
<vegan>false</vegan>
<meat>false</meat>
</meal> <meal>
<name>Fielt z Piersi Kurczaka</name>
<type>Main</type>
<price>34</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>false</vegan>
<meat>true</meat>
</meal> <meal>
<name>Tatar</name>
<type>Starter</type>
<price>24.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>false</vegan>
<meat>true</meat>
</meal> <meal>
<name>Pyra z Gzikiem</name>
<type>Starter</type>
<price>12.99</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>true</vegan>
<meat>true</meat>
</meal> <meal>
<name>Pomidorowa z Makaronem</name>
<type>Soup</type>
<price>18.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>true</vegetarian>
<vegan>false</vegan>
<meat>false</meat>
</meal> <meal>
<name>Szczawiowa z Jajkiem</name>
<type>Soup</type>
<price>20</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>true</vegetarian>
<vegan>false</vegan>
<meat>false</meat>
</meal> <meal>
<name>Boczniaki w Panierce</name>
<type>Main</type>
<price>34.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>true</vegetarian>
<vegan>false</vegan>
<meat>false</meat>
</meal> <meal>
<name>Wątróbka z Cebulą</name>
<type>Main</type>
<price>30.00</price>
<alergens>
<alergen>Gluten</alergen>
<alergen>Dairy</alergen>
</alergens>
<vegetarian>false</vegetarian>
<vegan>false</vegan>
<meat>true</meat>
</meal>
</meals>

13
database/servers.xml Normal file
View File

@ -0,0 +1,13 @@
<servers>
<server>
<name>Dzesika</name>
<surname>Płot</surname>
<employee_number>1</employee_number>
</server>
<server>
<name>Mariusz</name>
<surname>Kamień</surname>
<employee_number>2</employee_number>
</server>
</servers>

View File

@ -1,78 +0,0 @@
from pyswip import Prolog
prolog = Prolog ()
prolog.assertz("kelner(marta,komar,01)")
prolog.assertz("kelner(adam,bocian,02)")
prolog.assertz("kelner(wanda,sowa,03)")
prolog.assertz("kelner(piotr,skowron,04)")
prolog.assertz("klient(adam,kowalski,17)")
prolog.assertz("klient(anna,nowak,19)")
prolog.assertz("klient(jan,wisniewski,18)")
prolog.assertz("klient(katarzyna,dabrowska,41)")
prolog.assertz("klient(zofia,dabrowska,11)")
prolog.assertz("klient(michal,lewandowski,67)")
prolog.assertz("klient(magdadalena,wozniak,24)")
prolog.assertz("klient(pawel,kaminski,33)")
prolog.assertz("klient(karolina,kozlowska,39)")
prolog.assertz("klient(tomasz,jankowski,29)")
prolog.assertz("klient(monika,wieczorek,56)")
prolog.assertz("posilek(rosol_z_makaronem,zupa,10.00,[seler,gluten,jaja],miesne)")
prolog.assertz("posilek(pomidorowa,zupa,10.00,[gluten,seler],wegetarianskie)")
prolog.assertz("posilek(zurek,zupa,10.00,[gluten,jaja,mleko,seler],miesne)")
prolog.assertz("posilek(brokulowa,zupa,10.00,[seler],weganskie)")
prolog.assertz("posilek(kotlet_schabowy,danie_glowne,20.00,[gluten,jaja,mleko],miesne)")
prolog.assertz("posilek(devolay_z_maslem,danie_glowne,15.00,[gluten,jaja,mleko],miesne)")
prolog.assertz("posilek(grillowany_filet_z_kurczaka,danie_glowne,20.00,[gluten,soja,mleko,seler],miesne")
prolog.assertz("posilek(klopsiki_w_sosie_pomidorowym,danie_glowne,15.00,[gluten,jaja,seler],miesne)")
prolog.assertz("posilek(pieczone_udko_z_kurczaka,danie_glowne,25.00,[soja,seler],miesne)")
prolog.assertz("posilek(placki_ziemniaczane,danie_glowne,10.00,[gluten,jaja],wegetarianskie)")
prolog.assertz("posilek(nalesniki_z_serem,danie_glowne,10.00,[gluten,jaja,mleko],wegeterianskie)")
prolog.assertz("posilek(camembert_z_zurawina,danie_glowne,15.00,[gluten,mleko],wegetarianskie)")
prolog.assertz("posilek(curry_z_tofu,danie_glowne,15.00,[soja,orzechy],weganskie)")
prolog.assertz("posilek(ziemniaki,dodatek,8.00,[],weganskie)")
prolog.assertz("posilek(ryz,dodatek,6.00,[gluten,soja],weganskie)")
prolog.assertz("posilek(kasza_gryczna,dodatek,6.00,[gluten,soja],weganskie)")
prolog.assertz("posilek(frytki,dodatek,9.00,[],weganskie)")
prolog.assertz("posilek(sernik,deser,12.00,[mleko,jaja,gluten],wegetarianskie)")
prolog.assertz("posilek(brownie,deser,15.00,[mleko,jaja,gluten,orzechy],wegetarianskie)")
prolog.assertz("posilek(lody_waniliowe,deser,5.00,[mleko],wegetarianskie)")
prolog.assertz("posilek(panna_cotta,deser,17.00,[mleko],wegetarianskie)")
prolog.assertz("posilek(kawa_czarna,napoj_cieply,6.00,[],weganskie)")
prolog.assertz("posilek(kawa_biala,napoj_cieply,7.00,[mleko],wegetarianskie)")
prolog.assertz("posilek(herbata_zielona,napoj_cieply,5.00,[],weganskie)")
prolog.assertz("posilek(cola,napoj_zimny,6.00,[],weganskie)")
prolog.assertz("posilek(fanta,napoj_zimny,6.00,[],weganskie)")
prolog.assertz("posilek(sprite,napoj_zimny,6.00,[],weganskie)")
prolog.assertz("posilek(woda_niegazowana,napoj_zimny,3.00,[],weganskie)")
prolog.assertz("posilek(woda_gazowana,napoj_zimny,3.00,[],weganskie)")
prolog.assertz("posilek(ice_tea,napoj_zimny,6.00,[],weganskie)")
prolog.assertz("posilek(piwo,napoj_alkoholowy,12.00,[jeczmien,gluten,siarczyny,drodze],weganskie)")
prolog.assertz("posilek(whiskey,napoj_alkoholowy,15.00,[gluten],weganskie)")
prolog.assertz("posilek(wino,napoj_alkoholowy,17.00,[siarczyny],weganskie)")
prolog.assertz("posilek(wodka,napoj_alkoholowy,8.00,[],weganskie)")
prolog.assertz("stolik(1)")
prolog.assertz("stolik(2)")
prolog.assertz("stolik(3)")
prolog.assertz("stolik(4)")
prolog.assertz("stolik(5)")
prolog.assertz("stolik(6)")
prolog.assertz("stolik(7)")
prolog.assertz("stolik(8)")
prolog.assertz("stolik(9)")
prolog.assertz("stolik(10)")
prolog.assertz("zamowienie(Numer_zamowienia, Stolik, Kelner, Posilek) :- stolik(Stolik), kelner(_, _, Kelner), klient(_, _, _), posilek(Posilek, _, _, _, _).")