How to use the fava.core.tree.Tree function in fava

To help you get started, we’ve selected a few fava examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beancount / fava / tests / test_core_tree.py View on Github external
def test_tree_cap(example_ledger):
    closing_entries = summarize.cap_opt(
        example_ledger.entries, example_ledger.options
    )
    real_account = realization.realize(closing_entries)

    tree = Tree(example_ledger.entries)
    tree.cap(example_ledger.options, "Unrealized")

    for account in realization.iter_children(real_account):
        name = account.account
        node = tree[name]
        if not name:
            continue
        if name.startswith("Expenses") or name.startswith("Income"):
            continue
        _compare_inv_and_counter(account.balance, node.balance)
github beancount / fava / tests / test_core_tree.py View on Github external
def test_tree_from_entries(example_ledger):
    tree = Tree(example_ledger.entries)
    real_account = realization.realize(example_ledger.entries)

    for account in realization.iter_children(real_account):
        name = account.account
        node = tree[name]
        _compare_inv_and_counter(account.balance, node.balance)
        _compare_inv_and_counter(
            realization.compute_balance(account), node.balance_children
        )
github beancount / fava / tests / test_core_tree.py View on Github external
def test_tree():
    tree = Tree()
    assert len(tree) == 1
    tree.get("account:name:a:b:c")
    assert len(tree) == 1
    node = tree.get("account:name:a:b:c", insert=True)
    assert len(tree) == 6
    tree.get("account:name", insert=True)
    assert len(tree) == 6
    assert node is tree.get("account:name:a:b:c", insert=True)

    assert list(tree.ancestors("account:name:a:b:c")) == [
        tree.get("account:name:a:b"),
        tree.get("account:name:a"),
        tree.get("account:name"),
        tree.get("account"),
        tree.get(""),
    ]
github beancount / fava / fava / core / __init__.py View on Github external
for filter_name, value in kwargs.items():
            if self._filters[filter_name].set(value):
                changed = True

        if not (changed or force):
            return

        self.entries = self.all_entries

        for filter_class in self._filters.values():
            self.entries = filter_class.apply(self.entries)

        self.root_account = realization.realize(
            self.entries, self.account_types
        )
        self.root_tree = Tree(self.entries)

        self._date_first, self._date_last = getters.get_min_max_dates(
            self.entries, (Transaction)
        )
        if self._date_last:
            self._date_last = self._date_last + datetime.timedelta(1)

        if self._filters["time"]:
            self._date_first = self._filters["time"].begin_date
            self._date_last = self._filters["time"].end_date
github beancount / fava / fava / core / __init__.py View on Github external
def root_tree_closed(self):
        """A root tree for the balance sheet."""
        tree = Tree(self.entries)
        tree.cap(self.options, self.fava_options["unrealized"])
        return tree
github beancount / fava / fava / ext / portfolio_list / __init__.py View on Github external
def portfolio_accounts(self, begin=None, end=None):
        """An account tree based on matching regex patterns."""
        if begin:
            tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
        else:
            tree = self.ledger.root_tree

        portfolios = []

        for option in self.config:
            opt_key = option[0]
            if opt_key == "account_name_pattern":
                portfolio = self._account_name_pattern(tree, end, option[1])
            elif opt_key == "account_open_metadata_pattern":
                portfolio = self._account_metadata_pattern(
                    tree, end, option[1][0], option[1][1]
                )
            else:
                raise FavaAPIException("Portfolio List: Invalid option.")
            portfolios.append(portfolio)
github beancount / fava / fava / core / charts.py View on Github external
def hierarchy(self, account_name, begin=None, end=None):
        """An account tree."""
        if begin:
            tree = Tree(iter_entry_dates(self.ledger.entries, begin, end))
        else:
            tree = self.ledger.root_tree
        return tree.get(account_name).serialise(end)