|
|
|
|
@ -63,10 +63,10 @@ async def test_update_equipment_for_simulation_basic():
|
|
|
|
|
patch("src.aeros_equipment.service.get_aeros_equipment_by_location_tag", return_value=mock_nodes_data), \
|
|
|
|
|
patch("src.aeros_equipment.service.get_asset_batch", return_value=mock_reliability_data), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_oh_interval_offset", return_value=None), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None) as mock_update_node:
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None):
|
|
|
|
|
|
|
|
|
|
# Run the function
|
|
|
|
|
results = await update_equipment_for_simulation(
|
|
|
|
|
res = await update_equipment_for_simulation(
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
aeros_db_session=aeros_db_session,
|
|
|
|
|
project_name=project_name,
|
|
|
|
|
@ -77,15 +77,14 @@ async def test_update_equipment_for_simulation_basic():
|
|
|
|
|
schematic_name=schematic_name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results = res['reliability']
|
|
|
|
|
equipment_nodes = res['equipment_nodes']
|
|
|
|
|
|
|
|
|
|
# Assertions
|
|
|
|
|
assert "EQ001" in results
|
|
|
|
|
assert results["EQ001"]["distribution"] == "Weibull2"
|
|
|
|
|
assert results["EQ001"]["oh_duration"] == overhaul_duration
|
|
|
|
|
|
|
|
|
|
# Check if update_node was called with correct arguments
|
|
|
|
|
called_args = mock_update_node.call_args[1]
|
|
|
|
|
equipment_nodes = called_args["equipment_nodes"]
|
|
|
|
|
|
|
|
|
|
# Find EQ001 in equipment_nodes
|
|
|
|
|
eq001_node = next(node for node in equipment_nodes if node["equipmentName"] == "EQ001")
|
|
|
|
|
assert eq001_node["relDisType"] == "Weibull2"
|
|
|
|
|
@ -144,18 +143,20 @@ async def test_update_equipment_for_simulation_custom_input():
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None):
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
results = await update_equipment_for_simulation(
|
|
|
|
|
res = await update_equipment_for_simulation(
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
aeros_db_session=aeros_db_session,
|
|
|
|
|
project_name=project_name,
|
|
|
|
|
simulation_duration=simulation_duration,
|
|
|
|
|
overhaul_duration=overhaul_duration,
|
|
|
|
|
overhaul_interval=overhaul_interval,
|
|
|
|
|
offset=offset,
|
|
|
|
|
overhaul_interval=8000,
|
|
|
|
|
offset=0,
|
|
|
|
|
schematic_name=schematic_name,
|
|
|
|
|
custom_input=custom_input
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results = res['reliability']
|
|
|
|
|
|
|
|
|
|
assert "EQ001" in results
|
|
|
|
|
assert results["EQ001"]["mttr"] == 10
|
|
|
|
|
assert results["EQ001"]["distribution"] == "Exponential2"
|
|
|
|
|
@ -200,10 +201,10 @@ async def test_update_equipment_for_simulation_missing_reliability():
|
|
|
|
|
patch("src.aeros_equipment.service.get_aeros_equipment_by_location_tag", return_value=mock_nodes_data), \
|
|
|
|
|
patch("src.aeros_equipment.service.get_asset_batch", return_value={}), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_oh_interval_offset", return_value=None), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None) as mock_update_node:
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None):
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
results = await update_equipment_for_simulation(
|
|
|
|
|
res = await update_equipment_for_simulation(
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
aeros_db_session=aeros_db_session,
|
|
|
|
|
project_name=project_name,
|
|
|
|
|
@ -214,14 +215,87 @@ async def test_update_equipment_for_simulation_missing_reliability():
|
|
|
|
|
schematic_name=schematic_name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
results = res['reliability']
|
|
|
|
|
equipment_nodes = res['equipment_nodes']
|
|
|
|
|
|
|
|
|
|
assert "EQ_MISSING" in results
|
|
|
|
|
# Default values when no reliability data
|
|
|
|
|
assert results["EQ_MISSING"]["mttr"] == 0
|
|
|
|
|
assert results["EQ_MISSING"]["distribution"] == "Fixed"
|
|
|
|
|
|
|
|
|
|
# Check defaults in update_node call
|
|
|
|
|
called_args = mock_update_node.call_args[1]
|
|
|
|
|
eq_node = called_args["equipment_nodes"][0]
|
|
|
|
|
# Check defaults in returned equipment_nodes
|
|
|
|
|
eq_node = equipment_nodes[0]
|
|
|
|
|
assert eq_node["cmDisUnitCode"] == "UHour"
|
|
|
|
|
assert eq_node["relDisUnitCode"] == "UHour"
|
|
|
|
|
assert eq_node["ohDisUnitCode"] == "UHour"
|
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
|
|
async def test_update_equipment_for_simulation_sigma_constraint():
|
|
|
|
|
# Mock parameters
|
|
|
|
|
db_session = AsyncMock()
|
|
|
|
|
aeros_db_session = AsyncMock()
|
|
|
|
|
project_name = "TestProject"
|
|
|
|
|
simulation_duration = 8760
|
|
|
|
|
overhaul_duration = 72
|
|
|
|
|
overhaul_interval = 8000
|
|
|
|
|
offset = 0
|
|
|
|
|
schematic_name = "TestSchematic"
|
|
|
|
|
|
|
|
|
|
# Mock get_aeros_schematic_by_name
|
|
|
|
|
mock_schematic = MagicMock()
|
|
|
|
|
mock_schematic.id = 1
|
|
|
|
|
|
|
|
|
|
# Mock db_session.execute
|
|
|
|
|
mock_eq = MagicMock()
|
|
|
|
|
mock_eq.location_tag = "EQ_SIGMA"
|
|
|
|
|
mock_eq_result = MagicMock()
|
|
|
|
|
mock_eq_result.scalars.return_value.all.return_value = [mock_eq]
|
|
|
|
|
|
|
|
|
|
mock_empty_result = MagicMock()
|
|
|
|
|
mock_empty_result.scalars.return_value.all.return_value = []
|
|
|
|
|
|
|
|
|
|
db_session.execute.side_effect = [
|
|
|
|
|
mock_eq_result, # equipments
|
|
|
|
|
mock_empty_result, # rbd_group
|
|
|
|
|
mock_empty_result # non_repairable
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# Mock nodes data
|
|
|
|
|
mock_nodes_data = [
|
|
|
|
|
{"equipmentName": "EQ_SIGMA", "relDisType": "Fixed", "relDisP1": 0}
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# Mock reliability data with high sigma (> 1000)
|
|
|
|
|
mock_reliability_data = {
|
|
|
|
|
"EQ_SIGMA": {
|
|
|
|
|
"relDisType": "Normal",
|
|
|
|
|
"relDisP1": 100, # mu
|
|
|
|
|
"relDisP2": 1500, # sigma
|
|
|
|
|
"cmDisType": "Fixed",
|
|
|
|
|
"cmDisP1": 0,
|
|
|
|
|
"cmDisP2": 0
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with patch("src.aeros_equipment.service.get_aeros_schematic_by_name", return_value=mock_schematic), \
|
|
|
|
|
patch("src.aeros_equipment.service.get_aeros_equipment_by_location_tag", return_value=mock_nodes_data), \
|
|
|
|
|
patch("src.aeros_equipment.service.get_asset_batch", return_value=mock_reliability_data), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_oh_interval_offset", return_value=None), \
|
|
|
|
|
patch("src.aeros_equipment.service.update_node", return_value=None):
|
|
|
|
|
|
|
|
|
|
# Run
|
|
|
|
|
res = await update_equipment_for_simulation(
|
|
|
|
|
db_session=db_session,
|
|
|
|
|
aeros_db_session=aeros_db_session,
|
|
|
|
|
project_name=project_name,
|
|
|
|
|
simulation_duration=simulation_duration,
|
|
|
|
|
overhaul_duration=overhaul_duration,
|
|
|
|
|
overhaul_interval=overhaul_interval,
|
|
|
|
|
offset=offset,
|
|
|
|
|
schematic_name=schematic_name
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Check if sigma was constrained correctly in returned equipment_nodes
|
|
|
|
|
equipment_nodes = res['equipment_nodes']
|
|
|
|
|
eq_node = equipment_nodes[0]
|
|
|
|
|
assert eq_node["relDisP2"] == 999
|
|
|
|
|
|