prepare for upload

This commit is contained in:
olari
2021-05-14 19:53:44 +03:00
parent ea61d14250
commit ca7ce0e37c
2 changed files with 112 additions and 28 deletions

View File

@@ -5,6 +5,8 @@ from functools import reduce
import re
import string
import sys
def parse_foods_file():
path = Path.home() / 'projects' / 'open-journal' / 'foods'
text = path.read_text()
@@ -70,7 +72,7 @@ def parse_foods_file():
for k,v in mm.items():
calories += v * {
'Carbs': 4,
'Fat': 8,
'Fat': 9,
'Protein': 4
}.get(k, 0.0)
return calories
@@ -82,6 +84,32 @@ def parse_foods_file():
foods, recipes = parse_foods_file()
if len(sys.argv) > 1:
value, name = sys.argv[1:]
value = float(value.removesuffix('g'))
if name in recipes:
food = recipes[name]
if value == 0.0:
value = food['TOTAL']
food = {k: v*(value/food['TOTAL']) for k,v in food.items()}
elif name in foods:
if value == 0.0:
value = 100
food = {k: v*(value/100.0) for k,v in foods[name].items()}
else:
breakpoint()
print(f'ERROR: Invalid diet entry: {content}')
from pprint import pprint
pprint(food)
exit(0)
entry_re = re.compile(r'^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) ', re.MULTILINE)
diet_re = re.compile(r'@diet (\d+g) ([a-zA-Z]+)')
@@ -91,7 +119,7 @@ total_words = 0
word_frequency = Counter()
total_csv = [['day', 'entries', 'words']]
daily_csv = [['day', 'entries', 'words', 'calories']]
daily_csv = [['day', 'entries', 'words', 'calories', 'protein']]
entry_csv = [['timestamp', 'words']]
words_csv = [['word', 'count']]
@@ -108,6 +136,7 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
daily_entries = len(entries)
daily_words = 0
daily_calories = 0.0
daily_protein = 0.0
for (timestamp, content) in sorted(entries, key=lambda x: x[0]):
timestamp = int(datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S').timestamp())
@@ -153,6 +182,7 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
))
daily_calories += food.get('Energy', 0.0)
daily_protein += food.get('Protein', 0.0)
words = ''.join(
c if c in string.ascii_letters+"'" else ' '
@@ -166,7 +196,8 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
entry_csv.append([timestamp, entry_words])
daily_csv.append([day, daily_entries, daily_words, daily_calories])
daily_csv.append([day, daily_entries, daily_words, daily_calories,
daily_protein])
total_entries += daily_entries
total_words += daily_words

103
foods
View File

@@ -251,12 +251,13 @@ Coffee
Energy 0kcal
Oatmeal
Energy 68kcal
Fat 1.4g
Carbs 12g
Sugar 0.5g
Fiber 1.7g
Protein 2.4g
Energy 362kcal
Fat 7.5g
SaturatedFat 1.3g
Carbs 54g
Sugar 1.1g
Fiber 11g
Protein 14g
VahvlitortTallinn
Energy 505kcal
@@ -363,6 +364,36 @@ Sugar 5.7g
Protein 1.3g
Salt 1.27g
Orange
Energy 50kcal
Carbs 13g
Fiber 2.2g
Sugar 8.5g
WokMix
Energy 36kcal
Carbs 5.5g
Sugar 3.9g
Fiber 2.7g
Protein 1.7g
Salt 0.04g
ProteinRahka
Energy 67kcal
Fat 0.2g
SaturatedFat 0.1g
Carbs 6.0g
Sugar 5.9g
Protein 10g
Salt 0.06g
Watermelon
Energy 30kcal
Carbs 8g
Sugar 6g
Fiber 0.4g
Protein 0.6g
---
Omlette
@@ -371,9 +402,34 @@ Cheese 25g
Egg 180g
Flour 25g
Milk 80g
Oil 25g
Oil 20g
Salt 2g
RoastedVeggies
Oil 80g
Potato 1000g
SweetPotato 450g
OmletteWithoutMilk
Cheese 25g
Egg 180g
Flour 25g
Milk 80g
Oil 20g
FriedPotatoes
Potato 1560g
Oil 60g
BoiledWokMix
WokMix 400g
Oil 25g
FakeChickenVeggies
FakeChicken 250g
Oil 40g
PeasCornPepper 225g
MashedPotato
Margarine 40g
Milk 180g
@@ -388,18 +444,21 @@ SojaRouha 300g
PeasCornPepper 225g
TOTAL 2460g
RoastedVeggies
Oil 100g
Potato 1000g
SweetPotato 450g
MilkSoup
Margarine 30g
Milk 500g
Oil 25g
Pasta 350g
Sugar 10g
TOTAL 1315
TOTAL 1315g
MilkSoup2
Margarine 30g
Milk 480g
Oil 20g
Sugar 15g
Pasta 350g
TOTAL 1940g
Pancake
Egg 120g
@@ -414,19 +473,13 @@ FoodCream 450g
Oil 50g
Potato 1500g
FakeChickenVeggies
FakeChicken 250g
Oil 50g
PeasCornPepper 225g
OmletteWithoutMilk
Cheese 25g
Egg 180g
Flour 25g
Milk 80g
Oil 25g
ProteinSpaghettiBolognese
ProteinSpaghetti 500g
PastaSauce 500g
TOTAL 1640g
OatmealPorridge
Oatmeal 150g
Margarine 14g
Honey 25g
TOTAL 700g