Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improvementfactor #1416

Merged
merged 2 commits into from
Oct 12, 2024
Merged

refactor: improvementfactor #1416

merged 2 commits into from
Oct 12, 2024

Conversation

weibullguy
Copy link
Collaborator

@weibullguy weibullguy commented Oct 12, 2024

Does this PR introduce a breaking change?

  • Yes
  • No

Summary of Changes
Feature Enhancement: Dynamic Handling of User Floats in calculate_improvement Function

This PR refactors the calculate_improvement function to dynamically handle any number of user_float_X values passed as keyword arguments (kwargs). Previously, the function was limited to handling exactly 5 user_float_X values. Now, it can accommodate an arbitrary number of user_float_X inputs, improving flexibility.

Key Changes:

  1. Dynamic Collection of user_float_X Values:
    The function now iterates over all kwargs that start with user_float_ and collects them dynamically. This allows for greater flexibility in the number of inputs.

  2. Multiplication of All User Floats:
    The function multiplies all user_float_X values together, no longer being restricted to a fixed set of 5 user floats.

  3. Default to 1.0:
    If no user_float_X values are passed, the function defaults to multiplying by 1.0, ensuring the weight calculation remains valid.

  4. Error Handling for Non-Numeric Values:
    The function raises a ValueError if any of the user_float_X values are not numeric (int or float), ensuring robust input validation.

  5. Additional Improvements:
    Removed the need for #type: ignore by validating and converting inputs more explicitly.
    Simplified the calculation logic by dynamically iterating over the floats in kwargs.

  6. Tests Added:
    Added test cases to ensure the function correctly handles various numbers of user_float_X inputs (e.g., 2, 5, or no floats).
    Added validation tests to check that non-numeric user_float_X values raise appropriate exceptions.

Pull Request Checklist

  • Code Style

    • Code is following code style guidelines.
  • Static Checks

    • Failing static checks are only applicable to code outside the scope of
      this PR.
  • Tests

    • At least one test for all newly created functions/methods?
  • Chores

    • Issue(s) have been raised for problem areas outside the scope of
      this PR. These problem areas have been decorated with an ISSUE: # comment.

Summary by Sourcery

Refactor the calculate_improvement function to dynamically handle any number of user_float_X values, enhancing flexibility and input validation. Add comprehensive tests to ensure correct functionality and robust error handling.

New Features:

  • Enable dynamic handling of an arbitrary number of user_float_X values in the calculate_improvement function, allowing for greater flexibility in input.

Enhancements:

  • Improve input validation by raising a ValueError for non-numeric user_float_X values and ensuring all user_float_X values are positive numbers.
  • Simplify the calculation logic by dynamically iterating over user_float_X values in kwargs, removing the need for fixed user_float variables.
  • Default to a user_float value of 1.0 if no user_float_X values are provided, ensuring valid weight calculations.

Tests:

  • Add test cases to verify the calculate_improvement function handles various numbers of user_float_X inputs correctly, including cases with no floats.
  • Include validation tests to ensure non-numeric user_float_X values raise appropriate exceptions and that negative or zero ranks and priorities are handled correctly.

Copy link
Contributor

sourcery-ai bot commented Oct 12, 2024

Reviewer's Guide by Sourcery

This pull request refactors the calculate_improvement function in the improvement factor module to handle dynamic user float inputs, enhances error handling, and adds comprehensive test cases. The changes improve the flexibility and robustness of the function while maintaining its core functionality.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Refactored calculate_improvement function to handle dynamic user float inputs
  • Replaced fixed user_float_1 to user_float_5 with dynamic collection of user floats
  • Implemented input validation for ranks, priority, and user floats
  • Used math.prod() for multiplying user floats instead of individual multiplications
  • Added default behavior when no user floats are provided
src/ramstk/analyses/improvementfactor.py
Enhanced error handling and input validation
  • Added checks for non-negative integers for ranks
  • Added checks for positive numbers for priority
  • Implemented validation for user float inputs to ensure they are numeric and positive
src/ramstk/analyses/improvementfactor.py
Updated and expanded test cases
  • Added tests for dynamic handling of user floats
  • Implemented tests for various edge cases and error conditions
  • Updated existing tests to use pytest.approx for float comparisons
  • Added tests for default behavior when no user floats are provided
tests/analyses/test_improvementfactor.py
Updated copyright information
  • Changed copyright year from 2019 to 'since 2007'
src/ramstk/analyses/improvementfactor.py
tests/analyses/test_improvementfactor.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the type: refactor Issue or PR dealing with refactoring of RAMSTK code. label Oct 12, 2024
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @weibullguy - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@weibullguy weibullguy merged commit eba8abc into master Oct 12, 2024
22 checks passed
@trafico-bot trafico-bot bot added the endgame: merged Pull Request has been merged successfully label Oct 12, 2024
@weibullguy weibullguy deleted the refactor/improvementfactor branch October 12, 2024 22:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
endgame: merged Pull Request has been merged successfully type: refactor Issue or PR dealing with refactoring of RAMSTK code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant