Fix build in overhead allocation

This commit is contained in:
2024-12-26 19:43:02 +10:30
parent 139d6fb7fd
commit a9a9b1bec2

View File

@@ -4,6 +4,7 @@ use std::{
}; };
use csv::Reader; use csv::Reader;
use futures::SinkExt;
use itertools::Itertools; use itertools::Itertools;
use nalgebra::{DMatrix, Dynamic, LU}; use nalgebra::{DMatrix, Dynamic, LU};
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
@@ -409,7 +410,8 @@ where
summed_department_costs: total_cost, summed_department_costs: total_cost,
}) })
.collect(), .collect(),
if show_from { Some(output) } else { None }, output,
show_from,
zero_threshold, zero_threshold,
)?; )?;
@@ -509,7 +511,8 @@ fn remove_quote_and_padding(s: &str) -> String {
fn reciprocal_allocation_impl( fn reciprocal_allocation_impl(
allocations: Vec<OverheadAllocationRule>, allocations: Vec<OverheadAllocationRule>,
account_costs: Vec<AccountCost>, account_costs: Vec<AccountCost>,
movement_writer: Option<&mut impl RecordSerializer>, movement_writer: &mut impl RecordSerializer,
show_from: bool,
zero_threshold: f64, zero_threshold: f64,
) -> anyhow::Result<Vec<AccountCost>> { ) -> anyhow::Result<Vec<AccountCost>> {
let overhead_department_mappings = get_rules_indexes(&allocations, DepartmentType::Overhead); let overhead_department_mappings = get_rules_indexes(&allocations, DepartmentType::Overhead);
@@ -546,6 +549,7 @@ fn reciprocal_allocation_impl(
overhead_department_mappings, overhead_department_mappings,
allocations, allocations,
movement_writer, movement_writer,
show_from,
zero_threshold, zero_threshold,
) )
} else { } else {
@@ -555,6 +559,7 @@ fn reciprocal_allocation_impl(
overhead_department_mappings, overhead_department_mappings,
allocations, allocations,
movement_writer, movement_writer,
show_from,
zero_threshold, zero_threshold,
) )
} }
@@ -588,7 +593,8 @@ fn do_solve_reciprocal<T: ReciprocalAllocationSolver + Sync + Send>(
account_costs: Vec<AccountCost>, account_costs: Vec<AccountCost>,
overhead_department_mappings: HashMap<String, usize>, overhead_department_mappings: HashMap<String, usize>,
allocations: Vec<OverheadAllocationRule>, allocations: Vec<OverheadAllocationRule>,
temp_writer: Option<&mut impl RecordSerializer>, temp_writer: &mut impl RecordSerializer,
show_from: bool,
zero_threshold: f64, zero_threshold: f64,
) -> anyhow::Result<Vec<AccountCost>> { ) -> anyhow::Result<Vec<AccountCost>> {
let operating_department_mappings = get_rules_indexes(&allocations, DepartmentType::Operating); let operating_department_mappings = get_rules_indexes(&allocations, DepartmentType::Operating);
@@ -611,7 +617,7 @@ fn do_solve_reciprocal<T: ReciprocalAllocationSolver + Sync + Send>(
overhead_department_mappings.len(), overhead_department_mappings.len(),
operating_overhead_mappings, operating_overhead_mappings,
); );
if let Some(temp_writer) = temp_writer { if show_from {
solve_reciprocal_with_from( solve_reciprocal_with_from(
solver, solver,
account_costs, account_costs,
@@ -778,12 +784,12 @@ fn solve_reciprocal_with_from<T: ReciprocalAllocationSolver + Sync + Send>(
temp_writer.serialize(moved_amount)?; temp_writer.serialize(moved_amount)?;
} }
} }
temp_writer.flush()?;
Ok(()) Ok(())
} }
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::reciprocal_allocation; use crate::reciprocal_allocation;
use crate::AccountCost; use crate::AccountCost;
use crate::DepartmentType; use crate::DepartmentType;
@@ -871,7 +877,8 @@ mod tests {
let result = reciprocal_allocation_impl( let result = reciprocal_allocation_impl(
allocation_rules, allocation_rules,
initial_totals, initial_totals,
Some(&mut movement_writer), &mut movement_writer,
false,
0.00001, 0.00001,
) )
.unwrap(); .unwrap();