Allow to get only the main account

This commit is contained in:
traxys 2023-12-08 21:18:12 +01:00
parent 49d2745257
commit 4cfe91039c

View file

@ -117,11 +117,8 @@ pub(crate) trait Spendings {
.sum()
}
fn contributions(&self, archive: &BTreeMap<ReportDate, Report>) -> PossibleContributions {
let total_spendings = self.total_spendings();
let total_earnings = self.earnings().total();
let (historic_spendings, count) = std::iter::once(total_spendings)
fn main_account(&self, archive: &BTreeMap<ReportDate, Report>) -> (f64, u8) {
let (historic_spendings, count) = std::iter::once(self.total_spendings())
.chain(
match self.date() {
Some(date) => {
@ -143,7 +140,13 @@ pub(crate) trait Spendings {
(acc + spending, count + 1)
});
let main_account = historic_spendings / count as f64;
(historic_spendings / count as f64, count)
}
fn contributions(&self, archive: &BTreeMap<ReportDate, Report>) -> PossibleContributions {
let total_earnings = self.earnings().total();
let (main_account, count) = self.main_account(archive);
let main_factor = main_account / total_earnings;
let mut remaining = self.earnings();