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: allocation calculations #1411

Merged
merged 2 commits into from
Oct 9, 2024

Conversation

weibullguy
Copy link
Collaborator

@weibullguy weibullguy commented Oct 9, 2024

Does this PR introduce a breaking change?

  • Yes
  • No

Describe the purpose of this pull request.

This PR refactors the Allocation calculations.

Describe how this was implemented.

Ran code through ChatGPT.

Describe any particular area(s) reviewers should focus on.

None

Provide any other pertinent information.

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 allocation calculations to enhance code clarity and error handling, and update tests to align with these changes.

Enhancements:

  • Refactor allocation calculation methods to improve code readability and maintainability by extracting common value calculations and consolidating error handling.
  • Introduce a helper function _send_pubsub_message to streamline the sending of failure messages via pubsub.
  • Refactor the do_allocate_reliability function to use a dictionary for method selection, simplifying the allocation method dispatch logic.

Tests:

  • Update integration tests to reflect changes in error message formats for allocation methods.
  • Add new integration tests recommended by ChatGPT to validate successful goal calculations and reliability allocations.

Copy link
Contributor

sourcery-ai bot commented Oct 9, 2024

Reviewer's Guide by Sourcery

This pull request refactors the allocation calculations in the RAMSTK project. The main changes include improved error handling, code organization, and the introduction of helper functions to reduce code duplication. The refactoring aims to make the code more maintainable and easier to understand.

Class diagram for refactored allocation calculations

classDiagram
    direction TB
    class Allocation {
        +Dict _calculate_agree_apportionment(float parent_goal, Dict attributes)
        +Dict _calculate_arinc_apportionment(float parent_goal, Dict attributes)
        +Dict _calculate_equal_apportionment(float parent_goal, Dict attributes)
        +Dict _calculate_foo_apportionment(float parent_goal, int cum_weight, Dict attributes)
        +Dict do_allocate_reliability(float parent_goal, int cumulative_weight, **attributes)
        +Dict _calculate_common_values(Dict attributes)
        +void _send_pubsub_message(string message_type, string message)
    }
    Allocation --> PubSub : uses
    class PubSub {
        +void sendMessage(string message_type, string error_message)
    }
Loading

File-Level Changes

Change Details Files
Refactored allocation calculation functions
  • Introduced _calculate_common_values() function to extract and calculate common values
  • Simplified error handling using a new _send_pubsub_message() function
  • Reduced code duplication in calculation functions
  • Updated error messages to be more concise and informative
src/ramstk/analyses/allocation.py
Improved code organization in do_allocate_reliability()
  • Replaced if-elif chain with a dictionary of allocation methods
  • Simplified default case handling
src/ramstk/analyses/allocation.py
Updated test cases to reflect new error messages
  • Modified assertion messages in test functions
  • Added new tests recommended by ChatGPT for better coverage
tests/analyses/allocation_calc_integration_test.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 9, 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: 1 issue found
  • 🟢 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.

src/ramstk/analyses/allocation.py Show resolved Hide resolved
src/ramstk/analyses/allocation.py Show resolved Hide resolved
src/ramstk/analyses/allocation.py Show resolved Hide resolved
src/ramstk/analyses/allocation.py Show resolved Hide resolved
src/ramstk/analyses/allocation.py Show resolved Hide resolved
@weibullguy weibullguy merged commit e743ffb into master Oct 9, 2024
22 checks passed
@trafico-bot trafico-bot bot added the endgame: merged Pull Request has been merged successfully label Oct 9, 2024
@weibullguy weibullguy deleted the refactor/allocation_calculations branch October 9, 2024 18:12
@trafico-bot trafico-bot bot removed the endgame: merged Pull Request has been merged successfully label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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