반응형
칼로리 트래커 / 대시보드 (1)
Introduction
하루 하루 섭취한 음식을 등록할 때 마다 동기적으로 변하는 대시보드가 있다면 누적 칼로리, 하루 칼로리량을 관리하고 한 눈에 확인하기에 간편할 것 같습니다.
Full Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
from dataclasses import dataclass
import numpy as np
import matplotlib.pyplot as plt
CALORIES_GOAL_LIMIT = 3000 # kcal
PROTEIN_GOAL = 180 # grams
FAT_GOAL = 80 # grams
CARBS_GOAL = 300 # grams
today = []
@dataclass
class Food:
name: str
calories: int
protein: int
fat: int
carbs: int
done = False
while not done:
print("""
(1) Add a new food
(2) Visualize progress
(q) quit
""")
choice = input("Choose an option: ")
if choice == "1":
print("Adding a new food!")
name = input("Name: ")
calories = int(input("Calories: "))
proteins = int(input("Proteins: "))
fats = int(input("Fats: "))
carbs = int(input("Carbs: "))
food = Food(name, calories, proteins, fats, carbs)
print("Successfully added!")
elif choice == "2":
calorie_sum = sum(food.calories for food in today)
protein_sum = sum(food.protein for food in today)
fats_sum = sum(food.fat for food in today)
carbs_sum = sum(food.carbs for food in today)
fig, axs = plt.subplots(2, 2)
axs[0, 0].pie([protein_sum, fats_sum, carbs_sum], labels=["Proteins", "Fats", "Carbs"], autopct="%1.1f%%")
axs[0, 0].set_title("Macronutirients Distribution")
axs[0, 1].bar([0,1,2], [protein_sum, fats_sum, carbs_sum], width=0.4)
axs[0, 1].bar([0.5, 1.5, 2.5], [PROTEIN_GOAL, FAT_GOAL, CARBS_GOAL, width=0.4)
axs[0, 1].set_title("Macronutrients Progress")
axs[1, 0].pie([calorie_sum, CALORIE_GOAL_LIMIT - calorie_sum], labels=["Calories", "Remaining"], autopct="%1.1f%%")
axs[1, 0].set_title("Calories Goal Progress")
axs[1, 1].plot(list(range(len(today))), np.cumsum([food.calories for food in today]), labels="Calories Eaten")
axs[1, 1].plot(list(range(len(today))), [CALORIE_GOAL_LIMIT] * len(today), label="Calorie Goal")
axs[1, 1].set_legend()
axs[1, 1].set_title("Calories Goal Over Time")
fig.tight_layout()
fig.show()
elif choice == "q":
done = True
else:
print("Invalid choice!")
|
cs |
실행
반응형
'공부 > 파이썬 Python' 카테고리의 다른 글
카운터와 딕셔너리의 차이 in Python (0) | 2022.03.20 |
---|---|
다항식 회귀 (Polynomial Regression)이란 (0) | 2022.03.19 |
비밀번호 관리 매니저 만들기 using Python (0) | 2022.03.18 |
Pygorithm으로 알고리즘 공부하기 (0) | 2022.03.17 |
Python 대역폭 모니터 만들어보기 (Bandwidth Monitor Using Python) (0) | 2022.03.17 |
댓글