tktax-analysis 0.2.2

A robust Rust crate for financial account analysis, histogram generation, donation processing, and more.
Documentation
// ---------------- [ File: tktax-analysis/src/analysis_hooks.rs ]
crate::ix!();

pub type CreateProgramConfigFn                          = fn() -> ProgramConfig;
pub type CreateGoldenCategorizedTxnsFn                  = fn() -> String;
pub type CreateCategoryMapFn<TxCat:TransactionCategory> = fn(golden: &str) -> CategoryMap<TxCat>;
pub type CreateAmazonBizExpensesFn                      = fn() -> Vec<AmazonStoreBusinessPurchase>;
pub type CreateAmazonMedExpensesFn                      = fn() -> Vec<AmazonStoreMedicalPurchase>;

/// this lets us parametrize how we create the items we use
/// to run the program
///
#[derive(Builder,Getters)]
#[getset(get="pub")]
pub struct AccountAnalysisHooks {
    program_config:                    ProgramConfig,
    create_amazon_biz_expenses_fn:     Option<CreateAmazonBizExpensesFn>,
    create_amazon_med_expenses_fn:     Option<CreateAmazonMedExpensesFn>,
    donations_hooks:                   Option<DonationsHooks>,
}

impl AccountAnalysisHooks {

    pub fn run_analysis<TxCat:TransactionCategory + 'static>(&self, 
        year:            TrackedYear, 
        accounts:        Vec<AccountKind>,
        donation_config: Option<&DonationConfig>

    ) -> Result<(),AccountError> {

        debug!("program_config: {:#?}", self.program_config);

        let category_map       = CategoryMap::<TxCat>::new();

        let donations = match self.donations_hooks {

            Some(ref hooks) => {

                let donation_config = donation_config.expect("if we have the hooks, we should have the config");

                hooks.create_donations(&self.program_config,&donation_config)
            },

            None        => vec![],
        };

        let amazon_biz_items = match self.create_amazon_biz_expenses_fn {
            Some(create) => Some((create)()),
            None         => None,
        };

        let amazon_med_items = match self.create_amazon_med_expenses_fn {
            Some(create) => Some((create)()),
            None         => None,
        };

        let flags                      = AccountAnalysisFlags::default();
        let histogram_display_strategy = HistogramDisplayStrategy::default();

        let analysis = AccountAnalysisBuilder::default()
            .year(year)
            .flags(flags)
            .histogram_display_strategy(histogram_display_strategy)
            .accounts(accounts)
            .donations(donations)
            .amazon_biz_items(amazon_biz_items)
            .amazon_med_items(amazon_med_items)
            .category_map(category_map)
            .build()
            .unwrap();

        analysis.full_analysis(&self.program_config)?;

        Ok(())
    }
}