def test_ranker(): list_ = [1, 2, 3] ranker = ExponentialDecayRanker(list_) ranker.update(1, date(2015, 1, 1)) ranker.update(2, date(2014, 1, 1)) ranker.update(3, date(2016, 1, 1)) assert ranker.sort() == [3, 1, 2] list_ = [1, 2] ranker = ExponentialDecayRanker(list_) ranker.update(2, date(2016, 1, 1)) ranker.update(2, date(2016, 1, 1)) ranker.update(1, date(2016, 1, 1)) ranker.update(1, date(2016, 1, 2)) assert ranker.sort() == [1, 2] list_ = [1, 2] ranker = ExponentialDecayRanker(list_) ranker.update(2, date(2015, 1, 1)) ranker.update(2, date(2015, 1, 1)) ranker.update(1, date(2016, 1, 1)) assert ranker.sort() == [1, 2] list_ = [1, 2] ranker = ExponentialDecayRanker(list_) ranker.update(2, date(2015, 1, 1)) ranker.update(2, date(2015, 1, 2)) ranker.update(1, date(2016, 1, 1)) assert ranker.sort() == [2, 1]
def load_file(self): all_entries = self.ledger.all_entries self.links = getters.get_all_links(all_entries) self.tags = getters.get_all_tags(all_entries) self.years = list(getters.get_active_years(all_entries))[::-1] account_ranker = ExponentialDecayRanker( sorted(self.ledger.accounts.keys())) currency_ranker = ExponentialDecayRanker( self.ledger.options['commodities']) payee_ranker = ExponentialDecayRanker() transactions = self.ledger.all_entries_by_type[Transaction] for txn in transactions: if txn.payee: payee_ranker.update(txn.payee, txn.date) for posting in txn.postings: account_ranker.update(posting.account, txn.date) currency_ranker.update(posting.units.currency, txn.date) if posting.cost: currency_ranker.update(posting.cost.currency, txn.date) self.accounts = account_ranker.sort() self.currencies = currency_ranker.sort() self.payees = payee_ranker.sort()
def load_file(self) -> None: all_entries = self.ledger.all_entries self.links = get_all_links(all_entries) self.tags = get_all_tags(all_entries) self.years = get_active_years( all_entries, self.ledger.fava_options["fiscal-year-end"] ) account_ranker = ExponentialDecayRanker( sorted(self.ledger.accounts.keys()) ) currency_ranker = ExponentialDecayRanker() payee_ranker = ExponentialDecayRanker() transactions = self.ledger.all_entries_by_type.Transaction for txn in transactions: if txn.payee: payee_ranker.update(txn.payee, txn.date) for posting in txn.postings: account_ranker.update(posting.account, txn.date) currency_ranker.update( posting.units.currency, txn.date # type: ignore ) if posting.cost and posting.cost.currency is not None: currency_ranker.update(posting.cost.currency, txn.date) self.accounts = account_ranker.sort() self.currencies = currency_ranker.sort() self.payees = payee_ranker.sort()
def test_ranker() -> None: list_ = ["1", "2", "3"] ranker = ExponentialDecayRanker(list_) ranker.update("1", date(2015, 1, 1)) ranker.update("2", date(2014, 1, 1)) ranker.update("3", date(2016, 1, 1)) assert ranker.sort() == ["3", "1", "2"] list_ = ["1", "2"] ranker = ExponentialDecayRanker(list_) ranker.update("2", date(2016, 1, 1)) ranker.update("2", date(2016, 1, 1)) ranker.update("1", date(2016, 1, 1)) ranker.update("1", date(2016, 1, 2)) assert ranker.sort() == ["1", "2"] list_ = ["1", "2"] ranker = ExponentialDecayRanker(list_) ranker.update("2", date(2015, 1, 1)) ranker.update("2", date(2015, 1, 1)) ranker.update("1", date(2016, 1, 1)) assert ranker.sort() == ["1", "2"] list_ = ["1", "2"] ranker = ExponentialDecayRanker(list_) ranker.update("2", date(2015, 1, 1)) ranker.update("2", date(2015, 1, 2)) ranker.update("1", date(2016, 1, 1)) assert ranker.sort() == ["2", "1"]
def payee_accounts(self, payee): """Rank accounts for the given payee.""" account_ranker = ExponentialDecayRanker(self.accounts) for txn in filter_type(self.ledger.all_entries, Transaction): if txn.payee == payee: for posting in txn.postings: account_ranker.update(posting.account, txn.date) return account_ranker.sort()
def payee_accounts(self, payee): """Rank accounts for the given payee.""" account_ranker = ExponentialDecayRanker(self.accounts) transactions = self.ledger.all_entries_by_type[Transaction] for txn in transactions: if txn.payee == payee: for posting in txn.postings: account_ranker.update(posting.account, txn.date) return account_ranker.sort()
def payee_accounts(self, payee: str) -> List[str]: """Rank accounts for the given payee.""" account_ranker = ExponentialDecayRanker(self.accounts) transactions = self.ledger.all_entries_by_type[Transaction] for txn in transactions: if txn.payee == payee: for posting in txn.postings: account_ranker.update(posting.account, txn.date) return account_ranker.sort()