ReliaQualAssociates / ramstk

Reliability, Availability, Maintainability, Safety (RAMS) analysis program.
https://www.reliaqual.com/rtk/
BSD 3-Clause "New" or "Revised" License
46 stars 15 forks source link

refactor: allocation calculations #1411

Closed weibullguy closed 1 month ago

weibullguy commented 1 month ago

Does this PR introduce a breaking change?

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

Summary by Sourcery

Refactor allocation calculations to enhance code clarity and error handling, and update tests to align with these changes.

Enhancements:

Tests:

sourcery-ai[bot] commented 1 month ago

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)
    }

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](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).