Cizz22 3 months ago
parent 366e4d9753
commit bd437651a2

@ -0,0 +1,163 @@
import json
from collections import defaultdict
from sqlalchemy import create_engine, text
# 🔧 Adjust this to your environment
DB_URL = "postgresql+psycopg2://postgres:postgres@192.168.1.86:5432/digital_aeros_fixed"
def export_rbd_json(project_id, output_file="rbd.json"):
engine = create_engine(DB_URL)
with engine.connect() as conn:
# --- Project info ---
project = conn.execute(
text('SELECT "ProjectId","ProjectName" FROM public."Projects" WHERE "ProjectId" = :pid'),
{"pid": project_id}
).mappings().first()
if not project:
raise ValueError(f"❌ Project {project_id} not found")
print(f"🔍 Loaded project: {project['ProjectName']} (ID={project_id})")
# --- Schematics ---
schematics = conn.execute(
text('SELECT "SchematicId","SchematicName" FROM public."Schematics" WHERE "ProjectId" = :pid'),
{"pid": project_id}
).mappings().all()
all_schematics_json = {}
for s in schematics:
sid = s["SchematicId"]
sname = s["SchematicName"]
print(f"\n=== Processing schematic {sid} ({sname}) ===")
# --- Nodes ---
nodes_data = conn.execute(
text('SELECT "NodeId","NodeUIId","NodeName","NodeTypeCode" '
'FROM public."RegularNodes" WHERE "SchematicId" = :sid'),
{"sid": sid}
).mappings().all()
# dict keyed by NodeId
nodes = {str(n["NodeId"]): dict(n) for n in nodes_data}
# map UIId -> NodeId
uiid_to_id = {str(n["NodeUIId"]): str(n["NodeId"]) for n in nodes_data}
print(f"🟦 Nodes: {len(nodes)}")
# --- Connectors (edges) ---
edges = conn.execute(
text('SELECT "SourceUIId","SinkUIId" FROM public."Connectors" WHERE "SchematicId" = :sid'),
{"sid": sid}
).mappings().all()
children_map = defaultdict(list)
for e in edges:
src_ui = str(e["SourceUIId"])
sink_ui = str(e["SinkUIId"])
if src_ui in uiid_to_id and sink_ui in uiid_to_id:
src_id = uiid_to_id[src_ui]
sink_id = uiid_to_id[sink_ui]
children_map[src_id].append(sink_id)
print(f"🔗 Connectors: {len(edges)}")
# --- Redundancies ---
redundancies = conn.execute(
text('SELECT * FROM public."Redundancies" WHERE "SchematicId" = :sid'),
{"sid": sid}
).mappings().all()
states = conn.execute(
text('SELECT * FROM public."RedundancyStates" WHERE "RedundancyId" IN '
'(SELECT "RedundancyId" FROM public."Redundancies" WHERE "SchematicId" = :sid)'),
{"sid": sid}
).mappings().all()
state_cells = conn.execute(
text('SELECT * FROM public."RedundancyStateCells" WHERE "RedundancyStateId" IN '
'(SELECT "StateId" FROM public."RedundancyStates" WHERE "RedundancyId" IN '
'(SELECT "RedundancyId" FROM public."Redundancies" WHERE "SchematicId" = :sid))'),
{"sid": sid}
).mappings().all()
# Build redundancy structure
redundancy_map = {}
for r in redundancies:
rid = str(r["RedundancyId"])
redundancy_map[rid] = {
"name": r["RedundancyName"],
"type": "standby" if r["IsKNStandby"] else "kofn",
"min_required": r["MinRequiredNodes"],
"switch_delay": r["SwitchDelay"],
"states": {}
}
for st in states:
sid2 = str(st["StateId"])
rid = str(st["RedundancyId"])
redundancy_map[rid]["states"][sid2] = {
"priority": st["StatePriority"],
"duration": st["StateDuration"],
"cells": []
}
for c in state_cells:
sid2 = str(c["RedundancyStateId"])
for r_id, r in redundancy_map.items():
if sid2 in r["states"]:
node_id = str(c["InvolvedNodeId"])
if node_id in nodes: # only link if valid
r["states"][sid2]["cells"].append({
"node_id": node_id,
"status": c["NodeStatusCode"]
})
break
# --- Build JSON nodes ---
json_nodes = {}
for node_id, n in nodes.items():
node_type = str(n["NodeTypeCode"]).lower()
node_json = {
"type": node_type,
"name": n["NodeName"],
"children": children_map.get(node_id, []), # now NodeId-based
"availability": 1.0 # ✅ default availability
}
json_nodes[node_id] = node_json
# --- Root detection ---
all_children = {c for lst in children_map.values() for c in lst}
root_candidates = [nid for nid in nodes.keys() if nid not in all_children]
root = root_candidates[0] if root_candidates else None
print(f"🌳 Root node detected: {root}")
# --- Assemble schematic JSON ---
schematic_json = {
"schematic_id": sid,
"schematic_name": sname,
"root": str(root) if root else None,
"nodes": json_nodes,
"redundancies": redundancy_map
}
all_schematics_json[str(sid)] = schematic_json
print(f"✅ Finished schematic {sid}")
# --- Final JSON ---
final_json = {
"project_id": project["ProjectId"],
"project_name": project["ProjectName"],
"schematics": all_schematics_json
}
with open(output_file, "w") as f:
json.dump(final_json, f, indent=2)
print(f"\n🎉 Exported simplified RBD JSON (NodeId-based, availability=1.0) "
f"for Project {project_id}{output_file}")
if __name__ == "__main__":
export_rbd_json(project_id=70, output_file="project_70_rbd.json")

