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
71
72
73
74
75
76
77
78
79
80
81
use crate::xiolisa::LoadableDevice;
use crate::{file_load_json as load_json, LoadPathPattern, Result};
use indexmap::{IndexMap, IndexSet};
use std::path::PathBuf;

#[derive(Debug)]
pub struct Device {
    inner: crate::filesystem::Device,
}

impl Device {
    pub fn new(inner: crate::filesystem::Device) -> Self {
        Device { inner }
    }

    pub fn calibration_dir(&self, calibration_id: &str) -> PathBuf {
        self.inner
            .description_calibration_dir(calibration_id)
            .join("xiolisa")
    }

    pub fn calibration_job_file(
        &self,
        calibration_id: &str,
        job_id: &str,
    ) -> PathBuf {
        self.calibration_dir(calibration_id)
            .join(format!("{}.json", job_id))
    }

    pub fn sampling_dir(&self, sampling_id: &str) -> PathBuf {
        self.inner.sampling_dir(sampling_id).join("xiolisa")
    }

    pub fn sampling_job_file(
        &self,
        sampling_id: &str,
        job_id: &str,
    ) -> PathBuf {
        self.sampling_dir(sampling_id)
            .join(format!("{}.json", job_id))
    }
}

impl LoadableDevice for Device {
    fn load_calibration_mapping_index(
        &self,
        calibration_id: &str,
    ) -> Result<IndexSet<String>> {
        IndexSet::load_path_pattern_from_dir(
            self.calibration_dir(calibration_id),
            "*.json",
        )
    }

    fn load_calibration_mapping(
        &self,
        calibration_id: &str,
        job_id: &str,
    ) -> Result<IndexMap<String, IndexMap<String, String>>> {
        load_json(self.calibration_job_file(calibration_id, job_id))
    }

    fn load_sampling_mapping_index(
        &self,
        sampling_id: &str,
    ) -> Result<IndexSet<String>> {
        IndexSet::load_path_pattern_from_dir(
            self.sampling_dir(sampling_id),
            "*.json",
        )
    }

    fn load_sampling_mapping(
        &self,
        sampling_id: &str,
        job_id: &str,
    ) -> Result<IndexMap<String, IndexMap<String, String>>> {
        load_json(self.sampling_job_file(sampling_id, job_id))
    }
}