mirror of
https://github.com/nushell/nushell.git
synced 2025-04-02 20:27:11 +02:00
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_value(&column.item, column_value);
|
||||||
fact.insert_untagged("count", UntaggedValue::int(count));
|
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("*")
|
let string = std::iter::repeat("*")
|
||||||
.take(value.as_u64().map_err(|_| {
|
.take(value.as_u64().map_err(|_| {
|
||||||
ShellError::labeled_error("expected a number", "expected a number", &name)
|
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.
|
// 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,
|
input: &Value,
|
||||||
tag: impl Into<Tag>,
|
tag: impl Into<Tag>,
|
||||||
digits: Option<u64>,
|
digits: Option<u64>,
|
||||||
|
@ -5,7 +5,7 @@ mod contains;
|
|||||||
mod downcase;
|
mod downcase;
|
||||||
mod ends_with;
|
mod ends_with;
|
||||||
mod find_replace;
|
mod find_replace;
|
||||||
mod from;
|
pub mod from;
|
||||||
mod index_of;
|
mod index_of;
|
||||||
mod length;
|
mod length;
|
||||||
mod reverse;
|
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);
|
assert_eq!(actual.out, bit_json);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user