File diff suppressed because it is too large Load Diff

@ -0,0 +1,111 @@
import json
def series_availability(avails):
result = 1.0
for a in avails:
result *= a
return result
def parallel_availability(avails):
result = 1.0
for a in avails:
result *= (1 - a)
return 1 - result
def kofn_availability(avails, k):
if k <= 1:
return parallel_availability(avails)
return sum(avails) / len(avails) # simple approx
def compute_node_availability(node_id, schematic, schematics, overrides, visited):
if node_id in visited:
return 1.0
visited.add(node_id)
node = schematic["nodes"].get(node_id)
if not node:
return 1.0
node_name = node.get("name", "").strip().lower()
if node_name in overrides:
return overrides[node_name]
ntype = node["type"].lower()
if ntype == "regularnode":
return node.get("availability", 1.0)
elif ntype == "series":
return series_availability([
compute_node_availability(child, schematic, schematics, overrides, visited.copy())
for child in node.get("children", [])
])
elif ntype == "parallel":
return parallel_availability([
compute_node_availability(child, schematic, schematics, overrides, visited.copy())
for child in node.get("children", [])
])
elif ntype == "kofn":
k = node.get("min_required", 1)
return kofn_availability([
compute_node_availability(child, schematic, schematics, overrides, visited.copy())
for child in node.get("children", [])
], k)
elif ntype == "subschematic":
tschematic_id = node.get("tschematic_id")
if tschematic_id and str(tschematic_id) in schematics:
sub_schematic = schematics[str(tschematic_id)]
root = sub_schematic.get("root")
if root:
return compute_node_availability(root, sub_schematic, schematics, overrides, set())
return node.get("availability", 1.0)
return node.get("availability", 1.0)
def compute_schematic_availability(schematic, schematics, overrides):
root = schematic.get("root")
if not root:
return 1.0
return compute_node_availability(root, schematic, schematics, overrides, set())
def evaluate_project(json_file, overrides=None):
with open(json_file, "r") as f:
data = json.load(f)
schematics = data["schematics"]
overrides = overrides or {}
results = {}
top_availability = None
for sid, schematic in schematics.items():
name = schematic["schematic_name"].strip()
avail = compute_schematic_availability(schematic, schematics, overrides)
results[name] = avail
if name == "- TJB - Unit 3 -":
top_availability = avail
return results, top_availability
if __name__ == "__main__":
overrides = {
"WTP": 0.0, # Example override
}
results, top_avail = evaluate_project("project_70_rbd.json", overrides=overrides)
print("\n--- Schematic Availabilities ---")
for sch_name, avail in results.items():
print(f"{sch_name:25s}: {avail:.6f}")
print("\n=== TOTAL SYSTEM AVAILABILITY ===")
if top_avail is not None:
print(f"Top schematic (- TJB - Unit 3 -): {top_avail:.6f}")
else:
print("Top schematic not found in JSON!")

