histogram gives back percentage column. (#2340)

This commit is contained in:
Andrés N. Robalino 2020-08-12 04:21:28 -05:00 committed by GitHub
parent 48cfc9b598
commit 8ff15c46c1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View file

@ -130,6 +130,15 @@ pub async fn histogram(
fact.insert_value(&column.item, column_value);
fact.insert_untagged("count", UntaggedValue::int(count));
let percentage = format!(
"{}%",
// Some(2) < the number of digits
// true < group the digits
crate::commands::str_::from::action(&value, &name, Some(2), true)?
.as_string()?
);
fact.insert_untagged("percentage", UntaggedValue::string(percentage));
let string = std::iter::repeat("*")
.take(value.as_u64().map_err(|_| {
ShellError::labeled_error("expected a number", "expected a number", &name)

View file

@ -112,7 +112,7 @@ async fn operate(
}
// TODO If you're using the with-system-locale feature and you're on Windows, Clang 3.9 or higher is also required.
fn action(
pub fn action(
input: &Value,
tag: impl Into<Tag>,
digits: Option<u64>,

View file

@ -5,7 +5,7 @@ mod contains;
mod downcase;
mod ends_with;
mod find_replace;
mod from;
pub mod from;
mod index_of;
mod length;
mod reverse;

View file

@ -106,7 +106,7 @@ fn count() {
"#
));
let bit_json = r#"[{"bit":"1","count":2},{"bit":"0","count":6}]"#;
let bit_json = r#"[{"bit":"1","count":2,"percentage":"33.33%"},{"bit":"0","count":6,"percentage":"100.00%"}]"#;
assert_eq!(actual.out, bit_json);
}