Closed weibullguy closed 1 month ago
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.
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
Change | Details | Files |
---|---|---|
Improved type hinting and error handling in dormancy calculations |
|
src/ramstk/analyses/dormancy.py |
Enhanced test coverage for dormancy calculations |
|
tests/analyses/test_dormancy.py |
Improved code clarity and consistency |
|
src/ramstk/analyses/dormancy.py tests/analyses/test_dormancy.py |
Does this PR introduce a breaking change?
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
Static Checks
Tests
Chores
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:
Tests: