add: check-db command & add-skew command protoptype

This commit is contained in:
Wataru Otsubo 2024-07-21 21:23:32 +09:00
parent e856f1575a
commit fb11f18bbb
3 changed files with 39 additions and 11 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Subcommand `add-master-log` to parse master log for shiftwork 0.1.0 and write out to CSV
- Subcommand `add-master-log` to parse master log for shiftwork 0.1.0 and write out to CSV.
- Subcommand `check-db` to validate the database CSV file.
[Unreleased]: https://gitlab.cern.ch

View file

@ -37,6 +37,18 @@ pub enum Commands {
// #[arg(default_value = get_default_log_path().into_os_string())]
outfile: PathBuf,
},
/// Check CSV format
CheckDB {
/// Database CSV file.
csvfile: PathBuf,
},
/// Get LVDS TX skew from slave log _clk file.
AddSkew {
/// Slave _clk log file.
logfile: PathBuf,
/// Output CSV file.
outfile: PathBuf,
},
}
/// Layer
@ -473,15 +485,6 @@ fn main() -> Result<()> {
};
debug!("{:?}", result);
// {
// let file = File::options()
// .read(true)
// .open(args.outfile)?;
//
// let mut rdr = csv::Reader::from_reader(file);
// rdr.records();
// }
let expanded_results = PsbQaqcResult::from_masterlogresult(result);
let mut wtr = match outfile.exists() {
@ -504,6 +507,22 @@ fn main() -> Result<()> {
}
wtr.flush()?;
}
Commands::CheckDB { csvfile } => {
// TODO: more friendly message (like row number)
// TODO: more validation options (e.g. for each stage(Master log, Slave log(end of
// campaign)))
// TODO: Masterログが得られたときや、行として完成していかないときなど複数段階のチェックを用意する
let file = File::options().read(true).open(csvfile)?;
let rdr = csv::Reader::from_reader(file);
if !rdr
.into_deserialize::<PsbQaqcResult>()
.all(|row| row.is_ok())
{
return Err(anyhow!("Invalid csv"));
};
}
Commands::AddSkew { logfile, outfile } => todo!("Not implemented"),
}
Ok(())
}

View file

@ -6,7 +6,7 @@ mod integrated_test {
};
use anyhow::Result;
use assert_cmd::{assert::OutputAssertExt, Command};
use assert_cmd::Command;
use predicates::prelude::*;
#[test]
@ -42,6 +42,14 @@ mod integrated_test {
.assert()
.success();
// check
let mut cmd = Command::cargo_bin("psb-qaqc")?;
cmd.current_dir("tests")
.arg("check-db")
.arg(test_out.as_path())
.assert()
.success();
Ok(())
}