light_curve_feature/features/
maximum_time_interval.rs1use crate::evaluator::*;
2use itertools::Itertools;
3
4macro_const! {
5 const DOC: &str = r"
6Maximum time interval between consequent observations
7
8$$
9\max{(t_{i+1} - t_i)}
10$$
11
12Note: highly cadence-dependent feature.
13
14- Depends on: **time**
15- Minimum number of observations: **2**
16- Number of features: **1**
17";
18}
19
20#[doc = DOC!()]
21#[derive(Clone, Default, Debug, Deserialize, Serialize, JsonSchema)]
22pub struct MaximumTimeInterval {}
23
24impl MaximumTimeInterval {
25 pub fn new() -> Self {
26 Self {}
27 }
28
29 pub const fn doc() -> &'static str {
30 DOC
31 }
32}
33
34lazy_info!(
35 MAXIMUM_TIME_INTERVAL_INFO,
36 MaximumTimeInterval,
37 size: 1,
38 min_ts_length: 2,
39 t_required: true,
40 m_required: false,
41 w_required: false,
42 sorting_required: true,
43);
44
45impl FeatureNamesDescriptionsTrait for MaximumTimeInterval {
46 fn get_names(&self) -> Vec<&str> {
47 vec!["maximum_time_interval"]
48 }
49
50 fn get_descriptions(&self) -> Vec<&str> {
51 vec!["maximum time interval between consequent observations"]
52 }
53}
54
55impl<T> FeatureEvaluator<T> for MaximumTimeInterval
56where
57 T: Float,
58{
59 fn eval(&self, ts: &mut TimeSeries<T>) -> Result<Vec<T>, EvaluatorError> {
60 self.check_ts_length(ts)?;
61 let dt =
62 ts.t.as_slice()
63 .iter()
64 .tuple_windows()
65 .map(|(&a, &b)| b - a)
66 .max_by(|a, b| a.partial_cmp(b).unwrap())
67 .unwrap();
68 Ok(vec![dt])
69 }
70}
71
72#[cfg(test)]
73#[allow(clippy::unreadable_literal)]
74#[allow(clippy::excessive_precision)]
75mod tests {
76 use super::*;
77 use crate::tests::*;
78
79 check_feature!(MaximumTimeInterval);
80
81 feature_test!(
82 maximum_time_interval,
83 [MaximumTimeInterval::new()],
84 [9.0],
85 [0.0_f32, 0.5, 0.6, 1.6, 10.6],
86 );
87}