from vcf from ics and from ini (#367)

* MathEval Variance and Stddev

* Fix tests and linting

* Typo

* Deal with streams when they are not tables

* `from toml` command

* From ods

* From XLSX

* From ics

* From ini

* From vcf

* Forgot a eprintln!
This commit is contained in:
Luccas Mateus
2021-11-25 14:10:56 -03:00
committed by GitHub
parent 6a1942b18f
commit 8043516d75
11 changed files with 722 additions and 29 deletions

View File

@ -1,6 +1,6 @@
use indexmap::map::IndexMap;
use nu_protocol::ast::Call;
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Span, Value};
use std::collections::HashMap;
use nu_protocol::{IntoPipelineData, PipelineData, ShellError, Span, Spanned, Value};
pub fn run_with_function(
call: &Call,
@ -22,7 +22,7 @@ fn helper_for_tables(
) -> Result<Value, ShellError> {
// If we are not dealing with Primitives, then perhaps we are dealing with a table
// Create a key for each column name
let mut column_values = HashMap::new();
let mut column_values = IndexMap::new();
for val in values {
if let Value::Record { cols, vals, .. } = val {
for (key, value) in cols.iter().zip(vals.iter()) {
@ -37,7 +37,7 @@ fn helper_for_tables(
}
}
// The mathematical function operates over the columns of the table
let mut column_totals = HashMap::new();
let mut column_totals = IndexMap::new();
for (col_name, col_vals) in column_values {
if let Ok(out) = mf(&col_vals, &name) {
column_totals.insert(col_name, out);
@ -49,19 +49,11 @@ fn helper_for_tables(
name,
));
}
let (cols, vals) = column_totals
.into_iter()
.fold((vec![], vec![]), |mut acc, (k, v)| {
acc.0.push(k);
acc.1.push(v);
acc
});
Ok(Value::Record {
cols,
vals,
Ok(Value::from(Spanned {
item: column_totals,
span: name,
})
}))
}
pub fn calculate(