Skip to content

Commit

Permalink
feat: add functions to set default MIL-HDBK-217F values (#1038)
Browse files Browse the repository at this point in the history
* refactor: specific argument list to calculation functions

* test: update tests for function argument changes

* style: update stub files

* refactor: accept sourcery suggestions

* feat: set default capacitor MIL-HDBK-217F values

* feat: set default connection MIL-HDBK-217F values

* feat: set default crystal MIL-HDBK-217F values

* feat: set default inductor MIL-HDBK-217F values

* feat: set default lamp MIL-HDBK-217F values

* feat: set default relay MIL-HDBK-217F values

* feat: set default resistor MIL-HDBK-217F values

* feat: set default semiconductor MIL-HDBK-217F values

* feat: set default switch MIL-HDBK-217F values

* feat: set default integrated circuit MIL-HDK-217F values

* feat: set default electronic filter MIL-HDBK-217F values

* feat: set default fuse MIL-HDBK-217F values

* feat: set default meter MIL-HDBK-217F values

* feat: call functions to set MIL-HDBK-217F values

* style: update stub files

* test: add tests for default value functions

* build: update dependency versions

* test: fix test that no longer covered after setting defaults

* style: clean up code smells
  • Loading branch information
weibullguy committed Mar 30, 2022
1 parent 158af44 commit 2e8689e
Show file tree
Hide file tree
Showing 48 changed files with 3,775 additions and 1,776 deletions.
297 changes: 166 additions & 131 deletions poetry.lock

Large diffs are not rendered by default.

53 changes: 44 additions & 9 deletions src/ramstk/analyses/milhdbk217f/milhdbk217f.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ def do_predict_active_hazard_rate(**attributes: Dict[str, Any]) -> float:
:return: attributes['hazard_rate_active']
:rtype: float
"""
attributes = _do_set_default_values(**attributes)

try:
if attributes["hazard_rate_method_id"] == 1:
attributes = _do_calculate_part_count(**attributes)
Expand All @@ -55,7 +57,7 @@ def do_predict_active_hazard_rate(**attributes: Dict[str, Any]) -> float:
pub.sendMessage("succeed_predict_reliability", attributes=attributes)
pub.sendMessage("request_set_all_milhdbk217f_attributes", attributes=attributes)
pub.sendMessage("request_set_all_reliability_attributes", attributes=attributes)
except ValueError:
except (TypeError, ValueError):
pub.sendMessage(
"fail_predict_reliability",
error_message=(
Expand Down Expand Up @@ -89,13 +91,44 @@ def do_predict_active_hazard_rate(**attributes: Dict[str, Any]) -> float:
return attributes["hazard_rate_active"]


def _do_set_default_values(**attributes: Dict[str, Any]) -> Dict[str, Any]:
"""Set default values for parameters <= 0.0.
:param attributes: the attribute dict for the component being
calculated.
:return: attributes; the attribute dict with updated values.
:rtype: dict
"""
_default_values = {
1: integratedcircuit.set_default_values,
2: semiconductor.set_default_values,
3: resistor.set_default_values,
4: capacitor.set_default_values,
5: inductor.set_default_values,
6: relay.set_default_values,
7: switch.set_default_values,
8: connection.set_default_values,
9: meter.set_default_values,
10: {
1: crystal.set_default_values,
2: efilter.set_default_values,
3: fuse.set_default_values,
4: lamp.set_default_values,
},
}

attributes = _default_values[attributes["category_id"]](**attributes)

return attributes


# noinspection PyTypeChecker
def _do_calculate_part_count(**attributes: Dict[str, Any]) -> Dict[str, Any]:
"""Calculate the MIL-HDBK-217F parts count active hazard rate.
:param attributes: the attributes dict for the component being
:param attributes: the attribute dict for the component being
calculated.
:return: attributes; the attributes dict with updated values.
:return: attributes; the attribute dict with updated values.
:rtype: dict
:raise: IndexError if there is no entry for the active environment ID.
:raise: KeyError if there is no entry for category ID or subcategory ID.
Expand All @@ -118,9 +151,7 @@ def _do_calculate_part_count(**attributes: Dict[str, Any]) -> Dict[str, Any]:
},
}

if attributes["category_id"] == 2:
attributes = _part_count[attributes["category_id"]](**attributes)
elif attributes["category_id"] == 10:
if attributes["category_id"] == 10:
attributes["lambda_b"] = _part_count[attributes["category_id"]][
attributes["subcategory_id"]
](**attributes)
Expand All @@ -134,7 +165,11 @@ def _do_calculate_part_count(**attributes: Dict[str, Any]) -> Dict[str, Any]:
attributes["quality_id"],
)
else:
attributes = semiconductor.get_part_count_quality_factor(attributes)
attributes["piQ"] = semiconductor.get_part_count_quality_factor(
attributes["subcategory_id"],
attributes["quality_id"],
attributes["type_id"],
)

attributes["hazard_rate_active"] = attributes["lambda_b"] * attributes["piQ"]

Expand All @@ -145,9 +180,9 @@ def _do_calculate_part_count(**attributes: Dict[str, Any]) -> Dict[str, Any]:
def _do_calculate_part_stress(**attributes: Dict[str, Any]) -> Dict[str, Any]:
"""Calculate the MIL-HDBK-217F parts stress active hazard rate.
:param attributes: the attributes dict for the component being
:param attributes: the attribute dict for the component being
calculated.
:return: attributes; the attributes dict with updated values.
:return: attributes; the attribute dict with updated values.
:rtype: dict
:raise: IndexError if there is no entry for the active environment ID.
:raise: KeyError if there is no entry for category ID or subcategory ID.
Expand Down
Loading

0 comments on commit 2e8689e

Please sign in to comment.