pub struct Trend { /* private fields */ }vcs-git only.Expand description
The change-history metrics of a set of files sampled at several points in time (issue #333).
Each file maps to a vector aligned 1:1 with as_of_points:
element i is Some(stats) when the file existed and was tracked at
point i, or None when it did not exist yet (or was untracked /
binary) at that point.
§Rename limitation
Each snapshot keys files by their path at that snapshot’s tip, with renames followed only within that snapshot’s walk. A file renamed between two sampled points therefore appears as two separate path series (its old name, then its new name), not one continuous series. Cross-snapshot rename stitching is deferred; document this for consumers reading the series.
Implementations§
Source§impl Trend
impl Trend
Sourcepub fn from_snapshots(
as_of_points: Vec<i64>,
per_point: Vec<HashMap<PathBuf, Stats>>,
long_window_days: u32,
recent_window_days: u32,
truncated_shallow_clone: bool,
) -> Self
pub fn from_snapshots( as_of_points: Vec<i64>, per_point: Vec<HashMap<PathBuf, Stats>>, long_window_days: u32, recent_window_days: u32, truncated_shallow_clone: bool, ) -> Self
Assemble a Trend from one HistoryIndex
per time point.
as_of_points are the sampled timestamps (oldest-first).
per_point is the matching per-file Stats map for each point, in
the same order; a point that resolved to no commit (the repository
did not exist yet) contributes an empty map, leaving every file
None there. The two slices must be the same length — a backend
invariant, so a mismatch is a programming error rather than a
user-facing one.
Sourcepub fn as_of_points(&self) -> &[i64]
pub fn as_of_points(&self) -> &[i64]
The sampled timestamps, oldest-first, aligned 1:1 with each file’s point vector.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&PathBuf, &[Option<Stats>])>
pub fn iter(&self) -> impl Iterator<Item = (&PathBuf, &[Option<Stats>])>
Iterate (repo-relative path, per-point stats) pairs. Each inner
slice is aligned with as_of_points;
elements are None where the file did not exist.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of files tracked across the whole trend (the union over all points).
Sourcepub fn long_window_days(&self) -> u32
pub fn long_window_days(&self) -> u32
Long window length, in days (constant across all points).
Sourcepub fn recent_window_days(&self) -> u32
pub fn recent_window_days(&self) -> u32
Recent window length, in days (constant across all points).
Sourcepub fn truncated_shallow_clone(&self) -> bool
pub fn truncated_shallow_clone(&self) -> bool
true when any sampled snapshot came from a shallow clone, so the
per-point counts are lower bounds.
Sourcepub fn deltas(&self, top: usize) -> TrendDeltas
pub fn deltas(&self, top: usize) -> TrendDeltas
The most-improved and most-regressed files by change in
risk_score between each file’s earliest and latest present
points.
A file is only eligible when it is present at two or more points
(otherwise there is no direction to report). delta = last_risk - first_risk: negative means risk fell (improved), positive means it
rose (regressed). top truncates each list (0 keeps all). Ties
break on the file path so the output is deterministic.