diff --git a/src/main.rs b/src/main.rs index 138f445..b5a400f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,11 +117,8 @@ pub(crate) trait Spendings { .sum() } - fn contributions(&self, archive: &BTreeMap) -> 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) -> (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) -> 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();