Skip to content

tanmaytiwari37/Habit-Tracker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“Š Habit Tracker with Insights

A clean Python CLI tool to track daily habits, compute streaks, score consistency, and visualize progress over time.

Python Pandas NumPy Matplotlib

✨ About

Building good habits is hard. Knowing whether you're actually improving is harder. This project is a lightweight command-line habit tracker that does three things:

  1. Logs your daily habits in a CSV (no database setup needed)
  2. Analyzes patterns β€” streaks, completion rates, best/worst habits
  3. Visualizes progress through clean matplotlib charts

Built as a self-driven Python project to practice data handling, CSV I/O, and modular code design.

🎯 Features

  • βž• Add habits with a single command
  • βœ… Mark habits done for any given day
  • πŸ“‹ Show today's status, all habits, or delete unwanted ones
  • πŸ”₯ Streaks β€” current and longest streaks per habit
  • πŸ“ˆ Completion rates β€” % of days completed since habit was started
  • πŸ† Best & worst habit β€” weighted score based on consistency and streaks
  • πŸ“Š Visualizations β€” bar charts, progress lines, daily activity trends
  • πŸ’Ύ Local storage β€” all data lives in data/habits.csv

πŸ› οΈ Tech Stack

  • Python 3.10+ β€” uses match/case syntax
  • Pandas β€” data manipulation and analysis
  • NumPy β€” numerical operations (cumulative sums for progress charts)
  • Matplotlib β€” all visualizations
  • CSV β€” lightweight, human-readable storage

πŸ“ Project Structure

Habit Tracker/
β”œβ”€β”€ data/
β”‚   └── habits.csv          # All habit logs live here
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main.py             # Entry point β€” menu loop
β”‚   β”œβ”€β”€ tracker.py          # CRUD operations (add, mark, delete)
β”‚   β”œβ”€β”€ insights.py         # Stats engine (streaks, rates, scores)
β”‚   └── visualizer.py       # Matplotlib charts
β”œβ”€β”€ requirements.txt
└── README.md

πŸ—οΈ Architecture

The project follows a clean separation of concerns pattern:

β”œβ”€β”€> tracker.py     (write to CSV)
β”œβ”€β”€> insights.py    (analyze CSV)
└──> visualizer.py  (plot from CSV)
β”‚
β–Ό
data/habits.csv  (single source of truth)

Each module has one job:

  • tracker.py β†’ only writes
  • insights.py β†’ only reads + computes
  • visualizer.py β†’ only reads + plots

πŸš€ Getting Started

Prerequisites

python >= 3.10

Installation

# Clone the repo
git clone https://github.com/tanmaytiwari37/Habit-Tracker.git
cd Habit-Tracker

# Create virtual environment
python -m venv .venv

# Activate (Windows)
.venv\Scripts\activate

# Activate (Mac/Linux)
source .venv/bin/activate

# Install dependencies
pip install -r requirements.txt

Run

python src/main.py

⚠️ Run from the project root, not from inside src/ β€” the data path is relative.

πŸ“‹ Usage

=== Habit Tracker ===

Add Habit
Mark Habit as Done
Show Today's Status
View Stats
Visualize Data
Show All Habits
Delete Habit
Exit

Example Stats Output

πŸ”₯ Your Streaks:

         Current  Longest
Study          5       12
Walk           3        8
Journal        0        4

βœ… Your Completion Rates:

         Start Date  Days Missed  Completion Rate
Study    2025-01-05            2             93.5
Walk     2025-01-03            7             82.1
Journal  2025-01-08           15             45.2

🧠 How It Works

Streak Calculation

Walks through each habit's history chronologically, carrying forward the current streak. If yesterday was marked done, increment. If broken, reset. Track the maximum seen.

if status == 1 and (today - prev_date).days == 1:
    current_streak += 1
else:
    current_streak = 1 if status == 1 else 0
best_streak = max(best_streak, current_streak)

Best Habit Score

A weighted heuristic combining 3 signals:

Score = (Completion Rate / 1.4)
        + (Current Streak % / 2)
        + (Longest Streak % / 4)

The habit with the highest score is your "Best Habit" β€” the one with both consistency and recent momentum.

Progress Visualization

Uses np.cumsum to create a line that rises on consecutive days and dips on gaps β€” a smooth visual signal of consistency vs. relapse.

πŸ“Š CSV Schema

date,habits,status
2025-01-03,Walk,1
2025-01-04,Walk,1
2025-01-05,Study,0
Column Type Meaning
date ISO date When the entry was logged
habits string Habit name (title-cased)
status 0 or 1 0 = missed, 1 = completed

🧠 What I Learned

  • Modular design β€” splitting CRUD, analysis, and visualization into separate files
  • Pandas β€” groupby, iterrows, filtering, joins, and time-delta arithmetic
  • The accumulator pattern β€” carrying state across loop iterations (used in streak logic)
  • Matplotlib β€” bar charts, line plots, and date-axis formatting
  • DRY principle β€” visualizer reuses show_completion_rates() from insights instead of duplicating logic

πŸ‘€ About Me

Tanmay Tiwari β€” 1st-year B.Tech Aerospace Engineering, VIT Bhopal

πŸ“„ License

This project is licensed under the MIT License β€” feel free to use, modify, and learn from it.


Built as a self-study project to deepen Python and Pandas skills.

About

A modular Python habit tracker with streak analysis, completion rates, and matplotlib visualizations.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages