Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 178 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,184 @@ A starter project for the Core program final project:

https://hub.hackyourfuture.nl/core-program-week-14

A nutrition tracking app focused on **behavior change**, not just calorie counting.

The system helps users:
- understand their eating patterns
- receive structured feedback
- improve habits through measurable adjustments

Core principle:
**log → see → understand → adjust**

---

## 🎯 Project Goals

### 1. Motivation for Behavior Change
Help users improve eating habits through clear feedback

### 2. Motivation for Behavior Maintenance
Support consistency via simple daily evaluation

---

## 🧠 Motivation Tools

### Awareness through Data
- Users see actual intake vs goals

### Scoring System
- Daily score: **1–10**
- Based on deviation from goals
- Simplifies complex nutrition data

---

## ⚙️ Usage Configuration

The system allows users to:
- Select which parameters to track
- Define their own target values

---

## 🧭 Recommended Tracking Approaches

### Beginner Approach
- Calories
- Protein
- Fat
- Carbohydrates

### Full Tracking Approach
- Calories
- Protein
- Fat
- Carbohydrates
- Water
- Caffeine
- Alcohol

### Goal-Oriented Tracking

Examples:
- Alcohol reduction → track alcohol only
- Hydration improvement → track water

If unsure, start with the Beginner Approach and expand later.

---

## 🎯 Goal Setting

Users define their own targets for each parameter.

---

## 🔄 User Flow

1. Registration
2. Profile setup
3. Meal logging
4. Aggregation
5. AI evaluation
6. Daily report

---

## 🧠 Core Logic

**Log → Aggregate → Evaluate → Recommend → Adjust**

---

## 🧩 Features

- Food logging
- Macro & extended tracking
- Daily scoring
- AI-generated feedback
- Personalized recommendations

---

## 📊 Outputs

### Daily Summary (AI-generated)

```
SUMMARY: ...
SCORE: X/10

MACROS:
- Kcal: X / Y — under/on target/over
- Protein: Xg / Yg — under/on target/over
- Fat: Xg / Yg — under/on target/over
- Carbs: Xg / Yg — under/on target/over
- Water: Xml / Yml — under/on target/over
- Caffeine: Xmg / Ymg — under/on target/over
- Alcohol: Xml / Yml — under/on target/over

RECOMMENDATIONS:
- ...
- ...
```

---

### Daily Meals (CLI format)

```
DAILY MEALS

Date: YYYY-MM-DD

------------------------------------------------------------
Meal | Product | Kcal | Prot | Fat | Carbs
------------------------------------------------------------
Breakfast | Oatmeal 100g | 120 | 4g | 2g | 21g
Breakfast | Banana 120g | 105 | 1g | 0g | 27g

Lunch | Chicken 200g | 330 | 62g | 7g | 0g

Dinner | Rice 150g | 180 | 4g | 1g | 40g
------------------------------------------------------------

TOTALS
Kcal: X
Protein: Xg
Fat: Xg
Carbs: Xg
Water: X ml
Caffeine: X mg
Alcohol: X ml
```

---

## 🤖 AI Evaluation System

The system uses an LLM to analyze daily totals and generate structured feedback.

### AI Responsibilities

1. Parameter Evaluation
2. Daily Score (1–10)
3. Recommendations

---

## Input

```
GOALS:
kcal: X, protein: Xg, fat: Xg, carbs: Xg, water: Xml, caffeine: Xmg, alcohol: Xml

MEALS:
- MealType: Product amount (kcal, protein, fat, carbs)
```

## Setup

1. Clone the repository
Expand Down
Binary file modified src/databases/food_tracker.db
Binary file not shown.
136 changes: 136 additions & 0 deletions src/databases/queries.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
-- USERS

-- name: createUser(saveUser)
INSERT INTO users (email, name, age, weight, height)
VALUES (?, ?, ?, ?, ?);

-- name: getUserById
SELECT * FROM users
WHERE id = ?;

