Refactored doprocess

This commit is contained in:
Trey Blancher 2022-11-11 12:38:54 -05:00
parent d86822c40e
commit 914a57692f
4 changed files with 11 additions and 4 deletions

View File

@ -130,7 +130,7 @@ dependencies = [
]
[[package]]
name = "do_process"
name = "doprocess"
version = "0.1.0"
dependencies = [
"itertools",

View File

@ -2,7 +2,7 @@
members = [
"timetracker",
"do_process",
"doprocess",
"chug",
"timelogging"
]

View File

@ -1,5 +1,5 @@
[package]
name = "do_process"
name = "doprocess"
version = "0.1.0"
edition = "2021"

View File

@ -6,6 +6,9 @@ use itertools::Itertools;
use timelogging::timetracking::{nearest, process_input_file, generate_individual_timecards};
fn main() {
// set up a regex for escaping regex characters
let cat_esc = Regex::new(r"(?P<char>[-*^$+?])").unwrap();
// Process the file (stdin or file argument)
let input = env::args().nth(1);
let mut reader: Box<dyn BufRead> = match input {
@ -24,7 +27,10 @@ fn main() {
let mut running_total: f64 = 0.0;
for cat in categories {
let mut subtotal: f64 = 0.0;
let catre = Regex::new(&format!(r"\[{}\]\s+.*\s*$", cat).to_string()).unwrap();
let catre = Regex::new(&format!(r"\[{}\]\s+.*\s*$",
cat_esc.replace_all(&cat, r"\$char".to_string()))
.to_string())
.unwrap();
for (act, duration) in ind.iter().sorted_by_key(|x| x.0) {
if ! catre.is_match(&act.to_string()) {
continue
@ -49,3 +55,4 @@ fn main() {
println!("{}", format!("Grand total: {:.2}", gtoth));
}