diff --git a/src/main.rs b/src/main.rs index 6f52d61..791a66e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -45,6 +45,9 @@ pub enum Commands { csvfile: PathBuf, }, /// Get LVDS TX skew from slave log _clk file. + /// + /// PSB ID is extracted from `logfile` name and the corresponding QAQC run is retrieved by + /// searching the n-th run with the same PSB ID in chronological order. AddSkew { /// Slave _clk log file. logfile: PathBuf, diff --git a/src/skew.rs b/src/skew.rs index a47e8e0..73bf381 100644 --- a/src/skew.rs +++ b/src/skew.rs @@ -6,6 +6,27 @@ use std::{ path::PathBuf, }; +use crate::PsbId; + +/// Extract PsbId and runid from filename. +/// +/// format: +/// `PSBID_RUNID_clk.txt` +pub fn get_psbid_from_clklogfile(path: PathBuf) -> Result<(PsbId, u32)> { + let filename = path + .file_stem() + .context("path is not a file")? + .to_str() + .context("Invalid utf-8")?; + let mut parts = filename.split('_'); + let psbid: PsbId = { + let id: u32 = parts.next().context("No psbid")?.parse()?; + PsbId::new(id) + }; + let runid = parts.next().context("No run id")?.parse()?; + Ok((psbid, runid)) +} + fn parse_single_line(l: String) -> Result<(f64, u32, u32)> { let mut splitted = l.split_whitespace(); let delay: f64 = splitted.next().context("No value found")?.parse()?; @@ -38,7 +59,22 @@ pub fn parse_count_file(filename: PathBuf) -> Result { #[cfg(test)] mod test { + use crate::{skew::get_psbid_from_clklogfile, PsbId}; + use super::parse_counts; + + #[test] + fn test_get_psbid_from_clklog() { + assert_eq!( + get_psbid_from_clklogfile("120_1234.log".into()).unwrap(), + (PsbId::new(1020), 1234) + ); + assert_eq!( + get_psbid_from_clklogfile("1024_124.log".into()).unwrap(), + (PsbId::new(1024), 124) + ); + } + #[test] fn test_parse_counts1() { let file = "