prepare for upload
This commit is contained in:
37
analyze.py
37
analyze.py
@@ -5,6 +5,8 @@ from functools import reduce
|
|||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
def parse_foods_file():
|
def parse_foods_file():
|
||||||
path = Path.home() / 'projects' / 'open-journal' / 'foods'
|
path = Path.home() / 'projects' / 'open-journal' / 'foods'
|
||||||
text = path.read_text()
|
text = path.read_text()
|
||||||
@@ -70,7 +72,7 @@ def parse_foods_file():
|
|||||||
for k,v in mm.items():
|
for k,v in mm.items():
|
||||||
calories += v * {
|
calories += v * {
|
||||||
'Carbs': 4,
|
'Carbs': 4,
|
||||||
'Fat': 8,
|
'Fat': 9,
|
||||||
'Protein': 4
|
'Protein': 4
|
||||||
}.get(k, 0.0)
|
}.get(k, 0.0)
|
||||||
return calories
|
return calories
|
||||||
@@ -82,6 +84,32 @@ def parse_foods_file():
|
|||||||
|
|
||||||
foods, recipes = 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)
|
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]+)')
|
diet_re = re.compile(r'@diet (\d+g) ([a-zA-Z]+)')
|
||||||
@@ -91,7 +119,7 @@ total_words = 0
|
|||||||
word_frequency = Counter()
|
word_frequency = Counter()
|
||||||
|
|
||||||
total_csv = [['day', 'entries', 'words']]
|
total_csv = [['day', 'entries', 'words']]
|
||||||
daily_csv = [['day', 'entries', 'words', 'calories']]
|
daily_csv = [['day', 'entries', 'words', 'calories', 'protein']]
|
||||||
entry_csv = [['timestamp', 'words']]
|
entry_csv = [['timestamp', 'words']]
|
||||||
words_csv = [['word', 'count']]
|
words_csv = [['word', 'count']]
|
||||||
|
|
||||||
@@ -108,6 +136,7 @@ for fpath in sorted((Path.home() / 'workspace' / 'journal').glob('*.md')):
|
|||||||
daily_entries = len(entries)
|
daily_entries = len(entries)
|
||||||
daily_words = 0
|
daily_words = 0
|
||||||
daily_calories = 0.0
|
daily_calories = 0.0
|
||||||
|
daily_protein = 0.0
|
||||||
|
|
||||||
for (timestamp, content) in sorted(entries, key=lambda x: x[0]):
|
for (timestamp, content) in sorted(entries, key=lambda x: x[0]):
|
||||||
timestamp = int(datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S').timestamp())
|
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_calories += food.get('Energy', 0.0)
|
||||||
|
daily_protein += food.get('Protein', 0.0)
|
||||||
|
|
||||||
words = ''.join(
|
words = ''.join(
|
||||||
c if c in string.ascii_letters+"'" else ' '
|
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])
|
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_entries += daily_entries
|
||||||
total_words += daily_words
|
total_words += daily_words
|
||||||
|
|||||||
103
foods
103
foods
@@ -251,12 +251,13 @@ Coffee
|
|||||||
Energy 0kcal
|
Energy 0kcal
|
||||||
|
|
||||||
Oatmeal
|
Oatmeal
|
||||||
Energy 68kcal
|
Energy 362kcal
|
||||||
Fat 1.4g
|
Fat 7.5g
|
||||||
Carbs 12g
|
SaturatedFat 1.3g
|
||||||
Sugar 0.5g
|
Carbs 54g
|
||||||
Fiber 1.7g
|
Sugar 1.1g
|
||||||
Protein 2.4g
|
Fiber 11g
|
||||||
|
Protein 14g
|
||||||
|
|
||||||
VahvlitortTallinn
|
VahvlitortTallinn
|
||||||
Energy 505kcal
|
Energy 505kcal
|
||||||
@@ -363,6 +364,36 @@ Sugar 5.7g
|
|||||||
Protein 1.3g
|
Protein 1.3g
|
||||||
Salt 1.27g
|
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
|
Omlette
|
||||||
@@ -371,9 +402,34 @@ Cheese 25g
|
|||||||
Egg 180g
|
Egg 180g
|
||||||
Flour 25g
|
Flour 25g
|
||||||
Milk 80g
|
Milk 80g
|
||||||
Oil 25g
|
Oil 20g
|
||||||
Salt 2g
|
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
|
MashedPotato
|
||||||
Margarine 40g
|
Margarine 40g
|
||||||
Milk 180g
|
Milk 180g
|
||||||
@@ -388,18 +444,21 @@ SojaRouha 300g
|
|||||||
PeasCornPepper 225g
|
PeasCornPepper 225g
|
||||||
TOTAL 2460g
|
TOTAL 2460g
|
||||||
|
|
||||||
RoastedVeggies
|
|
||||||
Oil 100g
|
|
||||||
Potato 1000g
|
|
||||||
SweetPotato 450g
|
|
||||||
|
|
||||||
MilkSoup
|
MilkSoup
|
||||||
Margarine 30g
|
Margarine 30g
|
||||||
Milk 500g
|
Milk 500g
|
||||||
Oil 25g
|
Oil 25g
|
||||||
Pasta 350g
|
Pasta 350g
|
||||||
Sugar 10g
|
Sugar 10g
|
||||||
TOTAL 1315
|
TOTAL 1315g
|
||||||
|
|
||||||
|
MilkSoup2
|
||||||
|
Margarine 30g
|
||||||
|
Milk 480g
|
||||||
|
Oil 20g
|
||||||
|
Sugar 15g
|
||||||
|
Pasta 350g
|
||||||
|
TOTAL 1940g
|
||||||
|
|
||||||
Pancake
|
Pancake
|
||||||
Egg 120g
|
Egg 120g
|
||||||
@@ -414,19 +473,13 @@ FoodCream 450g
|
|||||||
Oil 50g
|
Oil 50g
|
||||||
Potato 1500g
|
Potato 1500g
|
||||||
|
|
||||||
FakeChickenVeggies
|
|
||||||
FakeChicken 250g
|
|
||||||
Oil 50g
|
|
||||||
PeasCornPepper 225g
|
|
||||||
|
|
||||||
OmletteWithoutMilk
|
|
||||||
Cheese 25g
|
|
||||||
Egg 180g
|
|
||||||
Flour 25g
|
|
||||||
Milk 80g
|
|
||||||
Oil 25g
|
|
||||||
|
|
||||||
ProteinSpaghettiBolognese
|
ProteinSpaghettiBolognese
|
||||||
ProteinSpaghetti 500g
|
ProteinSpaghetti 500g
|
||||||
PastaSauce 500g
|
PastaSauce 500g
|
||||||
TOTAL 1640g
|
TOTAL 1640g
|
||||||
|
|
||||||
|
OatmealPorridge
|
||||||
|
Oatmeal 150g
|
||||||
|
Margarine 14g
|
||||||
|
Honey 25g
|
||||||
|
TOTAL 700g
|
||||||
|
|||||||
Reference in New Issue
Block a user