forked from extern/nushell
histogram gives back percentage column. (#2340)
This commit is contained in:
parent
48cfc9b598
commit
8ff15c46c1
@ -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)
|
||||
|
@ -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>,
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user