1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use crate::arnalisa::{Calibration, Sampling};
use crate::Result;
use arnalisa::bins::SourceSinkDescription;
use indexmap::{IndexMap, IndexSet};

pub trait LoadableDevice {
    fn load_calibration_bin(
        &self,
        calibration_id: &str,
        bin_id: &str,
    ) -> Result<SourceSinkDescription>;

    fn load_calibration_bin_index(
        &self,
        calibration_id: &str,
    ) -> Result<IndexSet<String>>;

    fn load_calibration_bins(
        &self,
        calibration_id: &str,
    ) -> Result<IndexMap<String, SourceSinkDescription>> {
        self.load_calibration_bin_index(calibration_id)?
            .into_iter()
            .map(|id| {
                let item =
                    self.load_calibration_bin(calibration_id, &id)?;
                Ok((id, item))
            })
            .collect::<Result<_>>()
    }

    fn load_calibration(
        &self,
        calibration_id: &str,
    ) -> Result<Calibration> {
        Ok(Calibration {
            bins: self.load_calibration_bins(calibration_id)?,
        })
    }

    fn load_sampling_bin(
        &self,
        sampling_id: &str,
        bin_id: &str,
    ) -> Result<SourceSinkDescription>;

    fn load_sampling_bin_index(
        &self,
        sampling_id: &str,
    ) -> Result<IndexSet<String>>;

    fn load_sampling_bins(
        &self,
        sampling_id: &str,
    ) -> Result<IndexMap<String, SourceSinkDescription>> {
        self.load_sampling_bin_index(sampling_id)?
            .into_iter()
            .map(|id| {
                let item = self.load_sampling_bin(sampling_id, &id)?;
                Ok((id, item))
            })
            .collect::<Result<_>>()
    }

    fn load_sampling(&self, sampling_id: &str) -> Result<Sampling> {
        Ok(Sampling {
            bins: self.load_sampling_bins(sampling_id)?,
        })
    }
}