add definition of recipes in terms of other recipes
This commit is contained in:
23
common.py
23
common.py
@@ -10,7 +10,7 @@ def format_timestamp(timestamp):
|
||||
def parse_foods_file():
|
||||
path = Path.home() / 'projects' / 'open-journal' / 'foods'
|
||||
text = path.read_text()
|
||||
foods, recipes = text.split('---')
|
||||
foods, recipes_str = text.split('---')
|
||||
|
||||
def parse_macro(macro):
|
||||
if macro == '...':
|
||||
@@ -34,6 +34,8 @@ def parse_foods_file():
|
||||
result[k] = v
|
||||
return result
|
||||
|
||||
recipes = {}
|
||||
|
||||
def evaluate_ingredients(ingredients):
|
||||
result = {}
|
||||
|
||||
@@ -42,30 +44,31 @@ def parse_foods_file():
|
||||
k,v = parse_macro(ingredient)
|
||||
if k == 'TOTAL':
|
||||
result[k] = v
|
||||
break
|
||||
continue
|
||||
else:
|
||||
total_weight += v
|
||||
|
||||
food = foods.get(k)
|
||||
total = 100.0
|
||||
if not food:
|
||||
food = recipes[k].copy()
|
||||
total = food['TOTAL']
|
||||
del food['TOTAL']
|
||||
|
||||
food = foods[k]
|
||||
|
||||
for kk,vv in food.items():
|
||||
if kk not in result:
|
||||
result[kk] = 0.0
|
||||
|
||||
result[kk] += vv * (v/100.0)
|
||||
result[kk] += vv * (v/total)
|
||||
|
||||
if 'TOTAL' not in result:
|
||||
result['TOTAL'] = total_weight
|
||||
|
||||
return result
|
||||
|
||||
recipes = {
|
||||
ingredients[0]: evaluate_ingredients(ingredients[1:])
|
||||
for ingredients in [
|
||||
recipe.split('\n') for recipe in recipes.strip().split('\n\n')
|
||||
]
|
||||
}
|
||||
for ingredients in [recipe.split('\n') for recipe in recipes_str.strip().split('\n\n')]:
|
||||
recipes[ingredients[0]] = evaluate_ingredients(ingredients[1:])
|
||||
|
||||
def get_calories_from_macros(mm):
|
||||
calories = 0.0
|
||||
|
||||
46
foods
46
foods
@@ -640,6 +640,15 @@ Carbs 72g
|
||||
Sugar 3.9g
|
||||
Protein 11g
|
||||
|
||||
WholeGrainPasta
|
||||
Energy 350kcal
|
||||
Fat 2g
|
||||
SaturatedFat 0.4g
|
||||
Carbs 62g
|
||||
Sugar 3.6g
|
||||
Fiber 8g
|
||||
Protein 16g
|
||||
|
||||
SaskiaPeach
|
||||
Energy 16kcal
|
||||
Sugar 4g
|
||||
@@ -968,6 +977,11 @@ Milk 180g
|
||||
Potato 1000g
|
||||
TOTAL 1300g
|
||||
|
||||
MashedPotato2
|
||||
Margarine 20g
|
||||
Potato 760g
|
||||
Milk 300g
|
||||
|
||||
MashedPotato3
|
||||
Potato 1050g
|
||||
Milk 350g
|
||||
@@ -1009,6 +1023,13 @@ Oil 50g
|
||||
Sugar 12g
|
||||
Flour 300g
|
||||
|
||||
Pancake2
|
||||
AlmondMilk 650g
|
||||
Egg 130g
|
||||
Sugar 10g
|
||||
Oil 30g
|
||||
Flour 370g
|
||||
|
||||
CreamPotatoes
|
||||
Cheese 170g
|
||||
FoodCream 450g
|
||||
@@ -1068,11 +1089,6 @@ ProteinShake
|
||||
SkimMilk 400g
|
||||
ProteinPowder 60g
|
||||
|
||||
MashedPotato2
|
||||
Margarine 20g
|
||||
Potato 760g
|
||||
Milk 300g
|
||||
|
||||
VegeKotlet
|
||||
Oil 45g
|
||||
HarkisRouheseos 180g
|
||||
@@ -1112,6 +1128,12 @@ PeasCornPepper 220g
|
||||
Ketchup 100g
|
||||
TOTAL 740g
|
||||
|
||||
NyhtoKauraVeggies
|
||||
Oil 40g
|
||||
NyhtoKaura 240g
|
||||
PeasCornPepper 220g
|
||||
Ketchup 40g
|
||||
|
||||
Pancake
|
||||
SkimMilk 430g
|
||||
Water 300g
|
||||
@@ -1169,3 +1191,17 @@ Egg 130g
|
||||
PopcornDone
|
||||
Popcorn 150g
|
||||
Oil 40g
|
||||
|
||||
MacCheeseVeggies
|
||||
Cheese 150g
|
||||
Oil 20g
|
||||
PeasCornPepper 230g
|
||||
WholeGrainPasta 400g
|
||||
TOTAL 1270g
|
||||
|
||||
EggMacCheeseVeggies
|
||||
MacCheeseVeggies 215g
|
||||
Egg 325g
|
||||
Oil 20g
|
||||
Flour 20g
|
||||
Cheese 45g
|
||||
|
||||
Reference in New Issue
Block a user