1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-19 10:20:08 +01:00

Add Progressbar

Dieser Commit ist enthalten in:
Chaoscaot 2023-03-12 14:13:55 +01:00
Ursprung 3792be48a3
Commit 916613773b
3 geänderte Dateien mit 16 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -15,6 +15,7 @@ clap = { version = "4.1.8", features = ["cargo"] }
futures = { version = "0.3", optional = true } futures = { version = "0.3", optional = true }
sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" , "mysql" ], optional = true } sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls" , "mysql" ], optional = true }
rayon = "1.7.0" rayon = "1.7.0"
indicatif = { version = "0.17.3", features = ["rayon"] }
[features] [features]
sql = ["dep:schemsearch-sql", "dep:futures", "dep:sqlx"] sql = ["dep:schemsearch-sql", "dep:futures", "dep:sqlx"]

Datei anzeigen

@ -36,6 +36,7 @@ use schemsearch_sql::filter::SchematicFilter;
use schemsearch_sql::load_all_schematics; use schemsearch_sql::load_all_schematics;
#[cfg(feature = "sql")] #[cfg(feature = "sql")]
use crate::types::SqlSchematicSupplier; use crate::types::SqlSchematicSupplier;
use indicatif::{ProgressBar, ParallelProgressIterator, ProgressStyle};
fn main() { fn main() {
#[allow(unused_mut)] #[allow(unused_mut)]
@ -256,7 +257,7 @@ fn main() {
} }
ThreadPoolBuilder::new().num_threads(*matches.get_one::<usize>("threads").expect("Could not get threads")).build_global().unwrap(); ThreadPoolBuilder::new().num_threads(*matches.get_one::<usize>("threads").expect("Could not get threads")).build_global().unwrap();
let matches: Vec<Result> = schematics.par_iter().map(|schem| { let matches: Vec<Result> = schematics.par_iter().progress_with_style(ProgressStyle::default_bar()).map(|schem| {
match schem { match schem {
SchematicSupplierType::PATH(schem) => { SchematicSupplierType::PATH(schem) => {
let schematic = match load_schem(&schem.path) { let schematic = match load_schem(&schem.path) {

Datei anzeigen

@ -120,14 +120,14 @@ pub fn parse_schematic(data: &Vec<u8>) -> Schematic {
#[allow(unused_imports)] #[allow(unused_imports)]
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::path::Path; use std::path::{Path, PathBuf};
use schemsearch_files::Schematic; use schemsearch_files::Schematic;
use crate::pattern_mapper::strip_data; use crate::pattern_mapper::strip_data;
use super::*; use super::*;
#[test] #[test]
fn read_schematic() { fn read_schematic() {
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len()); assert_eq!(schematic.width as usize * schematic.height as usize * schematic.length as usize, schematic.block_data.len());
assert_eq!(schematic.palette_max, schematic.palette.len() as i32); assert_eq!(schematic.palette_max, schematic.palette.len() as i32);
} }
@ -142,7 +142,7 @@ mod tests {
#[test] #[test]
fn test_strip_schem() { fn test_strip_schem() {
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let stripped = strip_data(&schematic); let stripped = strip_data(&schematic);
assert_eq!(stripped.palette.keys().any(|k| k.contains('[')), false); assert_eq!(stripped.palette.keys().any(|k| k.contains('[')), false);
@ -150,24 +150,24 @@ mod tests {
#[test] #[test]
fn test_match_palette() { fn test_match_palette() {
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = match_palette(&schematic, &endstone, true); let _ = match_palette(&schematic, &endstone, true);
} }
#[test] #[test]
fn test_match_palette_ignore_data() { fn test_match_palette_ignore_data() {
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = match_palette(&schematic, &endstone, false); let _ = match_palette(&schematic, &endstone, false);
} }
#[test] #[test]
pub fn test_big_search() { pub fn test_big_search() {
let schematic = Schematic::load(Path::new("../tests/simple.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/simple.schem")).unwrap();
let endstone = Schematic::load(Path::new("../tests/endstone.schem")).unwrap(); let endstone = Schematic::load(&PathBuf::from("../tests/endstone.schem")).unwrap();
let _ = search(schematic, &endstone, SearchBehavior { let _ = search(schematic, &endstone, SearchBehavior {
ignore_block_data: true, ignore_block_data: true,
@ -181,8 +181,8 @@ mod tests {
#[test] #[test]
pub fn test_search() { pub fn test_search() {
let schematic = Schematic::load(Path::new("../tests/Random.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/Random.schem")).unwrap();
let pattern = Schematic::load(Path::new("../tests/Pattern.schem")).unwrap(); let pattern = Schematic::load(&PathBuf::from("../tests/Pattern.schem")).unwrap();
let matches = search(schematic, &pattern, SearchBehavior { let matches = search(schematic, &pattern, SearchBehavior {
ignore_block_data: true, ignore_block_data: true,
@ -200,8 +200,8 @@ mod tests {
#[test] #[test]
pub fn test_search_ws() { pub fn test_search_ws() {
let schematic = Schematic::load(Path::new("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap(); let schematic = Schematic::load(&PathBuf::from("../tests/warships/GreyFly-by-Bosslar.schem")).unwrap();
let pattern = Schematic::load(Path::new("../tests/gray_castle_complex.schem")).unwrap(); let pattern = Schematic::load(&PathBuf::from("../tests/gray_castle_complex.schem")).unwrap();
let matches = search(schematic, &pattern, SearchBehavior { let matches = search(schematic, &pattern, SearchBehavior {
ignore_block_data: false, ignore_block_data: false,