MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / looks_epoch_like

Function looks_epoch_like

nodedb/src/engine/timeseries/ts_detect.rs:111–132  ·  view source on GitHub ↗

Check if a sample of i64 values look like epoch timestamps. Heuristic: at least 80% of values fall within a reasonable epoch range (2000-01-01 to 2100-01-01 in seconds, milliseconds, microseconds, or nanoseconds).

(values: &[i64])

Source from the content-addressed store, hash-verified

109/// Heuristic: at least 80% of values fall within a reasonable epoch range
110/// (2000-01-01 to 2100-01-01 in seconds, milliseconds, microseconds, or nanoseconds).
111fn looks_epoch_like(values: &[i64]) -> bool {
112 if values.is_empty() {
113 return false;
114 }
115
116 // Epoch ranges for different resolutions.
117 let ranges: &[(i64, i64)] = &[
118 (946_684_800, 4_102_444_800), // seconds
119 (946_684_800_000, 4_102_444_800_000), // milliseconds
120 (946_684_800_000_000, 4_102_444_800_000_000), // microseconds
121 (946_684_800_000_000_000, 4_102_444_800_000_000_000), // nanoseconds
122 ];
123
124 let threshold = (values.len() * 4) / 5; // 80%
125 for &(min, max) in ranges {
126 let matches = values.iter().filter(|&&v| v >= min && v <= max).count();
127 if matches >= threshold {
128 return true;
129 }
130 }
131 false
132}
133
134#[cfg(test)]
135mod tests {

Callers 1

detect_timestampFunction · 0.85

Calls 4

is_emptyMethod · 0.45
lenMethod · 0.45
countMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected