ifc_lite_geometry/router/diagnostics/
attribution.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5//! Who a CSG failure belongs to: the synthetic bucket for records with no
6//! owner, and the one place that decides what counts as a failing PRODUCT.
7//!
8//! Split out of `router/diagnostics.rs` (module-size ratchet, #3821).
9
10use crate::BoolFailure;
11use rustc_hash::FxHashMap;
12
13/// The `csg_failures` key used for records that belong to no single product:
14/// the boolean processors' own logs (swept once per element by
15/// [`crate::GeometryRouter::drain_processor_failures`]) and
16/// `PENDING_MAPPED_BOOL_FAILURES`. Zero is not a valid IFC express id, so it
17/// cannot collide with a real product.
18pub const UNATTRIBUTED_PRODUCT_ID: u32 = 0;
19
20/// How many REAL products have at least one failure. The synthetic
21/// [`UNATTRIBUTED_PRODUCT_ID`] bucket is excluded: it is not a product, and
22/// counting it would report "1 product failed" for a model where the only
23/// records came from an unattributed sweep. Its records still count towards
24/// the failure TOTALS — they are real failures, only their owner is unknown.
25///
26/// One home, called from `aggregate_diagnostics` and from both pipelines'
27/// legacy scalar (`ProcessingStats.products_with_failures`, the wasm console
28/// summary), so the two cannot drift.
29pub fn count_attributed_products(csg_failures: &FxHashMap<u32, Vec<BoolFailure>>) -> u64 {
30    csg_failures
31        .keys()
32        .filter(|id| **id != UNATTRIBUTED_PRODUCT_ID)
33        .count() as u64
34}