fix(engine): correct fault equipment ID lookup and all_roles data structure
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
0c2ce48d23
commit
b5a8d6a71d
|
|
@ -63,7 +63,7 @@ async fn tick_unit(
|
||||||
// kind -> role -> EquipmentRolePoint (first equipment per kind wins)
|
// kind -> role -> EquipmentRolePoint (first equipment per kind wins)
|
||||||
let mut kind_roles: HashMap<String, HashMap<String, EquipmentRolePoint>> = HashMap::new();
|
let mut kind_roles: HashMap<String, HashMap<String, EquipmentRolePoint>> = HashMap::new();
|
||||||
// all role maps for fault/comm scanning across all equipment
|
// all role maps for fault/comm scanning across all equipment
|
||||||
let mut all_roles: Vec<HashMap<String, EquipmentRolePoint>> = Vec::new();
|
let mut all_roles: Vec<(Uuid, HashMap<String, EquipmentRolePoint>)> = Vec::new();
|
||||||
|
|
||||||
for equip in &equipment_list {
|
for equip in &equipment_list {
|
||||||
match crate::service::get_equipment_role_points(&state.pool, equip.id).await {
|
match crate::service::get_equipment_role_points(&state.pool, equip.id).await {
|
||||||
|
|
@ -84,7 +84,7 @@ async fn tick_unit(
|
||||||
kind_roles.insert(kind.clone(), role_map.clone());
|
kind_roles.insert(kind.clone(), role_map.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
all_roles.push(role_map);
|
all_roles.push((equip.id, role_map));
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
|
|
@ -102,7 +102,7 @@ async fn tick_unit(
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
// ── Communication check ──────────────────────────────────
|
// ── Communication check ──────────────────────────────────
|
||||||
let any_bad_quality = all_roles.iter().flat_map(|r| r.values()).any(|rp| {
|
let any_bad_quality = all_roles.iter().flat_map(|(_, r)| r.values()).any(|rp| {
|
||||||
monitor_guard
|
monitor_guard
|
||||||
.get(&rp.point_id)
|
.get(&rp.point_id)
|
||||||
.map(|m| m.quality != PointQuality::Good)
|
.map(|m| m.quality != PointQuality::Good)
|
||||||
|
|
@ -122,7 +122,7 @@ async fn tick_unit(
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Fault check ──────────────────────────────────────────
|
// ── Fault check ──────────────────────────────────────────
|
||||||
let any_flt = all_roles.iter().any(|roles| {
|
let any_flt = all_roles.iter().any(|(_, roles)| {
|
||||||
roles
|
roles
|
||||||
.get("flt")
|
.get("flt")
|
||||||
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
||||||
|
|
@ -135,18 +135,16 @@ async fn tick_unit(
|
||||||
|
|
||||||
if any_flt && !runtime.fault_locked {
|
if any_flt && !runtime.fault_locked {
|
||||||
// Find which equipment triggered the fault
|
// Find which equipment triggered the fault
|
||||||
let flt_eq_id = equipment_list
|
let flt_eq_id = all_roles
|
||||||
.iter()
|
.iter()
|
||||||
.find(|_e| {
|
.find(|(_, roles)| {
|
||||||
all_roles.iter().any(|roles| {
|
|
||||||
roles
|
roles
|
||||||
.get("flt")
|
.get("flt")
|
||||||
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
||||||
.map(|m| monitor_value_as_bool(m))
|
.map(|m| monitor_value_as_bool(m))
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
})
|
})
|
||||||
})
|
.map(|(eq_id, _)| *eq_id)
|
||||||
.map(|e| e.id)
|
|
||||||
.unwrap_or(Uuid::nil());
|
.unwrap_or(Uuid::nil());
|
||||||
|
|
||||||
runtime.fault_locked = true;
|
runtime.fault_locked = true;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue