elata_eeg_models/model.rs
1//! Core model trait
2
3use elata_eeg_hal::SampleBuffer;
4
5/// Output from a model analysis
6pub trait ModelOutput: Clone {
7 /// Get a human-readable description of the output
8 fn description(&self) -> String;
9
10 /// Get the primary numeric value (if applicable)
11 fn value(&self) -> Option<f32> {
12 None
13 }
14
15 /// Get confidence level (0.0 to 1.0) if applicable
16 fn confidence(&self) -> Option<f32> {
17 None
18 }
19}
20
21/// Core trait for EEG analysis models
22///
23/// Models take buffered EEG data and produce analysis outputs.
24/// They maintain internal state for temporal analysis.
25pub trait Model {
26 /// The output type produced by this model
27 type Output: ModelOutput;
28
29 /// Get the model name
30 fn name(&self) -> &str;
31
32 /// Get the minimum number of samples required for analysis
33 fn min_samples(&self) -> usize;
34
35 /// Process a buffer of samples and produce output
36 ///
37 /// This may return `None` if there's not enough data yet,
38 /// or if the model needs more time to produce a stable output.
39 fn process(&mut self, buffer: &SampleBuffer) -> Option<Self::Output>;
40
41 /// Reset the model's internal state
42 fn reset(&mut self);
43
44 /// Check if the model has enough data to produce output
45 fn is_ready(&self, buffer: &SampleBuffer) -> bool {
46 buffer.sample_count() >= self.min_samples()
47 }
48}