pub fn observation_gap_segment_ids(times: &[f64], gap_s: f64) -> Vec<u32> {
let n = times.len();
let mut out = vec![0u32; n];
if n == 0 {
return out;
}
let mut group = 0u32;
for i in 1..n {
if times[i] - times[i - 1] > gap_s {
group += 1;
}
out[i] = group;
}
out
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_and_single_point_inputs() {
assert_eq!(observation_gap_segment_ids(&[], 60.0), Vec::<u32>::new());
assert_eq!(observation_gap_segment_ids(&[0.0], 60.0), vec![0]);
}
#[test]
fn a_gap_above_threshold_splits_into_two_segments() {
let times = vec![0.0, 60.0, 120.0, 3720.0, 3780.0];
let ids = observation_gap_segment_ids(×, 600.0);
assert_eq!(ids, vec![0, 0, 0, 1, 1]);
}
#[test]
fn a_gap_at_or_below_threshold_never_splits() {
let times = vec![0.0, 60.0, 660.0, 720.0];
let ids = observation_gap_segment_ids(×, 600.0);
assert_eq!(ids, vec![0, 0, 0, 0]);
}
}