mirror of
https://github.com/nushell/nushell
synced 2024-11-15 09:27:08 +00:00
histogram gives back percentage column. (#2340)
This commit is contained in:
parent
48cfc9b598
commit
8ff15c46c1
4 changed files with 12 additions and 3 deletions
|
@ -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 a new issue