You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
138 lines
3.8 KiB
Python
138 lines
3.8 KiB
Python
from uuid import uuid4
|
|
|
|
from src.aeros_simulation.ramp_engine import (
|
|
_calc_result,
|
|
_duration_to_hours,
|
|
_filter_overrides_to_model,
|
|
build_ramp_distribution_overrides_from_rbd_reliability,
|
|
build_ramp_distribution_overrides,
|
|
selected_simulation_engine,
|
|
)
|
|
|
|
|
|
def test_selected_simulation_engine_defaults_to_aeros():
|
|
assert selected_simulation_engine({}) == "aeros"
|
|
|
|
|
|
def test_duration_to_hours_supports_aeros_units():
|
|
assert _duration_to_hours(2, "UYear") == 17520
|
|
assert _duration_to_hours(3, "UDay") == 72
|
|
assert _duration_to_hours(5, "UHour") == 5
|
|
|
|
|
|
def test_build_ramp_distribution_overrides_from_ahm_custom_input():
|
|
overrides = build_ramp_distribution_overrides(
|
|
{
|
|
"CustomInput": {
|
|
"EQ001": {
|
|
"mttr": 10,
|
|
"failure_rate": 0.5,
|
|
"distribution": "Weibull",
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
assert overrides["EQ001"]["repair_duration"] == 10
|
|
assert overrides["EQ001"]["model"] == {
|
|
"type": "NonRepairable",
|
|
"distribution": {"type": "Weibull", "shape": 1.0, "scale": 2000000.0},
|
|
}
|
|
|
|
|
|
def test_build_ramp_distribution_overrides_from_aeros_distribution_fields():
|
|
overrides = build_ramp_distribution_overrides(
|
|
{
|
|
"DistributionOverrides": {
|
|
"PUMP-A": {
|
|
"relDisType": "Weibull2",
|
|
"relDisP1": 1.7,
|
|
"relDisP2": 9000,
|
|
"cmDisType": "Normal",
|
|
"cmDisP1": 8,
|
|
"cmDisP2": 1.5,
|
|
}
|
|
}
|
|
}
|
|
)
|
|
|
|
assert overrides["PUMP-A"]["model"]["distribution"] == {
|
|
"type": "Weibull",
|
|
"shape": 1.7,
|
|
"scale": 9000.0,
|
|
}
|
|
assert overrides["PUMP-A"]["repair_duration"] == {
|
|
"type": "Normal",
|
|
"mean": 8.0,
|
|
"std_dev": 1.5,
|
|
}
|
|
|
|
|
|
def test_ramp_calc_result_uses_numeric_defaults_for_aeros_only_fields():
|
|
calc = _calc_result(
|
|
simulation_id=uuid4(),
|
|
node_id=uuid4(),
|
|
metrics={
|
|
"system_availability": 0.95,
|
|
"system_uptime": 95,
|
|
"system_downtime": 5,
|
|
"system_failures": 2,
|
|
},
|
|
)
|
|
|
|
assert calc.stg_input == 0
|
|
assert calc.stg_output == 0
|
|
assert calc.average_level == 0
|
|
assert calc.availability == 95.0
|
|
|
|
|
|
def test_build_ramp_distribution_overrides_from_rbd_reliability():
|
|
overrides = build_ramp_distribution_overrides_from_rbd_reliability(
|
|
{
|
|
"PUMP-A": {
|
|
"distribution": "NHPPTTFF",
|
|
"beta": 1.4,
|
|
"eta": 8000,
|
|
"mttr": 12,
|
|
},
|
|
"PUMP-B": {
|
|
"distribution": "Weibull2",
|
|
"beta": 2,
|
|
"eta": 9000,
|
|
"mttr": 8,
|
|
},
|
|
}
|
|
)
|
|
|
|
assert overrides["PUMP-A"]["model"] == {
|
|
"type": "RepairableNHPP",
|
|
"beta": 1.4,
|
|
"eta": 8000.0,
|
|
}
|
|
assert overrides["PUMP-A"]["repair_duration"] == 12.0
|
|
assert overrides["PUMP-B"]["model"]["distribution"] == {
|
|
"type": "Weibull",
|
|
"shape": 2.0,
|
|
"scale": 9000.0,
|
|
}
|
|
|
|
|
|
def test_filter_overrides_keeps_only_assets_present_in_model():
|
|
overrides = {
|
|
"3AH-AU501A": {"repair_duration": 4},
|
|
"3bad-m531": {"repair_duration": 6},
|
|
"00CHA-CV804": {"repair_duration": 8},
|
|
}
|
|
kept, dropped = _filter_overrides_to_model(overrides, {"3AH-AU501A", "3BAD-M531"})
|
|
|
|
assert set(kept) == {"3AH-AU501A", "3bad-m531"}
|
|
assert dropped == ["00CHA-CV804"]
|
|
|
|
|
|
def test_filter_overrides_passes_through_when_model_assets_unknown():
|
|
overrides = {"3AH-AU501A": {"repair_duration": 4}}
|
|
kept, dropped = _filter_overrides_to_model(overrides, set())
|
|
|
|
assert kept == overrides
|
|
assert dropped == []
|