new: get run information from skew log file name

This commit is contained in:
Wataru Otsubo 2024-07-24 12:45:30 +09:00
parent 73a169c68f
commit 059283fab3
2 changed files with 39 additions and 0 deletions

View file

@ -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,

View file

@ -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<f64> {
#[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 = "