Add optional messagepack output for overhead allocation to cli

This commit is contained in:
Piv
2023-03-17 18:57:47 +10:30
parent 7949a0a07b
commit 87fa169d0c
2 changed files with 41 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
use std::path::PathBuf; use std::{fs::File, io::BufWriter, path::PathBuf};
use clap::{Parser, Subcommand}; use clap::{Parser, Subcommand};
@@ -69,8 +69,11 @@ enum Commands {
#[arg(short, long, default_value = "0.00000000000000001")] #[arg(short, long, default_value = "0.00000000000000001")]
zero_threshold: f64, zero_threshold: f64,
#[arg(short, long, value_name = "FILE")] #[arg(short, long, value_name = "FILE", default_value = "alloc_output.csv")]
output: Option<PathBuf>, output: PathBuf,
#[arg(short, long)]
msgpack_serialisation: bool,
}, },
CreateProducts { CreateProducts {
#[arg(short, long, value_name = "FILE")] #[arg(short, long, value_name = "FILE")]
@@ -129,20 +132,41 @@ fn main() -> anyhow::Result<()> {
show_from, show_from,
zero_threshold, zero_threshold,
output, 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(lines)?,
&mut csv::Reader::from_path(accounts)?, &mut csv::Reader::from_path(accounts)?,
&mut csv::Reader::from_path(allocation_statistics)?, &mut csv::Reader::from_path(allocation_statistics)?,
&mut csv::Reader::from_path(areas)?, &mut csv::Reader::from_path(areas)?,
&mut csv::Reader::from_path(cost_centres)?, &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, use_numeric_accounts,
exclude_negative_allocation_statistics, exclude_negative_allocation_statistics,
true, true,
account_type, account_type,
show_from, show_from,
zero_threshold, 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 { Commands::CreateProducts {
definitions, definitions,
encounters, encounters,

View File

@@ -780,7 +780,6 @@ impl<W: Write> RecordSerializer for Serializer<W> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::fs::File;
use crate::reciprocal_allocation; use crate::reciprocal_allocation;
use crate::AccountCost; use crate::AccountCost;
@@ -789,7 +788,6 @@ mod tests {
use crate::TotalDepartmentCost; use crate::TotalDepartmentCost;
use super::reciprocal_allocation_impl; use super::reciprocal_allocation_impl;
use super::MovedAmount;
#[test] #[test]
fn test_basic() { fn test_basic() {