Refactor product creator, remove threading for writing to disk
This commit is contained in:
112
src/main.rs
112
src/main.rs
@@ -66,6 +66,28 @@ enum Commands {
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: Option<PathBuf>,
|
||||
},
|
||||
CreateProducts {
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
definitions: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
encounters: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
services: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
transfers: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
procedures: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
diagnoses: PathBuf,
|
||||
|
||||
#[arg(short, long, value_name = "FILE")]
|
||||
output: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
fn main() -> anyhow::Result<()> {
|
||||
@@ -80,12 +102,12 @@ fn main() -> anyhow::Result<()> {
|
||||
output,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
} => move_money(
|
||||
rules,
|
||||
lines,
|
||||
accounts,
|
||||
cost_centres,
|
||||
output,
|
||||
} => coster_rs::move_money(
|
||||
&mut csv::Reader::from_path(rules)?,
|
||||
&mut csv::Reader::from_path(lines)?,
|
||||
&mut csv::Reader::from_path(accounts)?,
|
||||
&mut csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
),
|
||||
@@ -99,61 +121,35 @@ fn main() -> anyhow::Result<()> {
|
||||
account_type,
|
||||
exclude_negative_allocation_statistics,
|
||||
output,
|
||||
} => allocate_overheads(
|
||||
lines,
|
||||
accounts,
|
||||
allocation_statistics,
|
||||
areas,
|
||||
cost_centres,
|
||||
} => coster_rs::reciprocal_allocation(
|
||||
csv::Reader::from_path(lines)?,
|
||||
csv::Reader::from_path(accounts)?,
|
||||
csv::Reader::from_path(allocation_statistics)?,
|
||||
csv::Reader::from_path(areas)?,
|
||||
csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
account_type,
|
||||
exclude_negative_allocation_statistics,
|
||||
true,
|
||||
account_type,
|
||||
),
|
||||
Commands::CreateProducts {
|
||||
definitions,
|
||||
encounters,
|
||||
services,
|
||||
transfers,
|
||||
procedures,
|
||||
diagnoses,
|
||||
output,
|
||||
} => coster_rs::create_products(
|
||||
&mut csv::Reader::from_path(definitions)?,
|
||||
&mut csv::Reader::from_path(encounters)?,
|
||||
&mut csv::Reader::from_path(services)?,
|
||||
&mut csv::Reader::from_path(transfers)?,
|
||||
&mut csv::Reader::from_path(procedures)?,
|
||||
&mut csv::Reader::from_path(diagnoses)?,
|
||||
&mut csv::Writer::from_path(output)?,
|
||||
1000000,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn move_money(
|
||||
rules: PathBuf,
|
||||
lines: PathBuf,
|
||||
accounts: PathBuf,
|
||||
cost_centres: PathBuf,
|
||||
output: Option<PathBuf>,
|
||||
use_numeric_accounts: bool,
|
||||
flush_pass: bool,
|
||||
) -> anyhow::Result<()> {
|
||||
coster_rs::move_money(
|
||||
&mut csv::Reader::from_path(rules)?,
|
||||
&mut csv::Reader::from_path(lines)?,
|
||||
&mut csv::Reader::from_path(accounts)?,
|
||||
&mut csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
flush_pass,
|
||||
)
|
||||
}
|
||||
|
||||
fn allocate_overheads(
|
||||
lines: PathBuf,
|
||||
accounts: PathBuf,
|
||||
allocation_statistics: PathBuf,
|
||||
areas: PathBuf,
|
||||
cost_centres: PathBuf,
|
||||
use_numeric_accounts: bool,
|
||||
account_type: String,
|
||||
exclude_negative_allocation_statistics: bool,
|
||||
output: Option<PathBuf>,
|
||||
) -> anyhow::Result<()> {
|
||||
coster_rs::reciprocal_allocation(
|
||||
csv::Reader::from_path(lines)?,
|
||||
csv::Reader::from_path(accounts)?,
|
||||
csv::Reader::from_path(allocation_statistics)?,
|
||||
csv::Reader::from_path(areas)?,
|
||||
csv::Reader::from_path(cost_centres)?,
|
||||
&mut csv::Writer::from_path(output.unwrap_or(PathBuf::from("alloc_output.csv")))?,
|
||||
use_numeric_accounts,
|
||||
exclude_negative_allocation_statistics,
|
||||
true,
|
||||
account_type,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user