Skip to content

Add muscle recovery tracking and recovery page component#27

Merged
brylie merged 56 commits intomainfrom
add-muscle-recovery
Apr 4, 2025
Merged

Add muscle recovery tracking and recovery page component#27
brylie merged 56 commits intomainfrom
add-muscle-recovery

Conversation

@brylie
Copy link
Copy Markdown
Owner

@brylie brylie commented Apr 2, 2025

Closes #3

User description

Introduce a recovery page component and enhance muscle details with recovery hours and muscle group classification. Implement a recovery module for tracking muscle recovery status, including calculations and improved data display. Add navigation for easy access to the recovery page and update documentation to emphasize the use of daisyUI components.


PR Type

Enhancement, Tests, Documentation


Description

  • Introduced a muscle recovery tracking module with detailed calculations.

    • Added calculateRecoveryPercentage function for recovery percentage computation.
    • Implemented getMuscleRecoveryStatus and getSingleMuscleRecoveryStatus for recovery data retrieval.
  • Enhanced muscle details with recovery hours and muscle group classification.

    • Updated muscles.ts to include recovery_hours and muscle_group properties.
    • Adjusted muscles.test.ts to validate new properties.
  • Developed a new Recovery Page component for tracking muscle recovery.

    • Displayed grouped muscle recovery data with statuses and progress bars.
    • Included collapsible details for recovery status explanation.
  • Added tests for the recovery module and related functionalities.

    • Verified recovery calculations and status determination logic.
    • Mocked database and exercise data for consistent test scenarios.
  • Updated navigation to include a link to the Recovery Page.

  • Improved documentation to emphasize the use of daisyUI components.


Changes walkthrough 📝

