Add macos/ios app using rust lib

This commit is contained in:
Piv
2023-02-03 21:29:23 +10:30
parent 1168ca46db
commit 734a19f711
25 changed files with 1265 additions and 8 deletions

View File

@@ -1,7 +1,8 @@
use std::collections::HashMap;
use std::{collections::HashMap, io::Read, path::Path};
use itertools::Itertools;
use nalgebra::{DMatrix, Dynamic, LU};
use serde::Deserialize;
#[derive(Debug, PartialEq, Eq)]
pub enum DepartmentType {
@@ -9,6 +10,36 @@ pub enum DepartmentType {
Overhead,
}
#[derive(Deserialize)]
pub struct CsvAllocationStatistic {
#[serde(rename = "Name")]
name: String,
#[serde(rename = "Description")]
description: Option<String>,
#[serde(rename = "AccountType")]
account_type: String,
#[serde(rename = "AccountRanges")]
account_ranges: String,
}
#[derive(Deserialize)]
pub struct CsvAccount {
#[serde(rename = "Code")]
code: String,
#[serde(rename = "Description")]
description: Option<String>,
#[serde(rename = "Type")]
account_type: String,
#[serde(rename = "CostOutput")]
cost_output: Option<String>,
#[serde(rename = "PercentFixed")]
percent_fixed: f64,
}
type CsvCostCentre = HashMap<String, String>;
type CsvArea = HashMap<String, String>;
// 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)
@@ -65,10 +96,32 @@ fn get_rules_indexes(
.collect()
}
pub fn reciprocal_allocation<Lines, Account, AllocationStatistic, Area, CostCentre, Output>(
lines: csv::Reader<Lines>,
accounts: csv::Reader<Account>,
allocation_statistics: csv::Reader<AllocationStatistic>,
areas: csv::Reader<Area>,
cost_centres: csv::Reader<CostCentre>,
output: csv::Writer<Output>,
) where
Lines: Read,
Account: Read,
AllocationStatistic: Read,
Area: Read,
CostCentre: Read,
Output: std::io::Write,
{
// Build out the the list of allocation rules from areas/allocation statistics (similar to ppm building 'cost drivers')
// do reciprocal allocation (only for variable portion of accounts), for each account
// Copy across fixed stuff (if necessary, not sure it is)
}
// Perform the reciprocal allocation (matrix) method to allocate servicing departments (indirect) costs
// to functional departments. Basically just a matrix solve, uses regression (moore-penrose pseudoinverse) when
// matrix is singular
pub fn reciprocal_allocation(
fn reciprocal_allocation_impl(
allocations: Vec<OverheadAllocationRule>,
account_costs: Vec<AccountCost>,
// TODO: Throw an appropriate error