Skip to content

Commit

Permalink
count, dedup, extdedup & sniff: replace thousands crate with …
Browse files Browse the repository at this point in the history
…indicatif::Humancount

- also replaced in config.rs for NO_INDEX_WARNING_FILESIZE warning
  • Loading branch information
jqnatividad committed Dec 6, 2023
1 parent 791b14d commit 74549c8
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 29 deletions.
10 changes: 3 additions & 7 deletions src/cmd/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
};

if args.flag_human_readable {
use thousands::Separable;
use indicatif::HumanCount;

if args.flag_width {
woutinfo!(
"{};{}",
count.separate_with_commas(),
width.separate_with_commas()
);
woutinfo!("{};{}", HumanCount(count as u64), HumanCount(width as u64));

Check warning

Code scanning / clippy

casting to the same type is unnecessary (u64 -> u64) Warning

casting to the same type is unnecessary (u64 -> u64)
} else {
woutinfo!("{}", count.separate_with_commas());
woutinfo!("{}", HumanCount(count as u64));

Check warning

Code scanning / clippy

casting to the same type is unnecessary (u64 -> u64) Warning

casting to the same type is unnecessary (u64 -> u64)
}
} else if args.flag_width {
woutinfo!("{count};{width}");
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
}

if args.flag_human_readable {
use thousands::Separable;
use indicatif::HumanCount;

eprintln!("{}", dupe_count.separate_with_commas());
eprintln!("{}", HumanCount(dupe_count as u64));
} else {
eprintln!("{dupe_count}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extdedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use std::{
io::{self, stdin, stdout, BufRead, Write},
};

use indicatif::HumanCount;
use serde::Deserialize;
use sysinfo::{System, SystemExt};
use thousands::Separable;

use crate::{config, odhtcache, util, CliResult};

Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
eprintln!(
"{}",
if args.flag_human_readable {
dupes_count.separate_with_commas()
HumanCount(dupes_count).to_string()
} else {
dupes_count.to_string()
}
Expand Down
22 changes: 9 additions & 13 deletions src/cmd/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ use bytes::Bytes;
use file_format::FileFormat;
use futures::executor::block_on;
use futures_util::StreamExt;
use indicatif::HumanCount;
#[cfg(any(feature = "feature_capable", feature = "lite"))]
use indicatif::{HumanBytes, HumanCount, ProgressBar, ProgressDrawTarget, ProgressStyle};
use indicatif::{HumanBytes, ProgressBar, ProgressDrawTarget, ProgressStyle};
use qsv_sniffer::{DatePreference, SampleSize, Sniffer};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
use tabwriter::TabWriter;
use tempfile::NamedTempFile;
use thousands::Separable;
use url::Url;

use crate::{
Expand Down Expand Up @@ -207,7 +207,7 @@ impl fmt::Display for SniffStruct {
writeln!(
f,
"Preamble Rows: {}",
self.preamble_rows.separate_with_commas()
HumanCount(self.preamble_rows as u64)
)?;
writeln!(f, "Quote Char: {}", self.quote_char)?;
writeln!(f, "Flexible: {}", self.flexible)?;
Expand All @@ -217,30 +217,26 @@ impl fmt::Display for SniffStruct {
writeln!(
f,
"Retrieved Size (bytes): {}",
self.retrieved_size.separate_with_commas()
HumanCount(self.retrieved_size as u64)
)?;
writeln!(
f,
"File Size (bytes): {}",
self.file_size.separate_with_commas()
HumanCount(self.file_size as u64)
)?;
writeln!(
f,
"Sampled Records: {}",
self.sampled_records.separate_with_commas()
HumanCount(self.sampled_records as u64)
)?;
writeln!(f, "Estimated: {}", self.estimated)?;
writeln!(
f,
"Num Records: {}",
self.num_records.separate_with_commas()
)?;
writeln!(f, "Num Records: {}", HumanCount(self.num_records as u64))?;
writeln!(
f,
"Avg Record Len (bytes): {}",
self.avg_record_len.separate_with_commas()
HumanCount(self.avg_record_len as u64)
)?;
writeln!(f, "Num Fields: {}", self.num_fields.separate_with_commas())?;
writeln!(f, "Num Fields: {}", HumanCount(self.num_fields as u64))?;
writeln!(f, "Stats Types: {}", self.stats_types)?;
writeln!(f, "Fields:")?;

Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ impl Config {
fs::File::open(&idx_path_work)?
} else if data_fsize >= NO_INDEX_WARNING_FILESIZE {
// warn user that the CSV file is large and not indexed
use thousands::Separable;
use indicatif::HumanCount;

warn!(
"The {} MB CSV file is larger than the {} MB \
NO_INDEX_WARNING_FILESIZE threshold. Consider creating an \
index file as it will make qsv commands much faster.",
(data_fsize * 100).separate_with_commas(),
(NO_INDEX_WARNING_FILESIZE * 100).separate_with_commas()
HumanCount(data_fsize * 100),
HumanCount(NO_INDEX_WARNING_FILESIZE * 100)
);
return Ok(None);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ fn prop_count_len(
cmd.arg("in.csv");

if human_readable {
use thousands::Separable;
use indicatif::HumanCount;

let got_count: String = wrk.stdout(&mut cmd);
let expected_count_commas = expected_count.separate_with_commas();
let expected_count_commas = HumanCount(expected_count as u64).to_string();

rassert_eq!(got_count, expected_count_commas)
} else {
Expand Down

0 comments on commit 74549c8

Please sign in to comment.