update
This commit is contained in:
21
common.py
21
common.py
@@ -4,6 +4,9 @@ from datetime import datetime
|
||||
def parse_timestamp(timestamp):
|
||||
return datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
|
||||
|
||||
def format_timestamp(timestamp):
|
||||
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
def parse_foods_file():
|
||||
path = Path.home() / 'projects' / 'open-journal' / 'foods'
|
||||
text = path.read_text()
|
||||
@@ -79,4 +82,22 @@ def parse_foods_file():
|
||||
|
||||
return foods, recipes
|
||||
|
||||
def evaluate_food_entry(foods, recipes, value, name):
|
||||
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}')
|
||||
|
||||
return food
|
||||
|
||||
|
||||
Reference in New Issue
Block a user