Add optional messagepack output for overhead allocation to cli
This commit is contained in:
36
src/main.rs
36
src/main.rs
@@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{fs::File, io::BufWriter, path::PathBuf};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
@@ -69,8 +69,11 @@ enum Commands {
|
||||
#[arg(short, long, default_value = "0.00000000000000001")]
|
||||
zero_threshold: f64,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: Option<PathBuf>,
|
||||
#[arg(short, long, value_name = "FILE", default_value = "alloc_output.csv")]
|
||||
output: PathBuf,
|
||||
|
||||
#[arg(short, long)]
|
||||
msgpack_serialisation: bool,
|
||||
},
|
||||
CreateProducts {
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
@@ -129,20 +132,41 @@ fn main() -> anyhow::Result<()> {
|
||||
show_from,
|
||||
zero_threshold,
|
||||
output,
|
||||
} => coster_rs::reciprocal_allocation(
|
||||
msgpack_serialisation,
|
||||
} => {
|
||||
if msgpack_serialisation {
|
||||
let mut file = BufWriter::new(File::create(output)?);
|
||||
coster_rs::reciprocal_allocation(
|
||||
&mut csv::Reader::from_path(lines)?,
|
||||
&mut csv::Reader::from_path(accounts)?,
|
||||
&mut csv::Reader::from_path(allocation_statistics)?,
|
||||
&mut csv::Reader::from_path(areas)?,
|
||||
&mut csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?,
|
||||
&mut rmp_serde::Serializer::new(&mut file),
|
||||
use_numeric_accounts,
|
||||
exclude_negative_allocation_statistics,
|
||||
true,
|
||||
account_type,
|
||||
show_from,
|
||||
zero_threshold,
|
||||
),
|
||||
)
|
||||
} else {
|
||||
coster_rs::reciprocal_allocation(
|
||||
&mut csv::Reader::from_path(lines)?,
|
||||
&mut csv::Reader::from_path(accounts)?,
|
||||
&mut csv::Reader::from_path(allocation_statistics)?,
|
||||
&mut csv::Reader::from_path(areas)?,
|
||||
&mut csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output)?,
|
||||
use_numeric_accounts,
|
||||
exclude_negative_allocation_statistics,
|
||||
true,
|
||||
account_type,
|
||||
show_from,
|
||||
zero_threshold,
|
||||
)
|
||||
}
|
||||
}
|
||||
Commands::CreateProducts {
|
||||
definitions,
|
||||
encounters,
|
||||
|
||||
@@ -780,7 +780,6 @@ impl<W: Write> RecordSerializer for Serializer<W> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::fs::File;
|
||||
|
||||
use crate::reciprocal_allocation;
|
||||
use crate::AccountCost;
|
||||
@@ -789,7 +788,6 @@ mod tests {
|
||||
use crate::TotalDepartmentCost;
|
||||
|
||||
use super::reciprocal_allocation_impl;
|
||||
use super::MovedAmount;
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
|
||||
Reference in New Issue
Block a user