tktax_analysis/
analysis_hooks.rs1crate::ix!();
3
4pub type CreateProgramConfigFn = fn() -> ProgramConfig;
5pub type CreateGoldenCategorizedTxnsFn = fn() -> String;
6pub type CreateCategoryMapFn<TxCat:TransactionCategory> = fn(golden: &str) -> CategoryMap<TxCat>;
7pub type CreateAmazonBizExpensesFn = fn() -> Vec<AmazonStoreBusinessPurchase>;
8pub type CreateAmazonMedExpensesFn = fn() -> Vec<AmazonStoreMedicalPurchase>;
9
10#[derive(Builder,Getters)]
14#[getset(get="pub")]
15pub struct AccountAnalysisHooks {
16 program_config: ProgramConfig,
17 create_amazon_biz_expenses_fn: Option<CreateAmazonBizExpensesFn>,
18 create_amazon_med_expenses_fn: Option<CreateAmazonMedExpensesFn>,
19 donations_hooks: Option<DonationsHooks>,
20}
21
22impl AccountAnalysisHooks {
23
24 pub fn run_analysis<TxCat:TransactionCategory + 'static>(&self,
25 year: TrackedYear,
26 accounts: Vec<AccountKind>,
27 donation_config: Option<&DonationConfig>
28
29 ) -> Result<(),AccountError> {
30
31 debug!("program_config: {:#?}", self.program_config);
32
33 let category_map = CategoryMap::<TxCat>::new();
34
35 let donations = match self.donations_hooks {
36
37 Some(ref hooks) => {
38
39 let donation_config = donation_config.expect("if we have the hooks, we should have the config");
40
41 hooks.create_donations(&self.program_config,&donation_config)
42 },
43
44 None => vec![],
45 };
46
47 let amazon_biz_items = match self.create_amazon_biz_expenses_fn {
48 Some(create) => Some((create)()),
49 None => None,
50 };
51
52 let amazon_med_items = match self.create_amazon_med_expenses_fn {
53 Some(create) => Some((create)()),
54 None => None,
55 };
56
57 let flags = AccountAnalysisFlags::default();
58 let histogram_display_strategy = HistogramDisplayStrategy::default();
59
60 let analysis = AccountAnalysisBuilder::default()
61 .year(year)
62 .flags(flags)
63 .histogram_display_strategy(histogram_display_strategy)
64 .accounts(accounts)
65 .donations(donations)
66 .amazon_biz_items(amazon_biz_items)
67 .amazon_med_items(amazon_med_items)
68 .category_map(category_map)
69 .build()
70 .unwrap();
71
72 analysis.full_analysis(&self.program_config)?;
73
74 Ok(())
75 }
76}