forked from extern/nushell
histogram: rename 'count' column to 'ocurrences'
This commit is contained in:
parent
0db4180cea
commit
dd7ee1808a
@ -127,13 +127,13 @@ pub async fn histogram(
|
|||||||
.table_entries()
|
.table_entries()
|
||||||
.map(move |value| {
|
.map(move |value| {
|
||||||
let values = value.table_entries().cloned().collect::<Vec<_>>();
|
let values = value.table_entries().cloned().collect::<Vec<_>>();
|
||||||
let count = values.len();
|
let ocurrences = values.len();
|
||||||
|
|
||||||
(count, values[count - 1].clone())
|
(ocurrences, values[ocurrences - 1].clone())
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |(count, value)| {
|
.map(move |(ocurrences, value)| {
|
||||||
let mut fact = TaggedDictBuilder::new(&name);
|
let mut fact = TaggedDictBuilder::new(&name);
|
||||||
let column_value = labels
|
let column_value = labels
|
||||||
.get(idx)
|
.get(idx)
|
||||||
@ -147,7 +147,7 @@ pub async fn histogram(
|
|||||||
.clone();
|
.clone();
|
||||||
|
|
||||||
fact.insert_value(&column.item, column_value);
|
fact.insert_value(&column.item, column_value);
|
||||||
fact.insert_untagged("count", UntaggedValue::int(count));
|
fact.insert_untagged("ocurrences", UntaggedValue::int(ocurrences));
|
||||||
|
|
||||||
let percentage = format!(
|
let percentage = format!(
|
||||||
"{}%",
|
"{}%",
|
||||||
|
@ -54,7 +54,7 @@ fn summarizes_by_values() {
|
|||||||
| get rusty_at
|
| get rusty_at
|
||||||
| histogram
|
| histogram
|
||||||
| where value == "Estados Unidos"
|
| where value == "Estados Unidos"
|
||||||
| get count
|
| get ocurrences
|
||||||
| echo $it
|
| echo $it
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
@ -93,20 +93,20 @@ fn help() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn count() {
|
fn ocurrences() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
echo "[{"bit":1},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":1}]"
|
echo "[{"bit":1},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":0},{"bit":1}]"
|
||||||
| from json
|
| from json
|
||||||
| histogram bit
|
| histogram bit
|
||||||
| sort-by count
|
| sort-by ocurrences
|
||||||
| reject frequency
|
| reject frequency
|
||||||
| to json
|
| to json
|
||||||
"#
|
"#
|
||||||
));
|
));
|
||||||
|
|
||||||
let bit_json = r#"[{"bit":"1","count":2,"percentage":"33.33%"},{"bit":"0","count":6,"percentage":"100.00%"}]"#;
|
let bit_json = r#"[{"bit":"1","ocurrences":2,"percentage":"33.33%"},{"bit":"0","ocurrences":6,"percentage":"100.00%"}]"#;
|
||||||
|
|
||||||
assert_eq!(actual.out, bit_json);
|
assert_eq!(actual.out, bit_json);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user