feat: Added logic_processor with example statement, and diet restriction for Clients

This commit is contained in:
Jager72 2024-04-11 15:09:27 +02:00
parent 1f404aa166
commit c2b3944373
6 changed files with 34 additions and 8 deletions

View File

@ -64,6 +64,10 @@ for person in root.findall('person'):
favorite_meal_element = person.find('favoriteMeal') favorite_meal_element = person.find('favoriteMeal')
favorite_meal = favorite_meal_element.text if favorite_meal_element is not None else None 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]: if favorite_meal in [meal.nazwa for meal in meals]:
favorite_meal = next((meal for meal in meals if meal.nazwa == favorite_meal), None) favorite_meal = next((meal for meal in meals if meal.nazwa == favorite_meal), None)
@ -71,7 +75,8 @@ for person in root.findall('person'):
'imie': name, 'imie': name,
'nazwisko': surname, 'nazwisko': surname,
'wiek': age, 'wiek': age,
'ulubiony_posilek': favorite_meal 'ulubiony_posilek': favorite_meal,
'restrykcje_dietowe': restrictions
} }
clients.append(Klient(**person_data)) clients.append(Klient(**person_data))
@ -135,10 +140,13 @@ 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"Klient {klient.imie} {klient.nazwisko} ma następujące Zamowienia:")
print(f"\t{klient.rachunek} i sumą {klient.rachunek.suma()}") 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: # for meal in meals:
# print(meal) # print(meal)

View File

@ -3,14 +3,14 @@ from rachunek import Rachunek
import random import random
class Klient: class Klient:
def __init__(self,imie,nazwisko,wiek,ulubiony_posilek=None): def __init__(self,imie,nazwisko,wiek,ulubiony_posilek=None, restrykcje_dietowe=None):
self.imie = imie self.imie = imie
self.nazwisko = nazwisko self.nazwisko = nazwisko
self.wiek = wiek self.wiek = wiek
self.stolik = None self.stolik = None
self.rachunek = Rachunek(random.randint(1,1000)) self.rachunek = Rachunek(random.randint(1,1000))
self.ulubiony_posilek = ulubiony_posilek self.ulubiony_posilek = ulubiony_posilek
self.restrykcje_dietowe = restrykcje_dietowe
def zloz_zamowienie(self,zamowienie,stolik): def zloz_zamowienie(self,zamowienie,stolik):
if self.stolik is None: if self.stolik is None:
self.stolik = stolik self.stolik = stolik
@ -21,5 +21,5 @@ class Klient:
print("Klient ma juz przypisany stolik.") print("Klient ma juz przypisany stolik.")
def __str__(self): def __str__(self):
return f"Klient: {self.imie} {self.nazwisko} {self.wiek}, ulubione Danie: {self.ulubiony_posilek}" return f"Klient: {self.imie} {self.nazwisko} {self.wiek}, ulubione Danie: {self.ulubiony_posilek}, restrykcje diet: {self.restrykcje_dietowe}"

View File

@ -0,0 +1,14 @@
def diet_restriction(meals,client):
for meal in meals:
vegan,vegetarian,meat = meal.vegan_vegetarian_meat
print(meal)
print(client.restrykcje_dietowe)
if vegan and client.restrykcje_dietowe == 'Vegan':
return True
elif vegetarian and (client.restrykcje_dietowe == 'Vegetarian' or meat and client.restrykcje_dietowe == 'Vegan'):
return True
elif client.restrykcje_dietowe == 'Meat':
return True
else:
return False

View File

@ -5,7 +5,6 @@ from posilek import Posilek
class Zamowienie: class Zamowienie:
def __init__(self,numer_zamowienia,posilek): def __init__(self,numer_zamowienia,posilek):
self.numer_zamowienia = numer_zamowienia 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" assert all(isinstance(p, Posilek) for p in posilek), "Zamowienie: posilek nie jest listą tylko typu Posilek"
self.posilek = posilek self.posilek = posilek
def __str__(self): def __str__(self):

View File

@ -4,23 +4,28 @@
<surname>Bowie</surname> <surname>Bowie</surname>
<age>21</age> <age>21</age>
<favoriteMeal>Tatar</favoriteMeal> <favoriteMeal>Tatar</favoriteMeal>
<restrictions>Meat</restrictions>
</person> </person>
<person> <person>
<name>Kamil</name> <name>Kamil</name>
<surname>Stop</surname> <surname>Stop</surname>
<age>17</age> <age>17</age>
<favoriteMeal>Pomidorowa z Makaronem</favoriteMeal> <favoriteMeal>Pomidorowa z Makaronem</favoriteMeal>
<restrictions>Vegetarian</restrictions>
</person> </person>
<person> <person>
<name>Jon</name> <name>Jon</name>
<surname>Snow</surname> <surname>Snow</surname>
<age>23</age> <age>23</age>
<favoriteMeal>Grochówka</favoriteMeal> <favoriteMeal>Grochówka</favoriteMeal>
<restrictions>Vegan</restrictions>
</person> </person>
<person> <person>
<name>Andrzej</name> <name>Andrzej</name>
<surname>Kowalski</surname> <surname>Kowalski</surname>
<age>44</age> <age>44</age>
<favoriteMeal>Spaghetti Bolognese</favoriteMeal> <favoriteMeal>Spaghetti Bolognese</favoriteMeal>
<restrictions>Meat</restrictions>
</person> </person>
</people> </people>

View File

@ -66,7 +66,7 @@
</alergens> </alergens>
<vegetarian>false</vegetarian> <vegetarian>false</vegetarian>
<vegan>true</vegan> <vegan>true</vegan>
<meat>true</meat> <meat>false</meat>
</meal> <meal> </meal> <meal>
<name>Pomidorowa z Makaronem</name> <name>Pomidorowa z Makaronem</name>
<type>Soup</type> <type>Soup</type>