parse_monitors/monitors/reports/
loader.rs

1use std::path::Path;
2
3#[cfg(feature = "2020")]
4mod y2020;
5#[cfg(any(feature = "2021", feature = "2025"))]
6mod y2021_25;
7
8pub struct MonitorsLoader<const YEAR: u32> {
9    pub(crate) path: String,
10    pub(crate) time_range: (f64, f64),
11    pub(crate) header_regex: String,
12    pub(crate) header_exclude_regex: Option<String>,
13}
14impl<const YEAR: u32> Default for MonitorsLoader<YEAR> {
15    fn default() -> Self {
16        Self {
17            path: String::from("monitors.csv"),
18            time_range: (0f64, f64::INFINITY),
19            header_regex: String::from(r"\w+"),
20            header_exclude_regex: None,
21        }
22    }
23}
24impl<const YEAR: u32> MonitorsLoader<YEAR> {
25    pub fn data_path<S: AsRef<Path> + std::convert::AsRef<std::ffi::OsStr>>(
26        self,
27        data_path: S,
28    ) -> Self {
29        let path = Path::new(&data_path).join("monitors.csv");
30        Self {
31            path: path.to_str().unwrap().to_owned(),
32            ..self
33        }
34    }
35    pub fn start_time(self, time: f64) -> Self {
36        Self {
37            time_range: (time, self.time_range.1),
38            ..self
39        }
40    }
41    pub fn end_time(self, time: f64) -> Self {
42        Self {
43            time_range: (self.time_range.0, time),
44            ..self
45        }
46    }
47    pub fn header_filter<S: Into<String>>(self, header_regex: S) -> Self {
48        Self {
49            header_regex: header_regex.into(),
50            ..self
51        }
52    }
53    pub fn exclude_filter<S: Into<String>>(self, header_exclude_regex: S) -> Self {
54        Self {
55            header_exclude_regex: Some(header_exclude_regex.into()),
56            ..self
57        }
58    }
59}