fix distribution

main
Cizz22 5 months ago
parent 0cec12e0c5
commit 540d3e8e46

@ -259,14 +259,19 @@ def get_asset_batch(location_tags: List[str], nr_location_tags: List[str],
for item in reliabiility_data:
location_tag = item["location_tag"]
is_nr = location_tag in nr_location_tags
results[location_tag]["cmDisP1"] = item.get("mttr", 0)
results[location_tag]["relDisType"] = item["distribution"] if is_nr else "NHPPTTFF"
results[location_tag]["relDisP1"] = item.get("parameters", 0).get("beta", 0) if not is_nr else item.get("mbtf", 0)
results[location_tag]["relDisP2"] = item.get("parameters", 0).get("eta", 0)
results[location_tag]["parameters"] = item.get("parameters", {})
try:
is_nr = item["distribution"] != "NHPP"
mtbf = item["mtbf"]
mttr = item["mttr"]
distribution, reldisp1, reldisp2 = get_distribution(item)
results[location_tag]["cmDisP1"] = mttr
results[location_tag]["relDisType"] = distribution
results[location_tag]["relDisP1"] = reldisp1
results[location_tag]["relDisP2"] = reldisp2
results[location_tag]["parameters"] = item.get("parameters", {})
except Exception as e:
raise Exception(f"Error processing item {location_tag}: {e}")
return results
@ -277,6 +282,35 @@ def get_asset_batch(location_tags: List[str], nr_location_tags: List[str],
)
def get_distribution(item):
name = item["distribution"]
# Map distribution names to the expected format
if name == "Weibull-2P":
beta = item["parameters"].get("beta", 0)
alpha = item["parameters"].get("alpha", 0)
return "Weibull2", beta, alpha
elif name == "Weibull-3P":
beta = item["parameters"].get("beta", 0)
alpha = item["parameters"].get("alpha", 0)
return "Weibull3", beta, alpha
elif name == "Exponential-2P":
lambda_ = item["parameters"].get("Lambda", 0)
gamma = item["parameters"].get("gamma", 0)
return "Exponential2", lambda_, gamma
elif name == "NHPP":
beta = item["parameters"].get("beta", 0)
eta = item["parameters"].get("eta", 0)
return "NHPPTTFF", beta, eta
elif name == "Lognormal":
mu = item["parameters"].get("mu", 0)
sigma = item["parameters"].get("sigma", 0)
return "Lognormal", mu, sigma
elif name == "Normal":
mu = item["parameters"].get("mu", 0)
sigma = item["parameters"].get("sigma", 0)
return "Normal", mu, 1000
else:
return name
async def update_equipment_for_simulation(*, db_session: DbSession, project_name: str, schematic_name: str, custom_input: Optional[dict] = None):
@ -347,7 +381,7 @@ async def update_equipment_for_simulation(*, db_session: DbSession, project_name
continue
eq["cmDisP1"] = reliabiility.get("cmDisP1", 0)
eq["relDisType"] = reliabiility.get("relDisType", "NHPPTTFF")
eq["relDisType"] = reliabiility.get("relDisType", "Fixed")
eq["relDisP1"] = reliabiility.get("relDisP1", 0)
eq["relDisP2"] = reliabiility.get("relDisP2", 0)

@ -122,6 +122,7 @@ class AerosSimulationCalcResult(Base, DefaultMixin):
eta = Column(Float, nullable=True)
beta = Column(Float, nullable=True)
mttr = Column(Integer, nullable=True)
parameters = Column(JSON, nullable=True)
aeros_simulation_id = Column(
UUID(as_uuid=True), ForeignKey("rbd_tr_aeros_simulation.id"), nullable=False

Loading…
Cancel
Save