ommui_data 0.39.0

OMMUI data structures
Documentation
use crate::arnalisa::LoadableDevice;
use crate::{file_load_json as load_json, LoadPathPattern, Result};
use arnalisa::bins::SourceSinkDescription;
use indexmap::IndexSet;
use std::path::PathBuf;

#[derive(Clone, 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("arnalisa")
    }

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

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

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

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

    fn load_calibration_bin(
        &self,
        calibration_id: &str,
        bin_id: &str,
    ) -> Result<SourceSinkDescription> {
        load_json(self.calibration_bin_file(calibration_id, bin_id))
    }

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

    fn load_sampling_bin(
        &self,
        sampling_id: &str,
        bin_id: &str,
    ) -> Result<SourceSinkDescription> {
        load_json(self.sampling_bin_file(sampling_id, bin_id))
    }
}