@ -5,85 +5,121 @@
{
"series": [
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB001A",
"3DCS-CAB001B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB002A",
"3DCS-CAB002B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB003A",
"3DCS-CAB003B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB004A",
"3DCS-CAB004B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB005A",
"3DCS-CAB005B",
"3DCS-CAB005C"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB006A",
"3DCS-CAB006B"
]
}
},
"3DCS-CAB007",
"3DCS-CAB008",
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB009A",
"3DCS-CAB009B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB010A",
"3DCS-CAB010B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CAB011A",
"3DCS-CAB011B"
]
}
},
"3DCS-CAB012",
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 1,
"components": [
"3DCS-CAB013A",
"3DCS-CAB013B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 1,
"components": [
"3DCS-CAB014A",
"3DCS-CAB014B"
]
}
},
"3DCS-CAB015",
"3DCS-CO001",
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3DCS-CO002A",
"3DCS-CO002B"
]
}
},
{
"parallel_no_redundancy": [
"parallel": [
"3DCS-CO003A",
"3DCS-CO003B",
"3DCS-CO003C",
@ -92,14 +128,17 @@
},
"3DCS-CO004",
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 3,
"components": [
"3DCS-CO005A",
"3DCS-CO005B",
"3DCS-CO005C"
]
}
},
{
"parallel_no_redundancy": [
"parallel": [
"3DCS-CO006A",
"3DCS-CO006B",
"3DCS-CO006C"
@ -113,8 +152,6 @@
"series": [
{
"parallel": [
{
"parallel_no_redundancy": [
{
"series": [
"00ACR-M001A",
@ -126,8 +163,6 @@
"00ACR-M001B",
"00ACR-C001B"
]
}
]
},
{
"series": [
@ -163,8 +198,6 @@
"3FW-H040",
{
"parallel": [
{
"parallel_no_redundancy": [
{
"series": [
"3LOT-T010A",
@ -179,8 +212,6 @@
},
{
"parallel": [
{
"parallel_no_redundancy": [
{
"series": [
"3LOT-M010A",
@ -192,8 +223,6 @@
"3LOT-M020A",
"3LOT-P020A"
]
}
]
},
{
"series": [
@ -239,8 +268,6 @@
},
{
"parallel": [
{
"parallel_no_redundancy": [
{
"series": [
"3LOT-M010B",
@ -252,8 +279,6 @@
"3LOT-M020B",
"3LOT-P020B"
]
}
]
},
{
"series": [
@ -284,8 +309,6 @@
]
}
]
}
]
},
{
"series": [
@ -317,7 +340,7 @@
"series": [
"3BOL-FD501",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
{
@ -524,7 +547,7 @@
"series": [
"3FO-FCV501",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3DM-B701A",
@ -562,7 +585,7 @@
"3BDW-H631",
"3BDW-H641",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3BDW-M521A",
@ -589,13 +612,13 @@
"3MS-HV013",
"3MS-HV014",
{
"parallel_no_redundancy": [
"parallel": [
"3MS-HV010A",
"3MS-HV010B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3MS-W001A",
"3MS-W001B"
]
@ -607,14 +630,14 @@
"series": [
"3BSS-H611",
{
"parallel_no_redundancy": [
"parallel": [
"3ATT-N501A",
"3ATT-N501B"
]
},
"3BSS-H621",
{
"parallel_no_redundancy": [
"parallel": [
"3ATT-N502A",
"3ATT-N502B"
]
@ -626,17 +649,20 @@
{
"series": [
{
"parallel_no_redundancy": ["3ATT-N503A", "3ATT-N503B"]
"parallel": [
"3ATT-N503A",
"3ATT-N503B"
]
},
"3BRS-H611",
"3BRS-H621",
"3BRS-H631"
]
},
},
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
"3HRH-HV020A",
"3HRH-HV020B"
]
@ -650,9 +676,9 @@
"series": [
"3AI-SFV501",
{
"parallel_no_redundancy": [
"parallel": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M501H",
@ -688,9 +714,9 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M501L",
@ -738,7 +764,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M501R",
@ -788,9 +814,9 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M501A",
@ -834,7 +860,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M506A",
@ -872,7 +898,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M515A",
@ -910,7 +936,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M510A",
@ -956,7 +982,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3AI-M551A",
@ -983,8 +1009,6 @@
"series": [
{
"parallel": [
{
"parallel_no_redundancy": [
{
"series": [
"3LOS-M010A",
@ -996,8 +1020,6 @@
"3LOS-M010B",
"3LOS-P010B"
]
}
]
},
{
"series": [
@ -1105,10 +1127,13 @@
"3EHB-P020",
"3EHB-T110",
{
"parallel": ["3EHB-P010A", "3EHB-P010B"]
"parallel": [
"3EHB-P010A",
"3EHB-P010B"
]
}
]
}
}
]
}
]
@ -1160,7 +1185,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3CW-M010A",
@ -1192,12 +1217,22 @@
"3GSS-H010",
{
"parallel": [
{"series": ["3GSS-M011A", "3GSS-F011A"]},
{"series": ["3GSS-M011B", "3GSS-F011B"]}
{
"series": [
"3GSS-M011A",
"3GSS-F011A"
]
},
{
"series": [
"3GSS-M011B",
"3GSS-F011B"
]
}
]
},
}
]
},
"3GEN-GM001",
{
"series": [
@ -1231,7 +1266,7 @@
"3GEN-GM001",
"3GEN-Z012",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3GEN-M101A",
@ -1250,15 +1285,11 @@
},
{
"parallel": [
{
"parallel_no_redundancy": [
"3GEN-M201A",
"3GEN-M202A",
"3GEN-M203A",
"3GEN-M204A",
"3GEN-M205A"
]
},
"3GEN-M205A",
"3GEN-M206A"
]
}
@ -1270,7 +1301,7 @@
"3GMC-Z001",
"3GMC-Z003",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3GEN-M211A",
@ -1306,25 +1337,21 @@
{
"series": [
{
"parallel_no_redundancy": [
{
"series": [
"parallel": [
"3TR-TF002A",
"3TR-Z003A"
"3TR-TF002B"
]
},
{
"series": [
"3TR-TF002B",
"3TR-Z003B"
]
}
"parallel": [
"3TR-Z003A",
"3TR-Z003A"
]
},
"3TR-TF001",
"3TR-TF005",
{
"parallel_no_redundancy": [
"parallel": [
"3TR-F301",
"3TR-F302",
"3TR-F303",
@ -1393,18 +1420,22 @@
"3CCCW-T010",
"3CCCW-M090",
"3CCCW-P090",
{
"parallel": [
"3CCCW-M010A",
"3CCCW-M010B"
]
},
{
"parallel": [
{
"series": [
"3CCCW-M010A",
"3CCCW-P010A",
"3CCCW-H010A"
]
},
{
"series": [
"3CCCW-M010B",
"3CCCW-P010B",
"3CCCW-H010B"
]
@ -1414,7 +1445,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
{
@ -1441,11 +1472,11 @@
"3AH-M501A",
"3AH-H501A"
]
},
},
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3ESP-CAB801",
@ -1499,7 +1530,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
"3GG-F853A",
"3GG-F853B",
"3GG-F853C",
@ -1579,7 +1610,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3ESP-CAB803",
@ -1634,7 +1665,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
"3GG-F854A",
"3GG-F854B",
"3GG-F854C",
@ -1737,7 +1768,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
"3APC-CB811",
"3APC-CB812",
"3APC-CB813",
@ -1745,25 +1776,25 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-LV001A",
"3APC-LV001B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-LV501A",
"3APC-LV501B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-LV810A",
"3APC-LV810B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-LV811P1",
"3APC-LV811P2",
"3APC-LV811P3",
@ -1775,13 +1806,13 @@
"3APC-LV851",
"3APC-MCC002",
{
"parallel_no_redundancy": [
"parallel": [
"3APC-MCC501A",
"3APC-MCC501B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-MCC502A",
"3APC-MCC502B",
"3APC-MCC502C",
@ -1793,43 +1824,43 @@
"3APC-MCC510",
"3APC-MCC851",
{
"parallel_no_redundancy": [
"parallel": [
"3APC-PD501A",
"3APC-PD501B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-PD901",
"3APC-PD902"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-PD921",
"3APC-PD922"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-TF001A",
"3APC-TF001B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-TF501A",
"3APC-TF501B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-TF502A",
"3APC-TF502B"
]
},
{
"parallel_no_redundancy": [
"parallel": [
"3APC-TF810A",
"3APC-TF810B"
]
@ -1842,42 +1873,54 @@
"series": [
"3APE-CAB852",
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3APE-MV001A",
"3APE-MV001B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3APE-MV002A",
"3APE-MV002B"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 4,
"components": [
"3APE-MV003A",
"3APE-MV003B",
"3APE-MV003C",
"3APE-MV003D"
]
}
},
{
"parallel_no_redundancy": [
"k_of_n": {
"k": 2,
"components": [
"3APE-MV004A",
"3APE-MV004B"
]
}
},
"3APE-MV851",
"3APE-MV852",
{
"parallel_no_redundancy": [
"parallel": [
"3APE-TF002A",
"3APE-TF002B"
]
},
"3APE-TF852",
{
"parallel_no_redundancy": [
"parallel": [
"3APE-Z005A",
"3APE-Z005B"
]
@ -1897,7 +1940,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3ABS-M879A",
@ -1950,7 +1993,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"3ABS-M888A",
@ -2056,7 +2099,7 @@
{
"series": [
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RO-M110A",
@ -2108,7 +2151,7 @@
"00RO-T320",
"00RO-T130",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RO-M126A",
@ -2172,7 +2215,7 @@
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RO-M160A",
@ -2203,7 +2246,7 @@
"SBS DOSING",
"ANTI SCALANT DOSING",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RO-M170A",
@ -2277,7 +2320,7 @@
},
"00RO-T162",
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RO-M190A",
@ -2479,7 +2522,7 @@
"series": [
"00RP-BM871",
{
"parallel_no_redundancy": [
"parallel": [
"00RP-M871A",
"00RP-M871B"
]
@ -2612,18 +2655,14 @@
},
{
"parallel": [
{
"parallel_no_redundancy": [
"00RP-Z851A",
"00RP-Z851B",
"00RP-Z851C"
]
},
"00RP-Z851C",
"00RP-Z851D"
]
},
{
"parallel_no_redundancy": [
"parallel": [
{
"series": [
"00RP-M856A",
@ -2649,7 +2688,7 @@
"00SSB-EV002",
"00SSB-EV003",
{
"parallel_no_redundancy": [
"parallel": [
"00SSB-EV004",
"00SSB-EV005"
]

@ -58,17 +58,40 @@ def system_availability(structure: Structure, availabilities: Dict[str, float])
result = Decimal('1.0') - product
return float(result)
elif "parallel_no_redundancy" in structure:
# Load sharing - system availability is minimum of components
components = structure["parallel_no_redundancy"]
elif "k_of_n" in structure:
k = structure["k_of_n"]["k"]
components = structure["k_of_n"]["components"]
if not components:
return 0.0
availabilities_list = [system_availability(s, availabilities) for s in components]
return min(availabilities_list)
component_availabilities = [system_availability(s, availabilities) for s in components]
return k_of_n_availability(component_availabilities, k)
raise ValueError(f"Invalid structure definition: {structure}")
from itertools import combinations
from decimal import Decimal
from math import comb
def k_of_n_availability(availabilities: list[float], k: int) -> float:
n = len(availabilities)
total = Decimal('0.0')
# Iterate over all combinations of components that can be working
for j in range(k, n+1):
for subset in combinations(range(n), j):
prob = Decimal('1.0')
for i in range(n):
if i in subset:
prob *= Decimal(str(availabilities[i]))
else:
prob *= (Decimal('1.0') - Decimal(str(availabilities[i])))
total += prob
return float(total)
def get_all_components(structure: Structure) -> set:
"""Extract all component names from a structure."""

@ -132,6 +132,8 @@ class AerosSimulationCalcResult(Base, DefaultMixin):
contribution = Column(Float, nullable=True)
criticality = Column(Float, nullable=True)
contribution_factor = Column(Float, nullable=True)
total_mo_downtime = Column(Float, nullable=True)
total_po_downtime = Column(Float, nullable=True)
aeros_simulation_id = Column(
UUID(as_uuid=True), ForeignKey("rbd_tr_aeros_simulation.id"), nullable=False

@ -231,14 +231,14 @@ async def get_simulation_result_plot_per_node(db_session: DbSession, simulation_
}
@router.get("/result/ranking/{simulation_id}", response_model=StandardResponse[List[SimulationRankingParameters]])
async def get_simulation_result_ranking(db_session: DbSession, simulation_id):
async def get_simulation_result_ranking(db_session: DbSession, simulation_id, limit:int = Query(None)):
"""Get simulation result."""
if simulation_id == 'default':
simulation = await get_default_simulation(db_session=db_session)
simulation_id = simulation.id
simulation_result = await get_result_ranking(db_session=db_session, simulation_id=simulation_id)
simulation_result = await get_result_ranking(db_session=db_session, simulation_id=simulation_id, limit=limit)
return {
"data": simulation_result,

@ -213,7 +213,7 @@ async def get_plant_calc_result(
return calc.scalar_one_or_none()
async def get_result_ranking(*, db_session: DbSession, simulation_id: UUID):
async def get_result_ranking(*, db_session: DbSession, simulation_id: UUID, limit: Optional[int]):
query = select(AerosEquipment, AerosSimulationCalcResult.availability).join(AerosNode, AerosNode.node_name == AerosEquipment.node_name).join(AerosSimulationCalcResult, AerosSimulationCalcResult.aeros_node_id == AerosNode.id)
@ -225,7 +225,10 @@ async def get_result_ranking(*, db_session: DbSession, simulation_id: UUID):
)
)
query = query.order_by(AerosSimulationCalcResult.availability.desc()).limit(10)
query = query.order_by(AerosSimulationCalcResult.availability.desc())
if limit:
query = query.limit(limit)
query = query.options(

Loading…
Cancel
Save