improve progress bar
This commit is contained in:
		
							
								
								
									
										26
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										26
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -298,6 +298,16 @@ version = "1.0.3" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" | ||||
|  | ||||
| [[package]] | ||||
| name = "colored" | ||||
| version = "2.2.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" | ||||
| dependencies = [ | ||||
|  "lazy_static", | ||||
|  "windows-sys 0.59.0", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "cpufeatures" | ||||
| version = "0.2.17" | ||||
| @@ -759,6 +769,12 @@ dependencies = [ | ||||
|  "wasm-bindgen", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "lazy_static" | ||||
| version = "1.5.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" | ||||
|  | ||||
| [[package]] | ||||
| name = "libc" | ||||
| version = "0.2.172" | ||||
| @@ -1076,6 +1092,15 @@ version = "0.8.5" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" | ||||
|  | ||||
| [[package]] | ||||
| name = "rich_progress_bar" | ||||
| version = "1.1.0" | ||||
| source = "registry+https://github.com/rust-lang/crates.io-index" | ||||
| checksum = "892eca205ea9663141375f828ed5cfc1adbe70b25283ccec0b2f264d7059cb06" | ||||
| dependencies = [ | ||||
|  "colored", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
| name = "rustc-demangle" | ||||
| version = "0.1.24" | ||||
| @@ -1623,6 +1648,7 @@ name = "xtask" | ||||
| version = "0.1.0" | ||||
| dependencies = [ | ||||
|  "rayon", | ||||
|  "rich_progress_bar", | ||||
| ] | ||||
|  | ||||
| [[package]] | ||||
|   | ||||
| @@ -5,3 +5,4 @@ edition = "2024" | ||||
|  | ||||
| [dependencies] | ||||
| rayon = "1.10" | ||||
| rich_progress_bar = "1.1" | ||||
|   | ||||
| @@ -4,11 +4,13 @@ use std::{ | ||||
|     net::TcpStream, | ||||
|     path::{Path, PathBuf}, | ||||
|     process::{Child, Command, Stdio}, | ||||
|     sync::{Mutex, atomic::AtomicUsize}, | ||||
|     thread::sleep, | ||||
|     time::Duration, | ||||
| }; | ||||
|  | ||||
| use rayon::iter::{IntoParallelIterator, ParallelIterator}; | ||||
| use rich_progress_bar::{Colors, RichProgressBar}; | ||||
|  | ||||
| type DynError = Box<dyn std::error::Error>; | ||||
|  | ||||
| @@ -232,6 +234,8 @@ fn regression() -> Result<(), DynError> { | ||||
|         } | ||||
|     }; | ||||
|  | ||||
|     sleep(Duration::from_secs(1)); | ||||
|  | ||||
|     let res = try_regression(); | ||||
|  | ||||
|     snake.kill().and(prod.kill())?; | ||||
| @@ -265,18 +269,25 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { | ||||
|         .build_global() | ||||
|         .unwrap(); | ||||
|  | ||||
|     let mut progress = RichProgressBar::new(); | ||||
|     progress | ||||
|         .set_progress_character('=') | ||||
|         .set_color(Colors::BrightCyan) | ||||
|         .set_total(GAMES as u64); | ||||
|     let progress = Mutex::new(&mut progress); | ||||
|     let stats = (0..GAMES) | ||||
|         .into_par_iter() | ||||
|         .flat_map(|_| { | ||||
|             eprint!("."); | ||||
|             let game = Command::new("./battlesnake-cli") | ||||
|                 .current_dir(project_root()) | ||||
|                 .args([ | ||||
|                     "play", | ||||
|                     "-W", | ||||
|                     "--width", | ||||
|                     "11", | ||||
|                     "-H", | ||||
|                     "--height", | ||||
|                     "11", | ||||
|                     "--timeout", | ||||
|                     "100", | ||||
|                     "--name", | ||||
|                     "local", | ||||
|                     "--url", | ||||
| @@ -290,7 +301,7 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { | ||||
|                 ]) | ||||
|                 .output() | ||||
|                 .ok()?; | ||||
|             if !game.status.success() { | ||||
|             let res = if !game.status.success() { | ||||
|                 eprintln!("game output: {}", String::from_utf8(game.stderr).ok()?); | ||||
|                 eprintln!("game status: {}", game.status); | ||||
|                 None | ||||
| @@ -308,7 +319,11 @@ fn try_regression() -> Result<(usize, usize, usize), DynError> { | ||||
|                 } else { | ||||
|                     Some((0, 1, 0)) | ||||
|                 } | ||||
|             }; | ||||
|             if let Ok(mut progress) = progress.lock() { | ||||
|                 let _ = progress.inc(); | ||||
|             } | ||||
|             res | ||||
|         }) | ||||
|         .reduce( | ||||
|             || (0, 0, 0), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user