Relevant files
Tests
3 files
exercises.test.ts
Added tests for `getExerciseById` function.                           
+21/-0   
muscles.test.ts
Updated tests to validate recovery hours and muscle group.
+21/-3   
recovery.test.ts
Added comprehensive tests for recovery module.                     
+448/-0 
Enhancement
5 files
exercises.ts
Implemented `getExerciseById` function for exercise retrieval.
+19/-10 
muscles.ts
Enhanced muscle details with recovery hours and groups.   
+44/-0   
recovery.ts
Implemented muscle recovery tracking logic.                           
+178/-0 
NavigationMenu.svelte
Added Recovery link to navigation menu.                                   
+9/-0     
+page.svelte
Created Recovery Page component with grouped muscle data.
+284/-0 
Documentation
1 files
copilot-instructions.md
Updated instructions to emphasize daisyUI usage.                 
+2/-0     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • @qodo-code-review
    Copy link
    Copy Markdown

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Recovery Calculation Logic

    The recovery calculation logic might not handle edge cases correctly. The function counts exercises within the recovery window by filtering dates that are both after the recovery window start and before the last trained date, which could miss exercises if multiple were done on the same day.

    exerciseCount = allExerciseDates.filter(
      (date) => date >= recoveryWindowStartTime && date <= lastTrainedDate,
    ).length;
    Error Handling

    The error handling in the onMount function catches errors but doesn't provide a way for users to retry loading the data if the initial fetch fails.

    } catch (err) {
      error =
        err instanceof Error
          ? err.message
          : "Failed to load muscle recovery data";
      isLoading = false;

    @qodo-code-review
    Copy link
    Copy Markdown

    qodo-code-review Bot commented Apr 2, 2025

    Qodo Merge was enabled for this repository. To continue using it, please link your Git account with your Qodo account here.

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix recovery window calculation
    Suggestion Impact:The commit implemented the exact logic suggested - changing from a backward-looking recovery window calculation to one that checks if each exercise's recovery period extends to the current time

    code diff:

    -      const recoveryWindowStartTime = new Date(lastTrainedDate.getTime());
    -      recoveryWindowStartTime.setHours(
    -        recoveryWindowStartTime.getHours() - muscle.recovery_hours,
    -      );
    +      const now = new Date();
     
    -      // Count exercises for this muscle that were done within recovery period
    -      exerciseCount = allExerciseDates.filter(
    -        (date) => date >= recoveryWindowStartTime && date <= lastTrainedDate,
    -      ).length;
    +      // Count exercises for this muscle that are still within their recovery period
    +      exerciseCount = allExerciseDates.filter((date) => {
    +        const recoveryEndTime = new Date(date.getTime());
    +        recoveryEndTime.setHours(
    +          recoveryEndTime.getHours() + muscle.recovery_hours,
    +        );
    +        return recoveryEndTime >= now;
    +      }).length;

    The recovery window calculation is incorrect. Currently, it's looking backward
    from the last training date by subtracting recovery hours, which means it's only
    counting exercises done before the last training. Instead, it should count all
    exercises done within the recovery period from each exercise date.

    app/src/lib/recovery.ts [135-148]

     // Count exercises performed within the muscle's recovery window
     let exerciseCount = 0;
     if (lastTrainedDate) {
       const allExerciseDates = exerciseDatesForMuscle.get(muscle.id) || [];
    -  const recoveryWindowStartTime = new Date(lastTrainedDate.getTime());
    -  recoveryWindowStartTime.setHours(
    -    recoveryWindowStartTime.getHours() - muscle.recovery_hours,
    -  );
    -
    +  const now = new Date();
    +  
       // Count exercises for this muscle that were done within recovery period
    -  exerciseCount = allExerciseDates.filter(
    -    (date) => date >= recoveryWindowStartTime && date <= lastTrainedDate,
    -  ).length;
    +  exerciseCount = allExerciseDates.filter(date => {
    +    const recoveryEndTime = new Date(date.getTime());
    +    recoveryEndTime.setHours(recoveryEndTime.getHours() + muscle.recovery_hours);
    +    return recoveryEndTime >= now;
    +  }).length;
     }

    [Suggestion has been applied]

    Suggestion importance[1-10]: 9

    __

    Why: The current implementation incorrectly calculates the recovery window by looking backward from the last training date, which only counts exercises done before the last training. The fix correctly determines if a muscle is still in recovery by checking if the recovery period extends to the current time, which is critical for accurate recovery status determination.

    High
    • Update

    @brylie brylie requested a review from Copilot April 2, 2025 14:13
    Copy link
    Copy Markdown

    Copilot AI left a comment

    Choose a reason for hiding this comment

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

    Pull Request Overview

    This PR adds a muscle recovery tracking module and a new Recovery Page component, and updates muscle details, tests, and documentation to support enhanced recovery calculation and display.

    • Introduces recovery module functions with recovery percentage calculations and status determination.
    • Enhances muscle definitions with recovery_hours and muscle_group properties.
    • Adds comprehensive tests for recovery logic, updates exercise retrieval, and incorporates daisyUI usage in documentation.

    Reviewed Changes

    Copilot reviewed 7 out of 9 changed files in this pull request and generated no comments.

    Show a summary per file
    File Description
    app/src/lib/recovery.ts Implements recovery calculations and status determination logic.
    app/src/lib/muscles.ts Enhances muscle details with recovery_hours and muscle_group properties.
    app/src/lib/muscles.test.ts Updates tests to validate new muscle properties.
    app/src/lib/exercises.ts Implements getExerciseById and adjusts imports using absolute paths.
    app/src/lib/exercises.test.ts Adds tests for getExerciseById.
    .github/copilot-instructions.md Updates instructions to include daisyUI component usage.
    Files not reviewed (2)
    • app/src/lib/components/NavigationMenu.svelte: Language not supported
    • app/src/routes/recovery/+page.svelte: Language not supported

    @brylie brylie requested a review from Copilot April 2, 2025 20:05
    Copy link
    Copy Markdown

    Copilot AI left a comment

    Choose a reason for hiding this comment

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

    Pull Request Overview

    This PR introduces a muscle recovery tracking module with a new Recovery Page component, updates to muscle details with recovery hours and muscle groups, and adds supporting tests and documentation.

    • Added recovery.ts which implements recovery percentage calculations and status determination
    • Updated muscles.ts to include recovery_hours and muscle_group properties and adjusted corresponding tests
    • Updated exercise retrieval, CI workflow, and documentation to reflect these new features

    Reviewed Changes

    Copilot reviewed 8 out of 10 changed files in this pull request and generated no comments.

    Show a summary per file
    File Description
    app/src/lib/recovery.ts Adds recovery calculations and functions to determine muscle status
    app/src/lib/muscles.ts Enhances muscle details with new recovery and classification fields
    app/src/lib/muscles.test.ts Updates tests to include validation of recovery_hours and muscle_group
    app/src/lib/exercises.ts Implements getExerciseById for exercise retrieval
    app/src/lib/exercises.test.ts Adds tests for getExerciseById functionality
    .github/workflows/ci.yml Modifies dependency installation and test execution commands
    .github/copilot-instructions.md Updates documentation to emphasize Tailwind CSS and daisyUI usage
    Files not reviewed (2)
    • app/src/lib/components/NavigationMenu.svelte: Language not supported
    • app/src/routes/recovery/+page.svelte: Language not supported
    Comments suppressed due to low confidence (1)

    .github/workflows/ci.yml:34

    • Using '--force' with pnpm install may bypass caching benefits and unnecessarily reinstall dependencies. Consider evaluating if this flag is essential or if restoring caching steps would improve CI efficiency.
    pnpm install --force
    

    brylie added 22 commits April 2, 2025 23:34
    @brylie brylie requested a review from Copilot April 4, 2025 09:20
    Copy link
    Copy Markdown

    Copilot AI left a comment

    Choose a reason for hiding this comment

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

    Copilot reviewed 12 out of 17 changed files in this pull request and generated 1 comment.

    Files not reviewed (5)
    • app/package.json: Language not supported
    • app/src/lib/components/NavigationMenu.svelte: Language not supported
    • app/src/routes/+layout.svelte: Language not supported
    • app/src/routes/recovery/+page.svelte: Language not supported
    • app/src/routes/workout/+page.svelte: Language not supported
    Comments suppressed due to low confidence (1)

    .github/workflows/ci.yml:36

    • [nitpick] Review the downgrade from actions/cache@v4 to actions/cache@v3 to confirm that it is intentional and no important caching improvements from v4 are missed.
    - uses: actions/cache@v3
    

    Comment thread app/src/lib/recovery.ts
    * @param recoveryHours - The number of hours needed for full recovery
    * @returns A number from 0 to 100 representing recovery percentage
    */
    export function calculateRecoveryPercentage(
    Copy link

    Copilot AI Apr 4, 2025

    Choose a reason for hiding this comment

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

    Consider adding a check to ensure the 'recoveryHours' parameter is greater than zero before using it in the division to avoid potential division by zero errors.

    Copilot uses AI. Check for mistakes.
    @brylie brylie merged commit e873ed1 into main Apr 4, 2025
    1 check passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    Implement Muscle Recovery Tracking and Smart Workout Generation

    2 participants