-- name: updateUser
UPDATE users
SET
email = ?,
name = ?,
age = ?,
weight = ?,
height = ?
WHERE id = ?;

-- GOALS

-- name: createGoal(saveGoal)
INSERT INTO goals (user_id, kcal, protein, fat, carbs, water, caffeine, alcohol)
VALUES (?, ?, ?, ?, ?, ?, ?, ?);

-- name: getUserGoals
SELECT * FROM goals
WHERE user_id = ?;

-- name: updateGoal
UPDATE goals
SET
kcal = ?,
protein = ?,
fat = ?,
carbs = ?,
water = ?,
caffeine = ?,
alcohol = ?
WHERE user_id = ?;

-- MEALS

-- name: createMeal
INSERT INTO meals (
user_id,
created_at,
name,
quantity,
calories,
protein,
fat,
carbs,
water,
caffeine,
alcohol
)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);

-- name: getMealById
SELECT *
FROM meals
WHERE id = ?;

-- name: updateMeal
UPDATE meals
SET
name = ?,
quantity = ?,
calories = ?,
protein = ?,
fat = ?,
carbs = ?,
water = ?,
caffeine = ?,
alcohol = ?
WHERE id = ?;

-- name: deleteMeal
DELETE FROM meals
WHERE id = ?;

-- name: getAllMeals
SELECT *
FROM meals
WHERE user_id = ?
ORDER BY created_at DESC;

-- name: getMealsByDate
SELECT *
FROM meals
WHERE user_id = ?
AND DATE(created_at) = ?;

-- ANALYTICS

-- name: getDailyTotals
SELECT
SELECT
COALESCE(SUM(calories), 0) AS total_kcal,
COALESCE(SUM(protein), 0) AS total_protein,
COALESCE(SUM(fat), 0) AS total_fat,
COALESCE(SUM(carbs), 0) AS total_carbs,
COALESCE(SUM(water), 0) AS total_water,
COALESCE(SUM(caffeine), 0) AS total_caffeine,
COALESCE(SUM(alcohol), 0) AS total_alcohol
FROM meals
WHERE user_id = ?
AND DATE(created_at) = ?;

-- name: getDailyComparison
SELECT
g.kcal AS goal_kcal,
SUM(m.calories) AS actual_kcal,
SUM(m.calories) - g.kcal AS diff_kcal,

g.protein,
SUM(m.protein) AS actual_protein,
SUM(m.protein) - g.protein AS diff_protein,

g.fat,
SUM(m.fat) AS actual_fat,
SUM(m.fat) - g.fat AS diff_fat,

g.carbs,
SUM(m.carbs) AS actual_carbs,
SUM(m.carbs) - g.carbs AS diff_carbs

FROM goals g
JOIN meals m ON g.user_id = m.user_id

WHERE g.user_id = ?
AND DATE(m.created_at) = ?

GROUP BY g.kcal, g.protein, g.fat, g.carbs;
51 changes: 51 additions & 0 deletions src/databases/schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email TEXT,
name TEXT,
age INT,
weight FLOAT,
height FLOAT
);

CREATE TABLE goals (
id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
kcal INT,
protein FLOAT,
fat FLOAT,
carbs FLOAT,
water FLOAT,
caffeine FLOAT,
alcohol FLOAT,

CONSTRAINT fk_goals_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE
);

CREATE TABLE meals (
id SERIAL PRIMARY KEY,
user_id INT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
source TEXT,
name TEXT,
quantity FLOAT,
calories FLOAT,
protein FLOAT,
fat FLOAT,
carbs FLOAT,
water FLOAT,
caffeine FLOAT,
alcohol FLOAT,

CONSTRAINT fk_meals_user
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE
);


CREATE INDEX idx_meals_user ON meals(user_id);
CREATE INDEX idx_meals_created_at ON meals(created_at);
CREATE INDEX idx_goals_user ON goals(user_id);
Loading