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: dormancy calculations #1413

Merged
merged 2 commits into from
Oct 11, 2024
Merged

Conversation

weibullguy
Copy link
Collaborator

@weibullguy weibullguy commented Oct 11, 2024

Does this PR introduce a breaking change?

  • Yes
  • No

Describe the purpose of this pull request.

Added detailed type hints throughout the code to ensure clarity on what each parameter and return value is expected to be.
The get_environment_type function now returns Optional[str], indicating that it may return None if the environment ID is invalid.

Instead of potentially allowing the get_environment_type function to return an invalid environment string, it now explicitly returns None if the env_id is out of bounds. The do_calculate_dormant_hazard_rate function handles this case by returning 0.0 if either environment is invalid.

Clarified hw_info indices in the docstrings to help understand what each index represents.

The code that handles the special case for semiconductors (category 1) was clarified, reducing unnecessary branches and making the logic easier to follow.

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 dormancy calculations to improve clarity and robustness by handling invalid environment IDs and simplifying logic for semiconductors. Enhance type hinting and expand test coverage to ensure correct behavior in edge cases.

Enhancements:

  • Refactor the get_environment_type function to return Optional[str] to handle invalid environment IDs by returning None.
  • Simplify the logic for handling semiconductors in the dormancy calculations, reducing unnecessary branches.
  • Add detailed type hints throughout the code to improve clarity on parameter and return value expectations.

Tests:

  • Add tests for get_environment_type to ensure it returns None for invalid environment IDs.
  • Add tests for do_calculate_dormant_hazard_rate to verify it returns 0.0 for invalid environments and zero hazard rates.
  • Add tests for get_dormant_hr_multiplier to ensure it handles invalid subcategories and environment combinations correctly.

Copy link
Contributor

sourcery-ai bot commented Oct 11, 2024

Reviewer's Guide by Sourcery

This pull request refactors the dormancy calculations in the RAMSTK project, focusing on improving type hints, error handling, and test coverage. The changes primarily affect the dormancy.py file in the src/ramstk/analyses/ directory and its corresponding test file test_dormancy.py in the tests/analyses/ directory.

Updated class diagram for dormancy calculations

classDiagram
    class DormancyCalculations {
        +get_environment_type(env_id: int, is_active: bool) Optional~str~
        +get_dormant_hr_multiplier(hw_info: List~Union~int, float~~, env_active: str, env_dormant: str) float
        +do_calculate_dormant_hazard_rate(hw_info: List~Union~int, float~~, env_info: List~int~) float
    }
    DormancyCalculations : -DORMANT_HR_MULTIPLIER
    DormancyCalculations : +get_environment_type
    DormancyCalculations : +get_dormant_hr_multiplier
    DormancyCalculations : +do_calculate_dormant_hazard_rate
    DormancyCalculations : +ENVIRONMENTS_ACTIVE
    DormancyCalculations : +ENVIRONMENTS_DORMANT
Loading

File-Level Changes

Change Details Files
Improved type hinting and error handling in dormancy calculations
  • Added Optional[str] return type to get_environment_type function
  • Implemented explicit None return for invalid environment IDs
  • Updated do_calculate_dormant_hazard_rate to handle None environment types
  • Modified get_environment_type to check for positive env_id
src/ramstk/analyses/dormancy.py
Enhanced test coverage for dormancy calculations
  • Added tests for invalid environment IDs in get_environment_type
  • Implemented tests for invalid subcategories in get_dormant_hr_multiplier
  • Added tests for invalid environments in do_calculate_dormant_hazard_rate
  • Included test for zero hazard rate in do_calculate_dormant_hazard_rate
  • Added parametrized test for different subcategories of category 1
tests/analyses/test_dormancy.py
Improved code clarity and consistency
  • Updated copyright year format
  • Replaced direct comparisons with pytest.approx for floating-point assertions
  • Clarified variable names (e.g., _env_active_id to _env_active)
src/ramstk/analyses/dormancy.py
tests/analyses/test_dormancy.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 11, 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 - here's some feedback:

Overall Comments:

  • Consider adding a comment in the get_environment_type function explaining why None is returned for invalid inputs, to make the intention clear for future maintainers.
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/dormancy.py Show resolved Hide resolved
@weibullguy weibullguy merged commit 090c0da into master Oct 11, 2024
22 checks passed
@trafico-bot trafico-bot bot added the endgame: merged Pull Request has been merged successfully label Oct 11, 2024
@weibullguy weibullguy deleted the refactor/dormancy_calculations branch October 11, 2024 05:41
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