A python-powered command-line application for tracking and analyzing daily/weekly habits. Built with object-oriented and functional programming paradigms.
- Create Habits: Define habits by task name, periodicity, and category.
- Track Completion: Record timestamps for habit completions.
- Analyze Progress: Calculate streaks, filter habits by periodicity/category, and generate reports.
- Data Management: Habits stored locally in an SQLite database.
- Command-line UI: User-friendly interface with
click.
-
Clone the repository:
git clone https://github.com/mardlpz/habit-tracker.git
-
Navigate to project directory:
(Replace with actual local path to cloned repository.)
cd path/to/habit-tracker -
Create virtual environment:
python -m venv .venv
-
Activate virtual environment:
On macOS/Linux:
source .venv/bin/activateOn Windows:
.venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Basic command-line interaction:
python -m habit_tracker.cli <command> --[option]
-
Create habits
- Command:
create - Options:
- Task name (mandatory, string):
--taskor--t - Periodicity (mandatory, 'daily' or 'weekly'):
--periodicityor--p - Category (optional, default: general):
--categoryor--c
- Task name (mandatory, string):
- Example:
python -m habit_tracker.cli create --task "Exercise" --periodicity daily --category health - Command:
-
Complete a Habit
- Command:
complete - Options:
- ID (mandatory):
--id
- ID (mandatory):
- Example:
python -m habit_tracker.cli complete --id 4 - Command:
-
List Habits
- Command:
list - Options (default: lists all habits):
- Periodicity (optional, 'daily' or 'weekly'):
--periodicityor--p - Category (optional):
--categoryor--c
- Periodicity (optional, 'daily' or 'weekly'):
- Example:
python -m habit_tracker.cli list --periodicity weekly --category education
- Command:
-
Analyze Habits
- Command:
analyze - Options:
- ID (for specific habit analysis):
--id - Periodicity:
--periodicityor--p - Category:
--categoryor--c - Longest streak:
--longest-streakor--ls - Current streak:
--current-streakor--cs - Completion rate:
--completion-rateor--cr - Most struggled habit:
--most-struggledor--ms - Weekly report:
--weekly-reportor--wr - Monthly report:
--monthly-reportor--mr
- ID (for specific habit analysis):
- Example:
python -m habit_tracker.cli analyze --longest-streak python -m habit_tracker.cli analyze --current-streak python -m habit_tracker.cli analyze --completion-rate python -m habit_tracker.cli analyze --most-struggled python -m habit_tracker.cli analyze --weekly-report python -m habit_tracker.cli analyze --monthly-report
- Command:
*--most-struggled, --weekly-report, and --monthly-report do not apply for specific analysis by ID, cannot be performed on a single habit.
-
Delete a Habit
- Command:
delete - Options:
- ID (mandatory):
--id
- ID (mandatory):
- Example:
python -m habit_tracker.cli delete --id 4
- Command:
-
Reset database
- Command:
reset - Example:
python -m habit_tracker.cli reset
- Command:
-
Exit and clear terminal
- Command:
exit - Example:
python -m habit_tracker.cli exit - Command:
Habit data is stored in an SQLite database contained within the file
"habits.db" (data/habits.db). The database is automatically created if it doesn’t exist yet.
When opening the file in an IDE such as PyCharm, habits and completions tables can be visualized
in ascending and descending order. It is important to refresh the file after an operation has
been performed on the database.
The application provides a file with sample data (sample_data.py) including 5 predefined habits with 4 weeks of tracking records each:
- Drink Water (Daily, Health)
- Yoga (Weekly, Health)
- Read (Daily, Education)
- Journal (Weekly, Mental Health)
- Meditate (Daily, Mental Health)
Load sample data into database with:
python sample_data.pyThe application includes a collection of pytest test cases to validate the core functionality. The test fixtures provide sample habit data with predefined completion dates to ensure consistent and reproducible test results. Run the unit tests with:
pytest tests/Exit and deactivate the virtual environment with:
deactivateAll code is documented with descriptive Python docstrings for further clarification. To access the help documentation directly from the command-line interface use the following commands:
- General help:
python -m habit_tracker.cli --help
- Command-specific help:
python -m habit_tracker.cli analyze --help python -m habit_tracker.cli complete --help python -m habit_tracker.cli create --help python -m habit_tracker.cli delete --help python -m habit_tracker.cli exit --help python -m habit_tracker.cli list --help python -m habit_tracker.cli reset --help
Author: Mariana Del Pozo Patrón
Python version: 3.12.3
Publish date: March 23, 2025
Object Oriented and Functional Programming with Python
International University of Applied Sciences