From 40f58ee939333a23e81076257c7e489ff0c4bff5 Mon Sep 17 00:00:00 2001 From: ANIRUDDHA ADAK Date: Sat, 11 Oct 2025 10:42:33 +0530 Subject: [PATCH] Add Weekly Habit Progress Chart Generator (fixes #636) --- .../weekly_habit_progress_chart.py | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 weekly_habit_progress_chart/weekly_habit_progress_chart.py diff --git a/weekly_habit_progress_chart/weekly_habit_progress_chart.py b/weekly_habit_progress_chart/weekly_habit_progress_chart.py new file mode 100644 index 00000000..94825b0a --- /dev/null +++ b/weekly_habit_progress_chart/weekly_habit_progress_chart.py @@ -0,0 +1,55 @@ +# Weekly Habit Progress Chart Generator (Under 100 lines) +# Issue: https://github.com/sumanth-0/100LinesOfPythonCode/issues/636 +# Usage: Run and enter habit completions (Y/N or 1/0) for Mon-Sun. Saves ASCII chart. + +DAYS = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"] + +def get_inputs(): + print("Enter habit name (e.g., Reading):") + habit = input("Habit: ").strip() or "Habit" + print("Enter completion for each day as 1/0 or Y/N. Press Enter to skip (0).") + vals = [] + for d in DAYS: + v = input(f"{d}: ").strip().lower() + vals.append(1 if v in ("1","y","yes","true","t") else 0) + return habit, vals + +def pct(vals): + return round(100 * sum(vals) / max(1,len(vals))) + +def bar(n, total=7, fill="█", empty="·"): + filled = int(n) + return fill*filled + empty*(total-filled) + +def weekly_chart(habit, vals): + total = sum(vals) + print("\n=== Weekly Habit Progress ===") + print(f"Habit: {habit}") + print("Days : " + " ".join(f"{d:>3}" for d in DAYS)) + print("Done : " + " ".join(" ✔ " if v else " " for v in vals)) + print(f"Total: {total}/7 ({pct(vals)}%)") + print("Progress:") + # 7-slot horizontal bar (one per day) + print("[" + bar(total, 7) + "]") + # Sparkline-like row + print("Spark : " + "".join("▇" if v else "▁" for v in vals)) + +def save_chart(habit, vals, path="weekly_habit_progress_chart/chart.txt"): + import os + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, "w", encoding="utf-8") as f: + f.write("=== Weekly Habit Progress ===\n") + f.write(f"Habit: {habit}\n") + f.write("Days : " + " ".join(f"{d:>3}" for d in DAYS) + "\n") + f.write("Done : " + " ".join("✔" if v else "-" for v in vals) + "\n") + f.write(f"Total: {sum(vals)}/7 ({pct(vals)}%)\n") + f.write("Progress:\n") + f.write("[" + bar(sum(vals), 7) + "]\n") + f.write("Spark : " + "".join("▇" if v else "▁" for v in vals) + "\n") + return path + +if __name__ == "__main__": + habit, vals = get_inputs() + weekly_chart(habit, vals) + out = save_chart(habit, vals) + print(f"\nSaved chart to: {out}")