From 1168ca46db1e0e8020ac25f1eae2cc9170a914c8 Mon Sep 17 00:00:00 2001 From: Piv <18462828+Piv200@users.noreply.github.com> Date: Wed, 1 Feb 2023 08:27:05 +1030 Subject: [PATCH] FIx rule import for move money so it moves percentage amounts correctly --- src/move_money.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/move_money.rs b/src/move_money.rs index 739b4ae..0aa7b34 100644 --- a/src/move_money.rs +++ b/src/move_money.rs @@ -198,7 +198,12 @@ where to_accounts, all_from_accounts: false, all_to_accounts: false, - amount: movement_rule.amount.unwrap_or(0.), + amount: movement_rule.amount.unwrap_or(0.) + * (if movement_rule.is_percent == "%" { + 0.01 + } else { + 1. + }), is_percent: movement_rule.is_percent == "%", is_separator: movement_rule.apply == "-DIVIDER-", }) @@ -265,6 +270,7 @@ pub fn move_money_1() {} // Note that the movement happens on a line-by-line level. So we can stream the data from disk, and potentially apply this // to every. It's also much more memory efficient than approach 1. // TODO: Time both approaches to seee which is faster depending on the size of the input data/number of rules +// Verdict: This is already pretty fast, at least much faster than ppm for BigDataset pub fn move_money_2( initial_totals: HashMap, rules: &Vec, @@ -321,7 +327,7 @@ mod tests { csv::Reader::from_path("reclassrule.csv").unwrap(), csv::Reader::from_path("line.csv").unwrap(), csv::Writer::from_path("output.csv").unwrap(), - false, + true, ); } }