From 887e7c950bd69ac9e7dc510320bf4233ae97d5d8 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Thu, 9 Mar 2023 18:58:54 +1030 Subject: [PATCH] Remove smush rules, fix warnings --- src/create_products.rs | 1 - src/lib.rs | 9 ++++----- src/main.rs | 33 +++++---------------------------- src/move_money.rs | 30 +++++++++--------------------- src/overhead_allocation.rs | 12 +++++------- src/smush_rules.rs | 22 ---------------------- 6 files changed, 23 insertions(+), 84 deletions(-) delete mode 100644 src/smush_rules.rs diff --git a/src/create_products.rs b/src/create_products.rs index a88493c..192f6b4 100644 --- a/src/create_products.rs +++ b/src/create_products.rs @@ -8,7 +8,6 @@ use std::{ use chrono::NaiveDateTime; use csv::Position; -use itertools::Itertools; use serde::Serialize; #[derive(Hash, PartialEq, PartialOrd, Ord, Eq)] diff --git a/src/lib.rs b/src/lib.rs index 488ada4..e0e301e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,6 @@ use std::ffi::CString; pub use self::move_money::*; -mod smush_rules; -pub use self::smush_rules::*; - mod overhead_allocation; pub use self::overhead_allocation::*; @@ -50,7 +47,8 @@ pub extern "C" fn move_money_from_text( &mut output_writer, use_numeric_accounts, true, - ); + ) + .expect("Failed to move money"); // TODO: Replace all these unwraps with something more elegant let inner = output_writer.into_inner().unwrap(); CString::new(String::from_utf8(inner).unwrap()) @@ -119,7 +117,8 @@ pub extern "C" fn allocate_overheads_from_text( false, true, account_type.to_str().unwrap().to_owned(), - ); + ) + .expect("Failed to allocate overheads"); let inner = output_writer.into_inner().unwrap(); CString::new(String::from_utf8(inner).unwrap()) .unwrap() diff --git a/src/main.rs b/src/main.rs index 5a8c90e..698bf8c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,6 @@ -use std::{collections::HashMap, error::Error, io::Write, path::PathBuf}; +use std::path::PathBuf; use clap::{Parser, Subcommand}; -use coster_rs::CsvCost; -use serde::Deserialize; #[derive(Parser)] #[command(name = "coster-rs")] @@ -17,7 +15,7 @@ struct Cli { #[derive(Subcommand)] enum Commands { /// Moves money between accounts and departments, using the given rules and lines - move_money { + MoveMoney { #[arg(short = 'r', long, value_name = "FILE")] rules: PathBuf, @@ -39,16 +37,8 @@ enum Commands { #[arg(short, long)] flush_pass: bool, }, - /// Combines rules to the minimum set required - smush_rules { - #[arg(short = 'r', long, value_name = "FILE")] - rules: PathBuf, - - #[arg(short, long, value_name = "FILE")] - output: Option, - }, /// Allocates servicing department amounts to operating departments - allocate_overheads { + AllocateOverheads { #[arg(short, long, value_name = "FILE")] lines: PathBuf, @@ -79,7 +69,7 @@ fn main() -> anyhow::Result<()> { let cli = Cli::parse(); match cli.command { - Commands::move_money { + Commands::MoveMoney { rules, lines, accounts, @@ -96,8 +86,7 @@ fn main() -> anyhow::Result<()> { use_numeric_accounts, flush_pass, ), - Commands::smush_rules { rules, output } => smush_rules(rules, output), - Commands::allocate_overheads { + Commands::AllocateOverheads { lines, accounts, allocation_statistics, @@ -139,10 +128,6 @@ fn move_money( ) } -fn smush_rules(rules_path: PathBuf, output: Option) -> anyhow::Result<()> { - Ok(()) -} - fn allocate_overheads( lines: PathBuf, accounts: PathBuf, @@ -166,11 +151,3 @@ fn allocate_overheads( account_type, ) } - -#[derive(Debug, Deserialize)] -struct CsvOverheadAllocationRule { - from_overhead_department: String, - to_department: String, - percent: f64, - to_department_type: String, -} diff --git a/src/move_money.rs b/src/move_money.rs index e81ac82..06d9c4c 100644 --- a/src/move_money.rs +++ b/src/move_money.rs @@ -1,7 +1,4 @@ -use std::{ - collections::{HashMap, HashSet}, - thread::current, -}; +use std::collections::{HashMap, HashSet}; use itertools::Itertools; use serde::{Deserialize, Serialize, Serializer}; @@ -26,15 +23,6 @@ struct CsvMovementRule { dest_from_account: String, #[serde(rename = "AccountDestTo", default)] dest_to_account: String, - // TODO: Check how these actually work, they're somehow integrated into other columns - #[serde(default)] - all_from_departments: bool, - #[serde(default)] - all_to_departments: bool, - #[serde(default)] - all_from_accounts: bool, - #[serde(default)] - all_to_accounts: bool, #[serde(rename = "AmountValue")] amount: Option, #[serde(rename = "AmountType", default)] @@ -166,7 +154,7 @@ where ) }) .collect(); - let mut accounts_reader = accounts_reader; + let accounts_reader = accounts_reader; let all_accounts = accounts_reader .deserialize() .collect::, csv::Error>>()?; @@ -203,7 +191,6 @@ where .unique() .sorted() .collect(); - let mut rules_reader = rules_reader; let mut rules: Vec = vec![]; for movement_rule in rules_reader.deserialize() { // TODO: Consider reclass rule group, how does that even work? @@ -375,10 +362,10 @@ pub fn move_money_2( // to add a new line let mut running_total = HashMap::from(initial_totals); let mut temp_total = running_total.clone(); - let mut moveMoneyResult: Vec = vec![]; + let mut move_money_result: Vec = vec![]; let mut current_pass = 0; if flush_pass { - moveMoneyResult.push(MoveMoneyResult { + move_money_result.push(MoveMoneyResult { pass: current_pass, totals: running_total.clone(), }) @@ -388,7 +375,7 @@ pub fn move_money_2( if flush_pass { current_pass += 1; // Flush the totals at the end of this pass (more specifically the change) - moveMoneyResult.push(MoveMoneyResult { + move_money_result.push(MoveMoneyResult { pass: current_pass, totals: temp_total .iter() @@ -433,12 +420,12 @@ pub fn move_money_2( } } } - moveMoneyResult.push(MoveMoneyResult { + move_money_result.push(MoveMoneyResult { pass: current_pass, totals: temp_total, }); - moveMoneyResult + move_money_result } #[cfg(test)] @@ -453,6 +440,7 @@ mod tests { &mut csv::Writer::from_path("output.csv").unwrap(), false, true, - ); + ) + .unwrap(); } } diff --git a/src/overhead_allocation.rs b/src/overhead_allocation.rs index 1930011..26ee9a7 100644 --- a/src/overhead_allocation.rs +++ b/src/overhead_allocation.rs @@ -1,4 +1,7 @@ -use std::{collections::{HashMap, HashSet}, io::Read, path::Path}; +use std::{ + collections::{HashMap, HashSet}, + io::Read, +}; use itertools::Itertools; use nalgebra::{DMatrix, Dynamic, LU}; @@ -26,8 +29,6 @@ impl DepartmentType { pub struct CsvAllocationStatistic { #[serde(rename = "Name")] name: String, - #[serde(rename = "Description")] - description: Option, #[serde(rename = "AccountType")] account_type: String, #[serde(rename = "AccountRanges")] @@ -39,8 +40,6 @@ pub struct AllocationStatisticAccountRange { end: usize, } -type CsvArea = HashMap; - // Note: remember these are overhead departments only when calculating the lu decomposition or pseudoinverse, and for each department, // you either need -1 or rest negative for a row to subtract the initial amounts so we end up effectively 0 (simultaneous equations end // up with negative there so yes this is expected) @@ -247,7 +246,7 @@ where if current_area_ccs.is_none() { continue; } - let mut current_area_ccs = current_area_ccs.unwrap().clone(); + let current_area_ccs = current_area_ccs.unwrap().clone(); for cc in current_area_ccs { overhead_ccs.insert(cc); @@ -592,7 +591,6 @@ fn do_solve_reciprocal( mod tests { use crate::reciprocal_allocation; use crate::AccountCost; - use crate::CsvCost; use crate::DepartmentType; use crate::OverheadAllocationRule; use crate::TotalDepartmentCost; diff --git a/src/smush_rules.rs b/src/smush_rules.rs deleted file mode 100644 index 7283888..0000000 --- a/src/smush_rules.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Rules get parsed from file, converted into matrix format (for the in-memory movement), -// then combined (smushed) into a single matrix + vector/rule for each . The list of units can then have the rules applied -// -// For now just ignore the all from/to stuff, it's kind of a shit thing to do, and can -// be worked around by actually inputting every type into the rules - -use std::collections::HashMap; - -use crate::MovementRule; - -pub fn smush_rules(rules: Vec) -> Vec { - let ruleMapping: HashMap = HashMap::new(); - // First build out the list/map of all departments (store index of each element in the array) - // TODO: We could make this more advanced by only smushing per divider, so that only the departments - // needed between each pass is actually required - for rule in rules { - for department in rule.from_departments { - // ruleMapping.entry(department).or_insert(ruleMapping.len()); - } - } - vec![] -}