big_code_analysis/vcs/hotspot.rs
1//! Complexity × churn "hotspot" score (Tornhill; Nagappan & Ball).
2//!
3//! A hotspot is a file that is both complex *and* changes often — the
4//! intersection the empirical work finds most defect-prone. It is only
5//! meaningful when an AST-derived complexity figure is available
6//! alongside the change history, so the field is `Option<f64>` on the
7//! serialized stats and is filled in by the consumer that has both
8//! halves (e.g. `bca metrics --metrics cyclomatic,vcs`).
9
10/// Compute the hotspot score from a complexity index and recent churn.
11///
12/// `complexity_index` is supplied by the caller from whichever
13/// AST metric it treats as the complexity axis (the CLI uses the
14/// file-level cyclomatic sum, the conventional hotspot proxy). The
15/// product is ordinal, like the risk score: rank files by it, do not
16/// read absolute magnitudes.
17#[must_use]
18#[allow(clippy::cast_precision_loss)]
19pub fn hotspot_score(complexity_index: f64, churn_recent: u64) -> f64 {
20 complexity_index.max(0.0) * churn_recent as f64
21}
22
23#[cfg(test)]
24#[path = "hotspot_tests.rs"]
25mod tests;