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)
|
||||
let mut kind_roles: HashMap<String, HashMap<String, EquipmentRolePoint>> = HashMap::new();
|
||||
// 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 {
|
||||
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());
|
||||
}
|
||||
}
|
||||
all_roles.push(role_map);
|
||||
all_roles.push((equip.id, role_map));
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(
|
||||
|
|
@ -102,7 +102,7 @@ async fn tick_unit(
|
|||
.await;
|
||||
|
||||
// ── 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
|
||||
.get(&rp.point_id)
|
||||
.map(|m| m.quality != PointQuality::Good)
|
||||
|
|
@ -122,7 +122,7 @@ async fn tick_unit(
|
|||
}
|
||||
|
||||
// ── Fault check ──────────────────────────────────────────
|
||||
let any_flt = all_roles.iter().any(|roles| {
|
||||
let any_flt = all_roles.iter().any(|(_, roles)| {
|
||||
roles
|
||||
.get("flt")
|
||||
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
||||
|
|
@ -135,18 +135,16 @@ async fn tick_unit(
|
|||
|
||||
if any_flt && !runtime.fault_locked {
|
||||
// Find which equipment triggered the fault
|
||||
let flt_eq_id = equipment_list
|
||||
let flt_eq_id = all_roles
|
||||
.iter()
|
||||
.find(|_e| {
|
||||
all_roles.iter().any(|roles| {
|
||||
roles
|
||||
.get("flt")
|
||||
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
||||
.map(|m| monitor_value_as_bool(m))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.find(|(_, roles)| {
|
||||
roles
|
||||
.get("flt")
|
||||
.and_then(|rp| monitor_guard.get(&rp.point_id))
|
||||
.map(|m| monitor_value_as_bool(m))
|
||||
.unwrap_or(false)
|
||||
})
|
||||
.map(|e| e.id)
|
||||
.map(|(eq_id, _)| *eq_id)
|
||||
.unwrap_or(Uuid::nil());
|
||||
|
||||
runtime.fault_locked = true;
|
||||
|
|
|
|||
Loading…
Reference in New Issue