mirror of
https://gitlab.cern.ch/wotsubo/psboard-qaqc-postprocess.git
synced 2024-11-24 16:11:11 +09:00
new: implement till parsing file (no output)
This commit is contained in:
parent
474f2397c6
commit
a14eb4ea48
7 changed files with 604 additions and 24 deletions
264
Cargo.lock
generated
264
Cargo.lock
generated
|
@ -81,12 +81,59 @@ version = "1.0.86"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "2.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
"predicates",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "assert_fs"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2cd762e110c8ed629b11b6cde59458cc1c71de78ebbcc30099fc8e0403a2a2ec"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"doc-comment",
|
||||
"globwalk",
|
||||
"predicates",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"tempfile",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
|
@ -182,6 +229,43 @@ version = "0.8.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-deque"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
|
||||
dependencies = [
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
|
||||
dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "env_filter"
|
||||
version = "0.1.0"
|
||||
|
@ -205,6 +289,55 @@ dependencies = [
|
|||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a"
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "globset"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"bstr",
|
||||
"log",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "globwalk"
|
||||
version = "0.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"ignore",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
|
@ -240,6 +373,22 @@ dependencies = [
|
|||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ignore"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1"
|
||||
dependencies = [
|
||||
"crossbeam-deque",
|
||||
"globset",
|
||||
"log",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"same-file",
|
||||
"walkdir",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.0"
|
||||
|
@ -261,6 +410,12 @@ version = "0.2.155"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.22"
|
||||
|
@ -273,6 +428,12 @@ version = "2.7.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
|
@ -288,6 +449,36 @@ version = "1.19.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
"normalize-line-endings",
|
||||
"predicates-core",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.86"
|
||||
|
@ -298,16 +489,19 @@ dependencies = [
|
|||
]
|
||||
|
||||
[[package]]
|
||||
name = "psb-qaqc"
|
||||
name = "psb-qaqc-parse"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"assert_fs",
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap-verbosity-flag",
|
||||
"clap_derive",
|
||||
"env_logger",
|
||||
"log",
|
||||
"predicates",
|
||||
"regex",
|
||||
"semver",
|
||||
]
|
||||
|
@ -350,6 +544,28 @@ version = "0.8.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.23"
|
||||
|
@ -393,6 +609,24 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"fastrand",
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
@ -405,6 +639,25 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
|
||||
dependencies = [
|
||||
"same-file",
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.92"
|
||||
|
@ -459,6 +712,15 @@ version = "0.2.92"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-core"
|
||||
version = "0.52.0"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "psb-qaqc"
|
||||
name = "psb-qaqc-parse"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
|
@ -13,3 +13,8 @@ anyhow = "1.0"
|
|||
chrono = { version = "0.4", features = ["serde"] }
|
||||
semver = "1.0"
|
||||
regex = "1.10"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0"
|
||||
assert_fs = "1.1"
|
||||
predicates = "3.1"
|
||||
|
|
23
README.md
Normal file
23
README.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
# psb_qaqc
|
||||
|
||||
## For developers
|
||||
### build / run
|
||||
```sh
|
||||
cargo build
|
||||
cargo run -- -h
|
||||
```
|
||||
|
||||
### test
|
||||
```sh
|
||||
cargo test
|
||||
```
|
||||
|
||||
### doc
|
||||
```sh
|
||||
cargo doc --open
|
||||
```
|
||||
|
||||
## TODO
|
||||
- test for various cases
|
||||
- skew measurement?
|
||||
- rename bin/project
|
205
src/main.rs
205
src/main.rs
|
@ -1,10 +1,11 @@
|
|||
use core::str;
|
||||
use core::{panic, str};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env,
|
||||
fmt::Display,
|
||||
fs::File,
|
||||
io::{BufRead, BufReader},
|
||||
path,
|
||||
io::{BufRead, BufReader, Write},
|
||||
path::{self, PathBuf},
|
||||
str::FromStr,
|
||||
};
|
||||
|
||||
|
@ -15,12 +16,26 @@ use log::{debug, error, info, trace, warn};
|
|||
use regex::Regex;
|
||||
use semver::Version;
|
||||
|
||||
fn get_default_output_path() -> PathBuf {
|
||||
PathBuf::from_str("outpu.csv").expect("Error")
|
||||
}
|
||||
fn get_default_log_path() -> PathBuf {
|
||||
let mut path = env::current_exe().unwrap();
|
||||
path.pop();
|
||||
path.push("log");
|
||||
path.push("debug.log");
|
||||
path
|
||||
}
|
||||
|
||||
/// Parse master jathub logfile for PS Board QAQC and write out to CSV.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Master log file.
|
||||
master_log: path::PathBuf,
|
||||
/// Output CSV file.
|
||||
// #[arg(default_value = get_default_log_path().into_os_string())]
|
||||
outfile: PathBuf,
|
||||
#[command(flatten)]
|
||||
verbose: clap_verbosity_flag::Verbosity,
|
||||
}
|
||||
|
@ -99,14 +114,14 @@ impl FromStr for Position {
|
|||
}
|
||||
|
||||
/// PSB ID printed on the tape on the board.
|
||||
#[derive(Debug, PartialEq)]
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
struct PsbId {
|
||||
id: u8,
|
||||
id: u32,
|
||||
}
|
||||
|
||||
impl PsbId {
|
||||
/// Without validation.
|
||||
pub fn new(id: u8) -> Self {
|
||||
pub fn new(id: u32) -> Self {
|
||||
PsbId { id }
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +130,10 @@ impl FromStr for PsbId {
|
|||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
|
||||
let num: u8 = s.parse()?;
|
||||
if !s.starts_with("PB") {
|
||||
return Err(anyhow!("Must prefixed with PB: {}", s));
|
||||
}
|
||||
let num = s[2..].parse()?;
|
||||
// TODO: add validation
|
||||
warn!("No validation implemented");
|
||||
Ok(PsbId::new(num))
|
||||
|
@ -123,24 +141,26 @@ impl FromStr for PsbId {
|
|||
}
|
||||
|
||||
/// QAQC results for each boards extracted from master log.
|
||||
///
|
||||
/// Temporary stores raw values.
|
||||
/// TODO: specify each filed types.(maybe multi values)
|
||||
#[derive(Debug)]
|
||||
struct BoardResult {
|
||||
id: PsbId,
|
||||
qspif: bool,
|
||||
qspip: bool,
|
||||
recov: bool,
|
||||
clock: bool,
|
||||
regac: bool,
|
||||
asdtp: bool,
|
||||
done: bool,
|
||||
qspif: u8,
|
||||
qspip: u8,
|
||||
recov: u8,
|
||||
clock: u8,
|
||||
regac: u8,
|
||||
asdtp: u8,
|
||||
done: u8,
|
||||
}
|
||||
|
||||
/// Full result for a single QAQC run from a log file on JATHub master.
|
||||
#[derive(Debug)]
|
||||
struct MasterLogResult {
|
||||
version: Version,
|
||||
datetime: DateTime<Local>,
|
||||
datetime: DateTime<Utc>,
|
||||
shifter: String,
|
||||
board_results: HashMap<Position, BoardResult>,
|
||||
}
|
||||
|
@ -210,7 +230,8 @@ impl MasterLogResult {
|
|||
}
|
||||
|
||||
let mut assignments = HashMap::new();
|
||||
for i in 0..18 {
|
||||
// till 19 for `===========`
|
||||
for i in 0..19 {
|
||||
let line = lines.next().context("Unexpected EOF")??;
|
||||
if line.starts_with("=========") {
|
||||
debug!("End of assignments");
|
||||
|
@ -232,10 +253,136 @@ impl MasterLogResult {
|
|||
trace!("Read all PBS assignments");
|
||||
info!("{:?}", assignments);
|
||||
|
||||
if !lines
|
||||
.next()
|
||||
.context("Invalid log format")??
|
||||
.contains("QAQC status")
|
||||
{
|
||||
info!("{:?}", lines.next());
|
||||
return Err(anyhow!("Invalid log format(result table header)"));
|
||||
}
|
||||
let _sep = lines
|
||||
.next()
|
||||
.context("Invalid log format(result table separator)")??;
|
||||
|
||||
if !lines
|
||||
.next()
|
||||
.context("Invalid log format")??
|
||||
.contains("Station0")
|
||||
{
|
||||
return Err(anyhow!("Invalid log format(result Station0)"));
|
||||
}
|
||||
|
||||
let mut board_results = HashMap::new();
|
||||
for station_minor in [0, 1] {
|
||||
info!("Result for {:?}", station_minor);
|
||||
for _ in 1..10 {
|
||||
let line = lines.next().context("Invalid log format(result body)")??;
|
||||
if line.contains("Station1") || line.contains("======") {
|
||||
break;
|
||||
}
|
||||
let parts: Vec<&str> = line.split('|').collect();
|
||||
let first = parts.first().context("No col 1")?;
|
||||
let raw_station_id = {
|
||||
let re = Regex::new(r"JATHub_( ?\d*)$")?;
|
||||
re.captures(first).map(|v| {
|
||||
v.get(1)
|
||||
.unwrap()
|
||||
.as_str()
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.unwrap()
|
||||
.parse::<u8>()
|
||||
})
|
||||
}
|
||||
.context("Invalid station format")??;
|
||||
let station_id = match station_minor {
|
||||
0 => raw_station_id,
|
||||
1 => raw_station_id - 10,
|
||||
_ => panic!("Unexpected"),
|
||||
};
|
||||
trace!("Row {} {:?}", station_id, parts);
|
||||
if parts.len() != 9 {
|
||||
return Err(anyhow!(
|
||||
"Invalid number of results(expected: 9, detected: {})",
|
||||
parts.len()
|
||||
));
|
||||
}
|
||||
|
||||
// Origin is different (-1)
|
||||
let pos = Position {
|
||||
major: PositionLayer::A,
|
||||
minor: station_minor,
|
||||
patch: station_id - 1,
|
||||
};
|
||||
debug!("pos from table {}", pos);
|
||||
|
||||
let psbid = assignments
|
||||
.get(&pos)
|
||||
.context(format!("No board on pos {}", pos))?
|
||||
.clone();
|
||||
|
||||
let result = BoardResult {
|
||||
id: psbid,
|
||||
qspif: parts
|
||||
.get(1)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid qspif")??,
|
||||
qspip: parts
|
||||
.get(2)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid qspip")??,
|
||||
recov: parts
|
||||
.get(3)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid recov")??,
|
||||
clock: parts
|
||||
.get(4)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid clock")??,
|
||||
regac: parts
|
||||
.get(5)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid regac")??,
|
||||
asdtp: parts
|
||||
.get(6)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid asdtp")??,
|
||||
done: parts
|
||||
.get(7)
|
||||
.map(|v| v.split_whitespace().next().unwrap().parse())
|
||||
.context("Invalid done")??,
|
||||
};
|
||||
|
||||
match board_results.insert(pos, result) {
|
||||
None => (),
|
||||
Some(v) => {
|
||||
panic!("Unexpected value already exists: {:?}", v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
debug!("{:#?}", board_results);
|
||||
|
||||
Ok(MasterLogResult {
|
||||
version,
|
||||
datetime,
|
||||
shifter,
|
||||
board_results,
|
||||
})
|
||||
}
|
||||
|
||||
fn write(&self, f: impl Write) -> Result<()> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn check_csv_header(f: impl BufRead) -> Result<()> {
|
||||
// f.lines()
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let args = Args::parse();
|
||||
env_logger::Builder::new()
|
||||
|
@ -244,10 +391,24 @@ fn main() -> Result<()> {
|
|||
debug!("Args: {:?}", args);
|
||||
println!("Hello, world!");
|
||||
|
||||
let file = File::open(args.master_log)?;
|
||||
let mut reader = BufReader::new(file);
|
||||
let result = MasterLogResult::parse_file(reader)?;
|
||||
debug!(
|
||||
"{:?}",
|
||||
" 1".split_whitespace().next().unwrap().parse::<u8>()
|
||||
);
|
||||
|
||||
let result = {
|
||||
let file = File::open(args.master_log)?;
|
||||
let reader = BufReader::new(file);
|
||||
MasterLogResult::parse_file(reader)?
|
||||
};
|
||||
debug!("{:?}", result);
|
||||
|
||||
// {
|
||||
// let file = File::options()
|
||||
// .read(true)
|
||||
// .open(args.outfile)?;
|
||||
// }
|
||||
//
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -305,7 +466,7 @@ mod test {
|
|||
#[test]
|
||||
fn parse_pos_id_line() {
|
||||
assert_eq!(
|
||||
extract_position_id("Position / assigned-ID : A-0-0 / 000004").unwrap(),
|
||||
extract_position_id("Position / assigned-ID : A-0-0 / PB0004").unwrap(),
|
||||
(
|
||||
Position {
|
||||
major: PositionLayer::A,
|
||||
|
@ -316,7 +477,7 @@ mod test {
|
|||
)
|
||||
);
|
||||
assert_eq!(
|
||||
extract_position_id("Position / assigned-ID : A-1-7 / 000108").unwrap(),
|
||||
extract_position_id("Position / assigned-ID : A-1-7 / PB0108").unwrap(),
|
||||
(
|
||||
Position {
|
||||
major: PositionLayer::A,
|
||||
|
@ -327,7 +488,7 @@ mod test {
|
|||
)
|
||||
);
|
||||
assert_ne!(
|
||||
extract_position_id("Position / assigned-ID : A-1-7 / 000108").unwrap(),
|
||||
extract_position_id("Position / assigned-ID : A-1-7 / PB0108").unwrap(),
|
||||
(
|
||||
Position {
|
||||
major: PositionLayer::A,
|
||||
|
|
41
tests/cli.rs
Normal file
41
tests/cli.rs
Normal file
|
@ -0,0 +1,41 @@
|
|||
mod integrated_test {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use anyhow::Result;
|
||||
use assert_cmd::{assert::OutputAssertExt, Command};
|
||||
use predicates::prelude::*;
|
||||
|
||||
#[test]
|
||||
fn full_log() -> Result<()> {
|
||||
let test_out_dir = assert_fs::TempDir::new()?;
|
||||
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
||||
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
||||
cmd.current_dir("tests")
|
||||
.arg("./example_logs/valid/20240620_083537.log")
|
||||
.arg(test_out.as_path())
|
||||
.assert()
|
||||
.success();
|
||||
// .failure()
|
||||
// .stderr(predicate::str::contains("not yet implemented"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn partial_log() -> Result<()> {
|
||||
let test_out_dir = assert_fs::TempDir::new()?;
|
||||
let test_out = PathBuf::new().join(&test_out_dir).join("out.csv");
|
||||
|
||||
let mut cmd = Command::cargo_bin("psb-qaqc-parse")?;
|
||||
cmd.current_dir("tests")
|
||||
.arg("./example_logs/valid/20240620_093537.log")
|
||||
.arg(test_out.as_path())
|
||||
.assert()
|
||||
.success();
|
||||
// .failure()
|
||||
// .stderr(predicate::str::contains("not yet implemented"));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
48
tests/example_logs/valid/20240620_083537.log
Normal file
48
tests/example_logs/valid/20240620_083537.log
Normal file
|
@ -0,0 +1,48 @@
|
|||
Shift script: 0.0.0
|
||||
----------------------
|
||||
Date: 2024-06-20T08:42:01+0000
|
||||
Shifters: Alice
|
||||
----------------------
|
||||
PBS Assignment:
|
||||
Position / assigned-ID : A-0-0 / PB0004
|
||||
Position / assigned-ID : A-1-0 / PB0004
|
||||
Position / assigned-ID : A-0-1 / PB0004
|
||||
Position / assigned-ID : A-1-1 / PB0004
|
||||
Position / assigned-ID : A-0-2 / PB0004
|
||||
Position / assigned-ID : A-1-2 / PB0004
|
||||
Position / assigned-ID : A-0-3 / PB0004
|
||||
Position / assigned-ID : A-1-3 / PB0004
|
||||
Position / assigned-ID : A-0-4 / PB0004
|
||||
Position / assigned-ID : A-1-4 / PB0004
|
||||
Position / assigned-ID : A-0-5 / PB0004
|
||||
Position / assigned-ID : A-1-5 / PB0004
|
||||
Position / assigned-ID : A-0-6 / PB0004
|
||||
Position / assigned-ID : A-1-6 / PB0004
|
||||
Position / assigned-ID : A-0-7 / PB0004
|
||||
Position / assigned-ID : A-1-7 / PB0004
|
||||
Position / assigned-ID : A-0-8 / PB0004
|
||||
Position / assigned-ID : A-1-8 / PB0004
|
||||
======================
|
||||
QAQC status| QSPIf | QSPIp | Recov | Clock | RegAc | ASDTP | DONE |
|
||||
-----------------------------------------------------------------------
|
||||
Station0
|
||||
JATHub_ 1| 0| 1| 1| 0| 1| 1| 1|
|
||||
JATHub_ 2| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 3| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 4| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 5| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 6| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 7| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 8| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 9| 0| 0| 1| 0| 1| 1| 1|
|
||||
Station1
|
||||
JATHub_11| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_12| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_13| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_14| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_15| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_16| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_17| 0| 0| 1| 1| 1| 2| 1|
|
||||
JATHub_18| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_19| 0| 0| 0| 0| 0| 0| 0|
|
||||
======================
|
40
tests/example_logs/valid/20240620_093537.log
Normal file
40
tests/example_logs/valid/20240620_093537.log
Normal file
|
@ -0,0 +1,40 @@
|
|||
Shift script: 0.0.0
|
||||
----------------------
|
||||
Date: 2024-06-20T09:42:01+0000
|
||||
Shifters: Alice
|
||||
----------------------
|
||||
PBS Assignment:
|
||||
Position / assigned-ID : A-0-0 / PB0004
|
||||
Position / assigned-ID : A-1-0 / PB0004
|
||||
Position / assigned-ID : A-0-1 / PB0004
|
||||
Position / assigned-ID : A-1-1 / PB0004
|
||||
Position / assigned-ID : A-0-4 / PB0004
|
||||
Position / assigned-ID : A-1-4 / PB0004
|
||||
Position / assigned-ID : A-0-5 / PB0004
|
||||
Position / assigned-ID : A-1-5 / PB0004
|
||||
Position / assigned-ID : A-0-6 / PB0004
|
||||
Position / assigned-ID : A-1-6 / PB0004
|
||||
Position / assigned-ID : A-0-7 / PB0004
|
||||
Position / assigned-ID : A-1-7 / PB0004
|
||||
Position / assigned-ID : A-0-8 / PB0004
|
||||
Position / assigned-ID : A-1-8 / PB0004
|
||||
======================
|
||||
QAQC status| QSPIf | QSPIp | Recov | Clock | RegAc | ASDTP | DONE |
|
||||
-----------------------------------------------------------------------
|
||||
Station0
|
||||
JATHub_ 1| 0| 1| 1| 0| 1| 1| 1|
|
||||
JATHub_ 2| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 5| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 6| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 7| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 8| 0| 0| 1| 0| 1| 1| 1|
|
||||
JATHub_ 9| 0| 0| 1| 0| 1| 1| 1|
|
||||
Station1
|
||||
JATHub_11| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_12| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_15| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_16| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_17| 0| 0| 1| 1| 1| 2| 1|
|
||||
JATHub_18| 0| 0| 1| 1| 1| 1| 1|
|
||||
JATHub_19| 0| 0| 0| 0| 0| 0| 0|
|
||||
======================
|
Loading…
Reference in a new issue