Skip to content

Create workout_tracker.py#1

Open
mitsuomkinoshita-tech wants to merge 1 commit intomainfrom
Python-version
Open

Create workout_tracker.py#1
mitsuomkinoshita-tech wants to merge 1 commit intomainfrom
Python-version

Conversation

@mitsuomkinoshita-tech
Copy link
Copy Markdown
Owner

@mitsuomkinoshita-tech mitsuomkinoshita-tech commented Oct 1, 2025

Summary by CodeRabbit

  • New Features
    • Introduced a desktop workout tracker app with a tabbed interface (Track Workout, Analytics).
    • Rest timer with start, pause, and reset, displaying a live countdown.
    • Log sets with exercise, weight, and reps; add entries quickly.
    • View recent sets with the ability to delete selected entries.
    • Analytics per exercise: total volume, estimated 1RM, and total sets; shows a placeholder when no data.
    • Input validation with clear error prompts.
    • Analytics update automatically after adding or deleting sets.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 1, 2025

Walkthrough

Introduces a new Tkinter GUI application in workout_tracker.py with a tabbed interface for tracking workouts and viewing analytics. Implements a rest timer, set logging with validation, recent sets management (add/delete), and dynamic analytics (volume, estimated 1RM, total sets). Data stored in-memory as dictionaries; UI updates on changes.

Changes

Cohort / File(s) Summary
GUI Workout Tracker App
workout_tracker.py
Adds WorkoutTrackerApp Tkinter application with tabbed UI (Track Workout, Analytics), rest timer (start/pause/reset), set logging (exercise, weight, reps), recent sets list with deletion, analytics rendering per exercise (volume, est. 1RM, total sets), input validation, time formatting, and main entry point.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as WorkoutTrackerApp UI
  participant Timer as RestTimer
  participant Store as In-Memory Store
  participant Analytics as Analytics View

  rect rgb(240,248,255)
  note over User,UI: Add Set Flow
  User->>UI: Enter exercise, weight, reps
  User->>UI: Click "Add Set"
  UI->>UI: Validate inputs
  alt valid
    UI->>Store: Append workout dict (exercise, weight, reps, volume, date)
    UI->>UI: Update Recent Sets list
    UI->>Analytics: Rebuild analytics panels
  else invalid
    UI-->>User: Show message box (error)
  end
  end

  rect rgb(245,255,250)
  note over User,Timer: Rest Timer Controls
  User->>Timer: Start
  Timer-->>UI: Periodic tick updates (countdown)
  User->>Timer: Pause / Reset
  Timer-->>UI: Update display (paused/reset)
  end

  rect rgb(255,250,240)
  note over User,UI: Delete Set Flow
  User->>UI: Select recent set and click "Delete"
  UI->>Store: Remove selected entry
  UI->>UI: Refresh Recent Sets list
  UI->>Analytics: Recompute and rebuild analytics view
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I hop through tabs with timer bright,
Counting reps in morning light.
Sets I log, then swiftly see,
Volumes, one-rep max for me.
Click to add, delete with cheer—
Analytics bloom like clover near.
Thump-thump! Ship it—carrot-clear. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Create workout_tracker.py” succinctly describes the main change of adding the new workout tracker file and is directly related to the contents of the pull request without including extraneous details.
✨ Finishing touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch Python-version

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 990b15a and 193812a.

📒 Files selected for processing (1)
  • workout_tracker.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.13.1)
workout_tracker.py

106-106: String contains ambiguous (HEAVY PLUS SIGN). Did you mean + (PLUS SIGN)?

(RUF001)


143-143: Unused lambda argument: e

(ARG005)


223-223: String contains ambiguous × (MULTIPLICATION SIGN). Did you mean x (LATIN SMALL LETTER X)?

(RUF001)

Comment thread workout_tracker.py
Comment on lines +163 to +195
def start_timer(self):
if not self.timer_running:
self.rest_time = self.rest_time_var.get()
self.timer_seconds = self.rest_time
self.timer_running = True
self.start_btn.config(state=tk.DISABLED)
self.pause_btn.config(state=tk.NORMAL)
self.run_timer()

def run_timer(self):
if self.timer_running and self.timer_seconds > 0:
self.timer_label.config(text=self.format_time(self.timer_seconds))
self.timer_seconds -= 1
self.root.after(1000, self.run_timer)
elif self.timer_seconds == 0:
self.timer_running = False
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)
self.timer_label.config(text="0:00")

def pause_timer(self):
self.timer_running = False
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)

def reset_timer(self):
self.timer_running = False
self.rest_time = self.rest_time_var.get()
self.timer_seconds = self.rest_time
self.timer_label.config(text=self.format_time(self.rest_time))
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Pause resumes reset the countdown
Pressing Start after Pause jumps straight back to the full rest duration because start_timer always reloads self.rest_time_var and overwrites self.timer_seconds. That breaks the pause/resume flow and forces users to restart every rest period from scratch. Only reset the counter when the countdown has finished (or before the first run).

Apply this diff to preserve the remaining time on resume:

     def start_timer(self):
         if not self.timer_running:
-            self.rest_time = self.rest_time_var.get()
-            self.timer_seconds = self.rest_time
+            if self.timer_seconds <= 0:
+                self.rest_time = self.rest_time_var.get()
+                self.timer_seconds = self.rest_time
             self.timer_running = True
             self.start_btn.config(state=tk.DISABLED)
             self.pause_btn.config(state=tk.NORMAL)
             self.run_timer()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def start_timer(self):
if not self.timer_running:
self.rest_time = self.rest_time_var.get()
self.timer_seconds = self.rest_time
self.timer_running = True
self.start_btn.config(state=tk.DISABLED)
self.pause_btn.config(state=tk.NORMAL)
self.run_timer()
def run_timer(self):
if self.timer_running and self.timer_seconds > 0:
self.timer_label.config(text=self.format_time(self.timer_seconds))
self.timer_seconds -= 1
self.root.after(1000, self.run_timer)
elif self.timer_seconds == 0:
self.timer_running = False
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)
self.timer_label.config(text="0:00")
def pause_timer(self):
self.timer_running = False
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)
def reset_timer(self):
self.timer_running = False
self.rest_time = self.rest_time_var.get()
self.timer_seconds = self.rest_time
self.timer_label.config(text=self.format_time(self.rest_time))
self.start_btn.config(state=tk.NORMAL)
self.pause_btn.config(state=tk.DISABLED)
def start_timer(self):
if not self.timer_running:
# Only reload the full rest duration if the previous countdown has finished
if self.timer_seconds <= 0:
self.rest_time = self.rest_time_var.get()
self.timer_seconds = self.rest_time
self.timer_running = True
self.start_btn.config(state=tk.DISABLED)
self.pause_btn.config(state=tk.NORMAL)
self.run_timer()
🤖 Prompt for AI Agents
In workout_tracker.py around lines 163 to 195, start_timer currently always
reloads self.rest_time_var and overwrites self.timer_seconds which causes a
paused timer to restart at full duration; change start_timer so it only
initializes self.rest_time and self.timer_seconds when beginning a new countdown
(e.g., if self.timer_seconds is None or self.timer_seconds == 0), otherwise
leave self.timer_seconds unchanged to preserve remaining time on resume; ensure
reset_timer continues to reload rest_time_var and set timer_seconds for fresh
starts or finished countdowns.

coderabbitai Bot added a commit that referenced this pull request Oct 1, 2025
Docstrings generation was requested by @mitsuomkinoshita-tech.

* #1 (comment)

The following files were modified:

* `workout_tracker.py`
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 1, 2025

Note

Generated docstrings for this pull request at #2

coderabbitai Bot added a commit that referenced this pull request Oct 2, 2025
Docstrings generation was requested by @mitsuomkinoshita-tech.

* #1 (comment)

The following files were modified:

* `workout_tracker.py`
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 2, 2025

Note

Generated docstrings for this pull request at #3

@mitsuomkinoshita-tech
Copy link
Copy Markdown
Owner Author

@coderabbitai can you confirm that the pause resumes resets the countdown counter?

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 2, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Read the workout_tracker.py file to examine timer functionality
cat workout_tracker.py

Length of output: 13095


@mitsuomkinoshita-tech: I've analyzed the timer code and found an issue with the pause/resume functionality. Here's what's happening:

Current Behavior (Bug)

Pause does NOT properly resume - it actually resets the countdown. Here's why:

  1. When you click "Pause", it stops the timer but keeps the current timer_seconds value
  2. However, when you click "Start" again, the start_timer() method always resets timer_seconds back to the original rest time:
def start_timer(self):
    if not self.timer_running:
        self.rest_time = self.rest_time_var.get()
        self.timer_seconds = self.rest_time  # ← This resets to original time!
        self.timer_running = True
        # ...

Reset works correctly - it resets the timer to the configured rest time.

Fix Required

To make pause/resume work properly, you need to track whether the timer was paused. Here's the corrected code:

def __init__(self, root):
    # ... existing code ...
    self.timer_seconds = 0
    self.timer_running = False
    self.timer_paused = False  # Add this flag
    self.rest_time = 90
    # ... rest of init ...

def start_timer(self):
    if not self.timer_running:
        # Only reset if not resuming from pause
        if not self.timer_paused:
            self.rest_time = self.rest_time_var.get()
            self.timer_seconds = self.rest_time
        self.timer_paused = False
        self.timer_running = True
        self.start_btn.config(state=tk.DISABLED)
        self.pause_btn.config(state=tk.NORMAL)
        self.run_timer()
        
def pause_timer(self):
    self.timer_running = False
    self.timer_paused = True  # Mark as paused
    self.start_btn.config(state=tk.NORMAL)
    self.pause_btn.config(state=tk.DISABLED)
    
def reset_timer(self):
    self.timer_running = False
    self.timer_paused = False  # Clear pause flag
    self.rest_time = self.rest_time_var.get()
    self.timer_seconds = self.rest_time
    self.timer_label.config(text=self.format_time(self.rest_time))
    self.start_btn.config(state=tk.NORMAL)
    self.pause_btn.config(state=tk.DISABLED)

Summary: Currently, pause → start resets the timer instead of resuming. Reset works correctly. The fix adds a timer_paused flag to distinguish between starting fresh and resuming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant